调用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

中国智能体开发者社区,聚焦智能体与大模型开发,提供前沿资讯、实用工具链、开源项目及行业案例。通过技术沙龙、开发者大赛等活动,促进经验交流与协作,助力开发者快速构建创新智能应用。

更多推荐