Introduction to the SparkDesk-API
Overview
The SparkDesk-API is a comprehensive interface to interact with the SparkDesk large model developed by iFlytek. This project provides an easy way to engage with the powerful capabilities of the SparkDesk model through a programmable interface. Users can utilize this API to conduct single or continuous chats, enabling dynamic interaction with SparkDesk's cognitive abilities.
Installation
To get started with the SparkDesk-API, users can install it using pip, a package manager for Python. The recommended version for installation is 1.5.0, which can be easily installed via the following command:
pip install sparkdesk-api==1.5.0
Alternatively, the package can be installed from the Python Package Index (PyPI) directly using:
pip install sparkdesk-api==1.5.0 -i https://pypi.org/simple
Usage
1. Web Mode
In Web Mode, users need to obtain three specific parameters: cookie, fd, and GtToken. These parameters can be acquired using the developer tools available in a web browser (often accessed using the F12 key) while visiting the SparkDesk model's web interface. Detailed instructions on obtaining these parameters are provided here.
Command Line Interaction
Once the necessary parameters are in hand, users can start a command line session with the SparkDesk using:
python sparkdesk_web_cli.py
API Interaction
To engage with the API programmatically, users can initiate chats using the chat()
function for single interactions, or chat_stream()
for continuous dialog, similar to command line usage.
from sparkdesk_web.core import SparkWeb
sparkWeb = SparkWeb(
cookie=cookie,
fd=fd,
GtToken=GtToken
)
# Single chat example
print(sparkWeb.chat("repeat: hello world"))
# Continuous chat
sparkWeb.chat_stream()
2. API Mode
For users who prefer API mode, this tool supports multiple versions, including 3.5, 3.0, 2.0, and 1.0, with version 3.5 as the default. The API offers a more extensive setup similar to the web mode but requires users to apply for access through iFlytek's official website using an app ID, API key, and API secret. For faster approval, applications using corporate emails are recommended.
Here's how a user can set up the API Mode:
from sparkdesk_api.core import SparkAPI
sparkAPI = SparkAPI(
app_id=app_id,
api_secret=api_secret,
api_key=api_key,
# Example for other versions: version=2.1,
# Example for assistant API: assistant_id="xyzspsb4i5s7_v1"
)
sparkAPI.chat_stream()
The API mode methods and functions mirror those in the Web Mode.
Support & Contributions
Users who find the project helpful are encouraged to support the developers by "buying a coffee" through sponsorship, as depicted below:
Acknowledgments
The project owes its existence to the invaluable contributions of various developers. Their efforts in enhancing the project's functionality are greatly appreciated. For a detailed list of contributors, please visit the project's contributors page.