科大讯飞星火大模型SDK
Project description
科大讯飞星火模型 Python SDK
介绍
关于科大讯飞星火模型 Python调用,科大讯飞官网仅给出了Web API文档。 本项目是对官方Web API封装,便于用户调用。
安装
pip install xunfei-spark-python==0.0.1
使用
问答接口
from xunfei.spark._client import Spark
from xunfei.spark._response import ChatResponse
if __name__ == '__main__':
config = {
"app_id": "{your_app_id}",
"api_secret": "{your_api_secret}",
"api_key": "{your_api_key}",
"gpt_url": "wss://spark-api.xf-yun.com/v3.5/chat",
"domain": "generalv3.5",
}
spark = Spark(**config)
messages = [{"role": "user", "content": "你是谁开发的?"}]
# 非stream模式调用示例
response: ChatResponse = spark.chat(messages=messages)
print('AI:', response.content)
print('Token使用量:', response.usage)
### Stream模式问答接口
```python
from xunfei.spark._client import Spark
from xunfei.spark._response import ChatResponse
if __name__ == '__main__':
config = {
"app_id": "{your_app_id}",
"api_secret": "{your_api_secret}",
"api_key": "{your_api_key}",
"gpt_url": "wss://spark-api.xf-yun.com/v3.5/chat",
"domain": "generalv3.5",
}
spark = Spark(**config)
messages = [{"role": "user", "content": "你是谁开发的?"}]
for message in spark.chat_stream(messages=messages):
if message:
if 'type' in message and message['type'] == 'chunk':
print(f"客户端接受到的消息: {message}")
elif 'type' in message and message['type'] == 'stop':
print(f"结束")
break
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Close
Hashes for xunfei-spark-python-0.0.5.tar.gz
Algorithm | Hash digest | |
---|---|---|
SHA256 | e9c369793db317c84ac61750ba7c9b56af7c4e929d609fc5b8d322b0b40f95fe |
|
MD5 | d04815aba256d58a6d0b2891b4799583 |
|
BLAKE2b-256 | 1f46b0ec2cb36f21b69164d75113903dffe8a3e7bdb9d535df5d82deb2412b74 |
Close
Hashes for xunfei_spark_python-0.0.5-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 49a3d85d93da8b29ea4e75d362c2b65ef1b150d1451043613d0e6618322f89b7 |
|
MD5 | f447e1113bdaafdd35ef27285dd80b82 |
|
BLAKE2b-256 | 979d69401eb0e2462bcbc12c415166d7dc0c2e3a22e6c6c0404ee970bd187795 |