Skip to content

Commit

Permalink
feat:修改讯飞大模型名称为“官网”对应名称;同时增加 Spark Pro-128K类型; (#1153)
Browse files Browse the repository at this point in the history
* feat:修改讯飞大模型名称为“官网”对应名称;同时增加 Spark Pro-128K类型;

* perf:完善token_limit配置;模型额外参数放到metadata字段中
  • Loading branch information
ZhengQinyu authored Aug 21, 2024
1 parent aac0f68 commit ebffc4e
Show file tree
Hide file tree
Showing 3 changed files with 98 additions and 21 deletions.
2 changes: 1 addition & 1 deletion modules/models/base_model.py
Original file line number Diff line number Diff line change
Expand Up @@ -209,7 +209,7 @@ def get_type(cls, model_name: str):
model_type = ModelType.Midjourney
elif "azure" in model_name_lower or "api" in model_name_lower:
model_type = ModelType.LangchainChat
elif "星火大模型" in model_name_lower:
elif "讯飞星火" in model_name_lower:
model_type = ModelType.Spark
elif "claude" in model_name_lower:
model_type = ModelType.Claude
Expand Down
17 changes: 2 additions & 15 deletions modules/models/spark.py
Original file line number Diff line number Diff line change
Expand Up @@ -72,21 +72,8 @@ def __init__(self, model_name, appid, api_key, api_secret, user_name="") -> None
self.api_secret = api_secret
if None in [self.api_key, self.appid, self.api_secret]:
raise Exception("请在配置文件或者环境变量中设置讯飞的API Key、APP ID和API Secret")
if "2.0" in self.model_name:
self.spark_url = "wss://spark-api.xf-yun.com/v2.1/chat"
self.domain = "generalv2"
elif "3.0" in self.model_name:
self.spark_url = "wss://spark-api.xf-yun.com/v3.1/chat"
self.domain = "generalv3"
elif "3.5" in self.model_name:
self.spark_url = "wss://spark-api.xf-yun.com/v3.5/chat"
self.domain = "generalv3.5"
elif "4.0" in self.model_name:
self.spark_url = "wss://spark-api.xf-yun.com/v4.0/chat"
self.domain = "4.0Ultra"
else:
self.spark_url = "wss://spark-api.xf-yun.com/v1.1/chat"
self.domain = "general"
self.spark_url = f"wss://spark-api.xf-yun.com{self.metadata['path']}"
self.domain = self.metadata['domain']

# 收到websocket错误的处理
def on_error(self, ws, error):
Expand Down
100 changes: 95 additions & 5 deletions modules/presets.py
Original file line number Diff line number Diff line change
Expand Up @@ -84,11 +84,19 @@
"yuanai-1.0-rhythm_poems",
"minimax-abab5-chat",
"midjourney",
# 兼容旧配置文件,待删除
"讯飞星火大模型V4.0",
"讯飞星火大模型V3.5",
"讯飞星火大模型V3.0",
"讯飞星火大模型V2.0",
"讯飞星火大模型V1.5",
# 新的名称
"讯飞星火4.0 Ultra",
"讯飞星火Max",
"讯飞星火Pro 128K",
"讯飞星火Pro",
"讯飞星火V2.0",
"讯飞星火Lite",
"ERNIE-Bot-turbo",
"ERNIE-Bot",
"ERNIE-Bot-4",
Expand Down Expand Up @@ -382,11 +390,93 @@
"yuanai-1.0-rhythm_poems": {"model_name": "yuanai-1.0-rhythm_poems"},
"minimax-abab5-chat": {"model_name": "minimax-abab5-chat"},
"midjourney": {"model_name": "midjourney"},
"讯飞星火大模型V4.0": {"model_name": "讯飞星火大模型V4.0"},
"讯飞星火大模型V3.5": {"model_name": "讯飞星火大模型V3.5"},
"讯飞星火大模型V3.0": {"model_name": "讯飞星火大模型V3.0"},
"讯飞星火大模型V2.0": {"model_name": "讯飞星火大模型V2.0"},
"讯飞星火大模型V1.5": {"model_name": "讯飞星火大模型V1.5"},
# 兼容旧配置文件,待删除
"讯飞星火大模型V4.0": {
"model_name": "讯飞星火大模型V4.0",
"token_limit": 8192,
"metadata": {
"path": "/v4.0/chat",
"domain": "4.0Ultra"
}
},
"讯飞星火大模型V3.5": {
"model_name": "讯飞星火大模型V3.5",
"token_limit": 8192,
"metadata": {
"path": "/v3.5/chat",
"domain": "generalv3.5"
}
},
"讯飞星火大模型V3.0": {
"model_name": "讯飞星火大模型V3.0",
"token_limit": 8192,
"metadata": {
"path": "/v3.1/chat",
"domain": "generalv3"
}
},
"讯飞星火大模型V2.0": {
"model_name": "讯飞星火大模型V2.0",
"metadata": {
"path": "/v2.1/chat",
"domain": "generalv2"
}
},
"讯飞星火大模型V1.5": {
"model_name": "讯飞星火大模型V1.5",
"metadata": {
"path": "/v1.1/chat",
"domain": "general"
}
},
# 新的名称
"讯飞星火4.0 Ultra": {
"model_name": "讯飞星火4.0 Ultra",
"token_limit": 8192,
"metadata": {
"path": "/v4.0/chat",
"domain": "4.0Ultra"
}
},
"讯飞星火Max": {
"model_name": "讯飞星火Max",
"token_limit": 8192,
"metadata": {
"path": "/v3.5/chat",
"domain": "generalv3.5"
}
},

"讯飞星火Pro 128K": {
"model_name": "讯飞星火Pro 128K",
"token_limit": 131072, # 128 * 1024
"metadata": {
"path": "/chat/pro-128k",
"domain": "pro-128k"
}
},
"讯飞星火Pro": {
"model_name": "讯飞星火Pro",
"token_limit": 8192,
"metadata": {
"path": "/v3.1/chat",
"domain": "generalv3"
}
},
"讯飞星火V2.0": {
"model_name": "讯飞星火V2.0",
"metadata": {
"path": "/v2.1/chat",
"domain": "generalv2"
}
},
"讯飞星火Lite": {
"model_name": "讯飞星火Lite",
"metadata": {
"path": "/v1.1/chat",
"domain": "general"
}
}
}

if os.environ.get('HIDE_LOCAL_MODELS', 'false') == 'true':
Expand Down

0 comments on commit ebffc4e

Please sign in to comment.