From 168d963c7cee3fb2b35ded3dd8c98436a649c77a Mon Sep 17 00:00:00 2001 From: suqingdong <1078595229@qq.com> Date: Thu, 26 Oct 2023 15:21:01 +0800 Subject: [PATCH] add support for V3.0 --- README.md | 6 +++--- example.env | 4 ++-- sparkapi/core/api.py | 2 ++ sparkapi/core/model.py | 4 ++++ sparkapi/core/query.py | 1 + sparkapi/version.json | 2 +- 6 files changed, 13 insertions(+), 6 deletions(-) diff --git a/README.md b/README.md index 3d40fc4..cdbfe25 100644 --- a/README.md +++ b/README.md @@ -3,7 +3,7 @@ ## Installation ```bash -python3 -m pip install sparkapi-python +python3 -m pip install -U sparkapi-python ``` ## Configuration @@ -12,8 +12,8 @@ python3 -m pip install sparkapi-python 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_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 ``` diff --git a/example.env b/example.env index e02b146..e1aea27 100644 --- a/example.env +++ b/example.env @@ -1,7 +1,7 @@ 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_API_MODEL='v2.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 diff --git a/sparkapi/core/api.py b/sparkapi/core/api.py index 7a8950b..fbd2673 100644 --- a/sparkapi/core/api.py +++ b/sparkapi/core/api.py @@ -47,6 +47,8 @@ def get_completion_from_messages(self, messages: List[dict], **kwargs): wss = self.create_wss_connection() query = self.build_query(messages, **kwargs) + from pprint import pprint + # pprint(query) wss.send(query) while True: diff --git a/sparkapi/core/model.py b/sparkapi/core/model.py index 75698af..217f26f 100644 --- a/sparkapi/core/model.py +++ b/sparkapi/core/model.py @@ -7,4 +7,8 @@ 'domain': 'generalv2', 'url': 'wss://spark-api.xf-yun.com/v2.1/chat', }, + 'v3.0': { + 'domain': 'generalv3', + 'url': 'wss://spark-api.xf-yun.com/v3.1/chat', + }, } diff --git a/sparkapi/core/query.py b/sparkapi/core/query.py index 51276f7..8d41a10 100644 --- a/sparkapi/core/query.py +++ b/sparkapi/core/query.py @@ -7,6 +7,7 @@ class Domain(Enum): GENERAL = 'general' GENERAL_V2 = 'generalv2' + GENERAL_V3 = 'generalv3' def __str__(self): return self.value diff --git a/sparkapi/version.json b/sparkapi/version.json index 1650795..b5f941c 100644 --- a/sparkapi/version.json +++ b/sparkapi/version.json @@ -4,5 +4,5 @@ "url": "https://github.com/suqingdong/sparkapi", "author": "suqingdong", "author_email": "suqingdong1114@gmail.com", - "version": "1.0.2" + "version": "1.0.3" }