PySparkAI - WebSocket Chatbot Client for 星火大模型
PySparkAI 是一个基于WebSocket调用星火大模型API的客户端。其目的是为用户提供高度封装的方法,从而简化使用过程。
特性
- 基于WebSocket的实时聊天:确保及时、持续的交互
- 星火大模型API:调用先进的AI技术来提供精确的回答
- 高度封装:减少配置和引导时间,即插即用
快速开始
安装
pip install xunfeispark
使用
查看demo.py脚本以了解如何使用PySparkAI。以下是demo.py的简短摘要:
from pysparkai import PySparkAI
def get_credentials_from_user():
"""
获取用户输入的敏感信息。
"""
APP_ID = "此处填入你的APP_ID"
API_KEY = "此处填入你的API_KEY"
API_SECRET = "此处填入你的API_SECRET"
SPARK_URL = "此处填入你的SPARK_URL"
DOMAIN = "此处填入你的DOMAIN"
return APP_ID, API_KEY, API_SECRET, SPARK_URL, DOMAIN
# 以上所有信息都可以在你的讯飞开放平台的控制台中找到
def main():
APP_ID, API_KEY, API_SECRET, SPARK_URL, DOMAIN = get_credentials_from_user()
ai = PySparkAI(app_id=APP_ID, api_key=API_KEY, api_secret=API_SECRET, spark_url=SPARK_URL, domain=DOMAIN)
prompt_message = {"role": "system",
"content": "在一个遥远的星球上,有一位智者名为Zarnak,他对于人类世界有着深厚的了解。"}
question_message = {"role": "user",
"content": "Zarnak, 你能告诉我地球上的人的性格为什么多种多样吗?"}
format_specification_message = {
"role": "system", "content": "请使用第三人称,以故事的方式回答。"}
messages = [prompt_message, format_specification_message, question_message]
completion = ai.chat(messages, temperature=0.3, max_tokens=200)
formatted_answer = f"""
Prompt: {prompt_message["content"]}
格式要求: {format_specification_message["content"]}
问题: {question_message["content"]}
回答: {completion["choices"][0]["message"]}
"""
print(formatted_answer)
print("Token 使用情况:")
for key, value in completion["usage"].items():
print(f"{key}: {value}")
if __name__ == "__main__":
main()
完整的demo.py脚本在仓库中可用。
开发
依赖
websocket-client: 为项目提供WebSocket通信功能。
贡献
如果您想为该项目做出贡献,请确保遵循以下步骤:
- Fork这个仓库: PySparkAI on GitLab。当然,这里的GitLab是大陆本土化的JihuLab。
- 创建你的功能分支 (
git checkout -b feature/YourFeature) - 提交你的更改 (
git commit -am 'Add some feature') - 推送到分支 (
git push origin feature/YourFeature) - 在GitLab上创建一个新的Merge Request
- 你也能够在PySparkAI on Github上找到它。
许可
该项目使用MIT许可。
联系
如有任何问题或建议,请联系 shadow.li981@gmail.com.
文档
更多关于 pysparkai 的详细文档,包括如何安装、使用和其他信息,请访问 这里。
Metadata
Release files for xunfeispark 1.0
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| xunfeispark-1.0-py3-none-any.whl | Python 3 | none | any | Details for xunfeispark-1.0-py3-none-any.whl |
Release files / xunfeispark-1.0-py3-none-any.whl
| Download URL | xunfeispark-1.0-py3-none-any.whl |
|---|---|
| Size | 9.2 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
1a97df69477ab63254669644c439e7ad244321ca9539509f7bc32cedf525baee
|
|
BLAKE2b-256 checksum How to use checksums |
c8587f1e0b65c63c00f9dfc1b9a5427a7bdd0b81b8650360691156ba66d878d0
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/4.0.2 CPython/3.10.12
|
Security for xunfeispark 1.0
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.