调用spark-lite大模型;

在讯飞开放平台注册,领取免费API试用

立即体验spark-lite版本 

注册后点击控制台(更多服务查询)获得AppID、appkey

看星火文档中心文档中心里有示范

复制好APIpassword

url = "https://spark-api-open.xf-yun.com/v1/chat/completions"
data = {
        "model": "lite", # lite是免费 有无限tokens
        "messages": [
            {
                "role": "user",
                "content": "你是谁"
            }
        ],
#下面是可选参数
        "tools": [
        {
            "type": "function",
            "function": {
                "name": "get_current_weather",
                "description": "返回实时天气",
                "parameters": {
                    "type": "object",
                    "properties": {
                        "location": {
                            "type": "string",
                            "description": "河北省承德市双桥区",
                        },
                        "format": {
                            "type": "string",
                            "enum": ["celsius", "fahrenheit"],
                            "description": "使用本地区常用的温度单位计量",
                        },
                    },
                    "required": ["location", "format"],
                }
            }
        }
    ]
    }
header = {
    "Authorization": "Bearer APIPassword" # 注意此处替换自己的APIPassword
}
response = requests.post(url, headers=header, json=data)
print(response.text)

然后可以仿照openai,编写get_chat_completion(prompt,model='lite'){}
 

Logo

腾讯云面向开发者汇聚海量精品云计算使用和开发经验,营造开放的云计算技术生态圈。

更多推荐