diff options
author | kqlio67 <kqlio67@users.noreply.github.com> | 2024-10-30 17:25:40 +0100 |
---|---|---|
committer | kqlio67 <kqlio67@users.noreply.github.com> | 2024-10-30 17:25:40 +0100 |
commit | a0087269b3f3fa21f6862904e5a5b64a33fb40ea (patch) | |
tree | b5c883696cdbf668ea776cac798253745250c60a /g4f/api/__init__.py | |
parent | The prefix function has been removed (diff) | |
download | gpt4free-a0087269b3f3fa21f6862904e5a5b64a33fb40ea.tar gpt4free-a0087269b3f3fa21f6862904e5a5b64a33fb40ea.tar.gz gpt4free-a0087269b3f3fa21f6862904e5a5b64a33fb40ea.tar.bz2 gpt4free-a0087269b3f3fa21f6862904e5a5b64a33fb40ea.tar.lz gpt4free-a0087269b3f3fa21f6862904e5a5b64a33fb40ea.tar.xz gpt4free-a0087269b3f3fa21f6862904e5a5b64a33fb40ea.tar.zst gpt4free-a0087269b3f3fa21f6862904e5a5b64a33fb40ea.zip |
Diffstat (limited to '')
-rw-r--r-- | g4f/api/__init__.py | 14 |
1 files changed, 14 insertions, 0 deletions
diff --git a/g4f/api/__init__.py b/g4f/api/__init__.py index 754a48f1..25694942 100644 --- a/g4f/api/__init__.py +++ b/g4f/api/__init__.py @@ -165,6 +165,19 @@ class Api: @self.app.post("/v1/chat/completions") async def chat_completions(config: ChatCompletionsConfig, request: Request = None, provider: str = None): try: + # Find the last delimiter with ':' or '-' + if ':' in config.model: + model_parts = config.model.rsplit(":", 1) + elif '-' in config.model: + model_parts = config.model.rsplit("-", 1) + else: + model_parts = [config.model] # There is no prefix. + + base_model = model_parts[0] # We use the base model name + model_prefix = model_parts[1] if len(model_parts) > 1 else None + + config.model = base_model # Update the configuration to the basic model + config.provider = provider if config.provider is None else config.provider if config.api_key is None and request is not None: auth_header = request.headers.get("Authorization") @@ -229,6 +242,7 @@ class Api: async def completions(): return Response(content=json.dumps({'info': 'Not working yet.'}, indent=4), media_type="application/json") + def format_exception(e: Exception, config: Union[ChatCompletionsConfig, ImageGenerationConfig]) -> str: last_provider = g4f.get_last_provider(True) return json.dumps({ |