From 335c971f6a9cd071d18f9fffeb76df4eda8876d5 Mon Sep 17 00:00:00 2001 From: H Lohaus Date: Fri, 13 Dec 2024 22:20:58 +0100 Subject: Add multiple images support (#2478) * Add multiple images support * Add multiple images support in gui * Support multiple images in legacy client and in the api Fix some model names in provider model list * Fix unittests * Add vision and providers docs --- g4f/Provider/DeepInfraChat.py | 48 ++++++++----------------------------------- 1 file changed, 8 insertions(+), 40 deletions(-) (limited to 'g4f/Provider/DeepInfraChat.py') diff --git a/g4f/Provider/DeepInfraChat.py b/g4f/Provider/DeepInfraChat.py index 6874b023..5f3e68e5 100644 --- a/g4f/Provider/DeepInfraChat.py +++ b/g4f/Provider/DeepInfraChat.py @@ -1,19 +1,12 @@ from __future__ import annotations -from aiohttp import ClientSession, ClientResponseError -import json -from ..typing import AsyncResult, Messages, ImageType -from .base_provider import AsyncGeneratorProvider, ProviderModelMixin +from ..typing import AsyncResult, Messages +from .needs_auth import OpenaiAPI - -class DeepInfraChat(AsyncGeneratorProvider, ProviderModelMixin): +class DeepInfraChat(OpenaiAPI): + label = "DeepInfra Chat" url = "https://deepinfra.com/chat" - api_endpoint = "https://api.deepinfra.com/v1/openai/chat/completions" - working = True - supports_stream = True - supports_system_message = True - supports_message_history = True default_model = 'meta-llama/Meta-Llama-3.1-70B-Instruct-Turbo' models = [ @@ -31,16 +24,17 @@ class DeepInfraChat(AsyncGeneratorProvider, ProviderModelMixin): "qwq-32b": "Qwen/QwQ-32B-Preview", "wizardlm-2-8x22b": "microsoft/WizardLM-2-8x22B", "qwen-2-72b": "Qwen/Qwen2.5-72B-Instruct", - "qwen-2.5-coder-32b": "Qwen2.5-Coder-32B-Instruct", + "qwen-2.5-coder-32b": "Qwen/Qwen2.5-Coder-32B-Instruct", "nemotron-70b": "nvidia/Llama-3.1-Nemotron-70B-Instruct", } @classmethod - async def create_async_generator( + def create_async_generator( cls, model: str, messages: Messages, proxy: str = None, + api_base: str = "https://api.deepinfra.com/v1/openai", **kwargs ) -> AsyncResult: headers = { @@ -52,30 +46,4 @@ class DeepInfraChat(AsyncGeneratorProvider, ProviderModelMixin): 'X-Deepinfra-Source': 'web-page', 'accept': 'text/event-stream', } - - data = { - 'model': model, - 'messages': messages, - 'stream': True - } - - async with ClientSession(headers=headers) as session: - async with session.post(cls.api_endpoint, json=data, proxy=proxy) as response: - response.raise_for_status() - async for line in response.content: - if line: - decoded_line = line.decode('utf-8').strip() - if decoded_line.startswith('data:'): - json_part = decoded_line[5:].strip() - if json_part == '[DONE]': - break - try: - data = json.loads(json_part) - choices = data.get('choices', []) - if choices: - delta = choices[0].get('delta', {}) - content = delta.get('content', '') - if content: - yield content - except json.JSONDecodeError: - print(f"JSON decode error: {json_part}") + return super().create_async_generator(model, messages, proxy, api_base=api_base, headers=headers, **kwargs) \ No newline at end of file -- cgit v1.2.3