三种国产大语言模型Python免费调用

基础三大模型,需要先去官方注册获得key;后续可以使用下列代码调用

1.腾讯

安装:

复制代码
pip install -i https://mirrors.tencent.com/pypi/simple/ --upgrade tencentcloud-sdk-python

实例:

复制代码
import jsonimport typesfrom tencentcloud.common import credentialfrom tencentcloud.common.profile.client_profile import ClientProfilefrom tencentcloud.common.profile.http_profile import HttpProfilefrom tencentcloud.common.exception.tencent_cloud_sdk_exception import TencentCloudSDKExceptionfrom tencentcloud.hunyuan.v20230901 import hunyuan_client, modelstry:    cred = credential.Credential("你的SecretId", "你的SecretKey")    httpProfile = HttpProfile()    httpProfile.endpoint = "hunyuan.tencentcloudapi.com"    clientProfile = ClientProfile()    clientProfile.httpProfile = httpProfile    req = models.ChatCompletionsRequest()    params = {        "Model": "hunyuan-lite",        "Messages": [            {                "Role": "user",                "Content": "你好"            }        ]    }    req.from_json_string(json.dumps(params))    resp = client.ChatCompletions(req)    if isinstance(resp, types.GeneratorType):         for event in resp:            print(event)    else:         print(resp)except TencentCloudSDKException as err:    print(err)

2.讯飞

安装:

复制代码
pip install spark-ai-python

实例:

复制代码
from sparkai.llm.llm import ChatSparkLLM, ChunkPrintHandlerfrom sparkai.core.messages import ChatMessage
def get_response(text):    if text is not None:        SPARKAI_URL = 'wss://spark-api.xf-yun.com/v1.1/chat'        SPARKAI_APP_ID = ''        SPARKAI_API_SECRET = ''        SPARKAI_API_KEY = ''        SPARKAI_DOMAIN = 'general'        spark = ChatSparkLLM(spark_api_url=SPARKAI_URL, spark_app_id=SPARKAI_APP_ID, spark_api_key=SPARKAI_API_KEY,                              spark_api_secret=SPARKAI_API_SECRET, spark_llm_domain=SPARKAI_DOMAIN, streaming=False)        messages = [ChatMessage(role="user", content=text)]        handler = ChunkPrintHandler()        st = spark.generate([messages], callbacks=[handler])        return st
response = get_response("你好")print(response)

3.百度:

安装:

复制代码
pip install requests

import requestsimport jsondef get_access_token():    url = "https://aip.baidubce.com/oauth/2.0/token?grant_type=client_credentials&client_id=&client_secret="    payload = json.dumps("")    headers = {        'Content-Type': 'application/json',        'Accept': 'application/json'    }    response = requests.request("POST", url, headers=headers, data=payload)    return response.json().get("access_token")

def get_response(text):       url = "https://aip.baidubce.com/rpc/2.0/ai_custom/v1/wenxinworkshop/chat/yi_34b_chat?access_token=" + get_access_token()    payload = json.dumps({"messages": [{"role": "user","content": "hi"}]})    headers = {        'Content-Type': 'application/json'    }    response = requests.request("POST", url, headers=headers, data=payload)        print(response.json().get("result"))    
相关推荐
liangshanbo12157 分钟前
Web Worker 在 AI 前端应用中有什么具体使用场景?
前端·人工智能
daad7778 分钟前
手写一个 LPC 语音 Codec:从一帧真实音频看编码到解码的全过程
人工智能·音视频·语音识别
nap-joker8 分钟前
解耦多模态对抗自编码器:在不完全多模态神经图像下婴儿年龄预测中的应用
人工智能·特征解耦·婴儿年龄预测·vae-based
Martina_03219 分钟前
山谷地形下雨后湿痕总往坡上爬?用6步检查高度场、流向遮罩与分区加载
人工智能·游戏·数学建模·3d·自然语言处理·aigc·关卡设计
跟我学机器学习11 分钟前
基于两阶段索引的RAG Agent:检索增强与 Agent 结合实践
人工智能·深度学习·语言模型
Keep_Trying_Go13 分钟前
MobileSAM 论文方法详解
人工智能·深度学习·计算机视觉·分割算法
ZhengEnCi18 分钟前
AI 生成 App 原型图:一句话真能画出可交互界面吗?从 Text-to-Prototype(文本生成原型)到 D2C(Design to Code,设计转代
人工智能
学弟18 分钟前
内涵:sam系列论文梳理
人工智能
weixin_4462608522 分钟前
利用千问Qwen3.8-27B 开源模型越狱版自动CTF题目解题
人工智能
LaughingZhu24 分钟前
Product Hunt 每日热榜 | 2026-10-07
人工智能·深度学习·神经网络·搜索引擎·百度