summaryrefslogtreecommitdiffstats
path: root/g4f/api/__init__.py
diff options
context:
space:
mode:
authorHeiner Lohaus <hlohaus@users.noreply.github.com>2024-02-23 11:33:38 +0100
committerHeiner Lohaus <hlohaus@users.noreply.github.com>2024-02-23 11:33:38 +0100
commit51264fe20cda57eff47ac9a386edb3563eac4568 (patch)
tree29233c3c384ebc8cc493e68842aa0dcff499cd49 /g4f/api/__init__.py
parentAdd missing file (diff)
downloadgpt4free-51264fe20cda57eff47ac9a386edb3563eac4568.tar
gpt4free-51264fe20cda57eff47ac9a386edb3563eac4568.tar.gz
gpt4free-51264fe20cda57eff47ac9a386edb3563eac4568.tar.bz2
gpt4free-51264fe20cda57eff47ac9a386edb3563eac4568.tar.lz
gpt4free-51264fe20cda57eff47ac9a386edb3563eac4568.tar.xz
gpt4free-51264fe20cda57eff47ac9a386edb3563eac4568.tar.zst
gpt4free-51264fe20cda57eff47ac9a386edb3563eac4568.zip
Diffstat (limited to '')
-rw-r--r--g4f/api/__init__.py13
1 files changed, 9 insertions, 4 deletions
diff --git a/g4f/api/__init__.py b/g4f/api/__init__.py
index d1e8539f..18268eec 100644
--- a/g4f/api/__init__.py
+++ b/g4f/api/__init__.py
@@ -21,7 +21,7 @@ class ChatCompletionsConfig(BaseModel):
temperature: Union[float, None]
max_tokens: int = None
stop: Union[list[str], str, None]
- access_token: Union[str, None]
+ api_key: Union[str, None]
class Api:
def __init__(self, engine: g4f, debug: bool = True, sentry: bool = False,
@@ -82,10 +82,10 @@ class Api:
async def chat_completions(config: ChatCompletionsConfig = None, request: Request = None, provider: str = None):
try:
config.provider = provider if config.provider is None else config.provider
- if config.access_token is None and request is not None:
+ if config.api_key is None and request is not None:
auth_header = request.headers.get("Authorization")
if auth_header is not None:
- config.access_token = auth_header.split(None, 1)[-1]
+ config.api_key = auth_header.split(None, 1)[-1]
response = self.client.chat.completions.create(
**dict(config),
@@ -124,4 +124,9 @@ def format_exception(e: Exception, config: ChatCompletionsConfig) -> str:
"error": {"message": f"ChatCompletionsError: {e.__class__.__name__}: {e}"},
"model": last_provider.get("model") if last_provider else config.model,
"provider": last_provider.get("name") if last_provider else config.provider
- }) \ No newline at end of file
+ })
+
+def run_api(host: str = '0.0.0.0', port: int = 1337, debug: bool = False, use_colors=True) -> None:
+ print(f'Starting server... [g4f v-{g4f.version.utils.current_version}]')
+ app = Api(engine=g4f, debug=debug)
+ uvicorn.run(app=app, host=host, port=port, use_colors=use_colors) \ No newline at end of file