XFE Git
XFE Studio Git
Git 首页 全局搜索
XFE 主站 文档 NuGet
公开
关注 0 Fork 0 Star 1
返回提交历史

XFEstudio/gpt4free

feat(g4f/api/__init__.py): support both ':' and '-' in model prefixes

a0087269
kqlio67 <kqlio67@users.noreply.github.com>
提交于

代码差异

1 个文件 +14 -0
Modified g4f/api/__init__.py +14 -0
@@ -165,6 +165,19 @@ class Api:
165 165 @self.app.post("/v1/chat/completions")
166 166 async def chat_completions(config: ChatCompletionsConfig, request: Request = None, provider: str = None):
167 167 try:
168 # Find the last delimiter with ':' or '-'
169 if ':' in config.model:
170 model_parts = config.model.rsplit(":", 1)
171 elif '-' in config.model:
172 model_parts = config.model.rsplit("-", 1)
173 else:
174 model_parts = [config.model] # There is no prefix.
175
176 base_model = model_parts[0] # We use the base model name
177 model_prefix = model_parts[1] if len(model_parts) > 1 else None
178
179 config.model = base_model # Update the configuration to the basic model
180
168 181 config.provider = provider if config.provider is None else config.provider
169 182 if config.api_key is None and request is not None:
170 183 auth_header = request.headers.get("Authorization")
@@ -229,6 +242,7 @@ class Api:
229 242 async def completions():
230 243 return Response(content=json.dumps({'info': 'Not working yet.'}, indent=4), media_type="application/json")
231 244
245
232 246 def format_exception(e: Exception, config: Union[ChatCompletionsConfig, ImageGenerationConfig]) -> str:
233 247 last_provider = g4f.get_last_provider(True)
234 248 return json.dumps({