SparkDesk API and Client
Project description
SparkDesk API and Client
接口说明 注意: 该接口可以正式使用。如您需要申请使用,请点击前往产品页面
计费说明:
服务引擎 | 单价 |
---|---|
讯飞星火认知大模型V1.5 | 0.18元/万tokens |
讯飞星火认知大模型V2.0 | 0.36元/万tokens |
讯飞星火认知大模型V3.0 | 0.36元/万tokens |
Installation
python3 -m pip install -U sparkapi-python
Configuration
copy
example.env
to~/.sparkapi.env
and edit the file with your credentials.
SPARK_APP_ID=<your-app-id>
SPARK_API_SECRET=<your-api-secret>
SPARK_API_KEY=<your-api-key>
SPARK_API_MODEL='v3.0' # v1.5, v2.0, v3.0
SPARK_CHAT_MAX_TOKENS=4096 # v1.5: 1-4096, v2.0: 1-8192
SPARK_CHAT_TEMPERATURE=0.5 # 0-1
SPARK_CHAT_TOP_K=4 # 1-6
Quickstart
CommandLine
sparkapi --help
# start a chat session
sparkapi chat
# get completion from your prompt
sparkapi prompt 详细介绍一下科大讯飞,输出Markdown结果
Python
from sparkapi.core.api import SparkAPI
from sparkapi.core.config import SparkConfig
config = SparkConfig().model_dump()
api = SparkAPI(**config)
# start a chat session
api.chat()
# get completion from prompt
res = api.get_completion('hello')
print(''.join(res))
# get completion from messages
messages = [
{'role': 'user', 'content': 'hello'},
{'role': 'assistant', 'content': 'Hello! How can I assist'},
{'role': 'user', 'content': 'write me a Python script of BubbleSort'},
]
res = api.get_completion_from_messages(messages)
print(''.join(res))
Changelog
[1.0.3] - 2023-10-26
- Add support for
v3.0
Project details
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
sparkapi-python-1.0.3.tar.gz
(8.0 kB
view hashes)
Built Distribution
Close
Hashes for sparkapi_python-1.0.3-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | c53bfa0bab145a5d7d811dea45fd9f79c70311b1e84fd5f941eb2d9fffe450a0 |
|
MD5 | 6c33bcf72c88ee18474d2b723cfdbdb9 |
|
BLAKE2b-256 | 6932a59eedcb77d0e5c2565cb3a73bfa9967db5dbe2a13a477ae62c1d1dbac0c |