diff options
author | madonchik123 <68397448+madonchik123@users.noreply.github.com> | 2023-12-01 23:11:52 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2023-12-01 23:11:52 +0100 |
commit | b0276f6c9e2925c65a00b7189bad92feb25cefbd (patch) | |
tree | 1909ac2fd081e2e8ad5b5dfa8ae46bd6fd58c579 /g4f/api/__init__.py | |
parent | ~ (diff) | |
download | gpt4free-b0276f6c9e2925c65a00b7189bad92feb25cefbd.tar gpt4free-b0276f6c9e2925c65a00b7189bad92feb25cefbd.tar.gz gpt4free-b0276f6c9e2925c65a00b7189bad92feb25cefbd.tar.bz2 gpt4free-b0276f6c9e2925c65a00b7189bad92feb25cefbd.tar.lz gpt4free-b0276f6c9e2925c65a00b7189bad92feb25cefbd.tar.xz gpt4free-b0276f6c9e2925c65a00b7189bad92feb25cefbd.tar.zst gpt4free-b0276f6c9e2925c65a00b7189bad92feb25cefbd.zip |
Diffstat (limited to '')
-rw-r--r-- | g4f/api/__init__.py | 30 |
1 files changed, 21 insertions, 9 deletions
diff --git a/g4f/api/__init__.py b/g4f/api/__init__.py index d2244ff5..410fcc5f 100644 --- a/g4f/api/__init__.py +++ b/g4f/api/__init__.py @@ -40,12 +40,15 @@ class Api: @self.app.get("/v1/models") async def models(): - model_list = [{ + model_list = [] + for model in g4f.Model.__all__(): + model_info = (g4f.ModelUtils.convert[model]) + model_list.append({ 'id': model, 'object': 'model', 'created': 0, - 'owned_by': 'g4f'} for model in g4f.Model.__all__()] - + 'owned_by': model_info.base_provider} + ) return Response(content=json.dumps({ 'object': 'list', 'data': model_list}, indent=4), media_type="application/json") @@ -80,17 +83,25 @@ class Api: model = item_data.get('model') stream = True if item_data.get("stream") == "True" else False messages = item_data.get('messages') + conversation = item_data.get('conversation') if item_data.get('conversation') != None else None try: - response = g4f.ChatCompletion.create( - model=model, - stream=stream, - messages=messages, - ignored=self.list_ignored_providers) + if model == 'pi': + response = g4f.ChatCompletion.create( + model=model, + stream=stream, + messages=messages, + conversation=conversation, + ignored=self.list_ignored_providers) + else: + response = g4f.ChatCompletion.create( + model=model, + stream=stream, + messages=messages, + ignored=self.list_ignored_providers) except Exception as e: logging.exception(e) return Response(content=json.dumps({"error": "An error occurred while generating the response."}, indent=4), media_type="application/json") - completion_id = ''.join(random.choices(string.ascii_letters + string.digits, k=28)) completion_timestamp = int(time.time()) @@ -134,6 +145,7 @@ class Api: { 'index': 0, 'delta': { + 'role': 'assistant', 'content': chunk, }, 'finish_reason': None, |