SparkDesk API and Client
Project description
SparkDesk API and Client
Installation
python3 -m pip install 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='v2.0' # v1.5, v2.0
SPARK_CHAT_MAX_TOKENS=4096 # 1-4096
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))
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.2.tar.gz
(7.3 kB
view hashes)
Built Distribution
Close
Hashes for sparkapi_python-1.0.2-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | f98f4cab7f521b172f902ae261363f5c7a6479c1b443a095e82980cbba5f0d68 |
|
MD5 | b0495f5e324445950300b010ab5b197e |
|
BLAKE2b-256 | 8cec375663bddd9f0be43fb109360ecca517e110ae8add4db2827fa013dfe58d |