三种国产大语言模型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"))    
相关推荐
qq_1893704912 分钟前
自然语言处理NLP中的连续词袋(Continuous bag of words,CBOW)方法、优势、作用和程序举例
人工智能·自然语言处理·连续词袋
threelab3 小时前
07.three官方示例+编辑器+AI快速学习webgl_buffergeometry_attributes_integer
人工智能·学习·编辑器
背太阳的牧羊人4 小时前
tokenizer.encode_plus,BERT类模型 和 Sentence-BERT 他们之间的区别与联系
人工智能·深度学习·bert
学算法的程霖4 小时前
TGRS | FSVLM: 用于遥感农田分割的视觉语言模型
人工智能·深度学习·目标检测·机器学习·计算机视觉·自然语言处理·遥感图像分类
博睿谷IT99_4 小时前
华为HCIP-AI认证考试版本更新通知
人工智能·华为
小彭律师4 小时前
数字化工厂中央控制室驾驶舱系统架构文档
python
一点.点5 小时前
SafeDrive:大语言模型实现自动驾驶汽车知识驱动和数据驱动的风险-敏感决策——论文阅读
人工智能·语言模型·自动驾驶
concisedistinct5 小时前
如何评价大语言模型架构 TTT ?模型应不应该永远“固定”在推理阶段?模型是否应当在使用时继续学习?
人工智能·语言模型·大模型
找了一圈尾巴5 小时前
AI Agent-基础认知与架构解析
人工智能·ai agent
jzwei0236 小时前
Transformer Decoder-Only 参数量计算
人工智能·深度学习·transformer