summaryrefslogtreecommitdiffstats
path: root/g4f/Provider/GizAI.py
diff options
context:
space:
mode:
Diffstat (limited to 'g4f/Provider/GizAI.py')
-rw-r--r--g4f/Provider/GizAI.py121
1 files changed, 23 insertions, 98 deletions
diff --git a/g4f/Provider/GizAI.py b/g4f/Provider/GizAI.py
index 127edc9e..f00b344e 100644
--- a/g4f/Provider/GizAI.py
+++ b/g4f/Provider/GizAI.py
@@ -1,62 +1,24 @@
from __future__ import annotations
-import json
from aiohttp import ClientSession
from ..typing import AsyncResult, Messages
-from ..image import ImageResponse
from .base_provider import AsyncGeneratorProvider, ProviderModelMixin
from .helper import format_prompt
+
class GizAI(AsyncGeneratorProvider, ProviderModelMixin):
- url = "https://app.giz.ai/assistant/"
+ url = "https://app.giz.ai/assistant"
api_endpoint = "https://app.giz.ai/api/data/users/inferenceServer.infer"
working = True
-
+ supports_stream = False
supports_system_message = True
supports_message_history = True
- # Chat models
default_model = 'chat-gemini-flash'
- chat_models = [
- default_model,
- 'chat-gemini-pro',
- 'chat-gpt4m',
- 'chat-gpt4',
- 'claude-sonnet',
- 'claude-haiku',
- 'llama-3-70b',
- 'llama-3-8b',
- 'mistral-large',
- 'chat-o1-mini'
- ]
-
- # Image models
- image_models = [
- 'flux1',
- 'sdxl',
- 'sd',
- 'sd35',
- ]
-
- models = [*chat_models, *image_models]
+ models = [default_model]
- model_aliases = {
- # Chat model aliases
- "gemini-flash": "chat-gemini-flash",
- "gemini-pro": "chat-gemini-pro",
- "gpt-4o-mini": "chat-gpt4m",
- "gpt-4o": "chat-gpt4",
- "claude-3.5-sonnet": "claude-sonnet",
- "claude-3-haiku": "claude-haiku",
- "llama-3.1-70b": "llama-3-70b",
- "llama-3.1-8b": "llama-3-8b",
- "o1-mini": "chat-o1-mini",
- # Image model aliases
- "sd-1.5": "sd",
- "sd-3.5": "sd35",
- "flux-schnell": "flux1",
- }
+ model_aliases = {"gemini-flash": "chat-gemini-flash",}
@classmethod
def get_model(cls, model: str) -> str:
@@ -68,10 +30,6 @@ class GizAI(AsyncGeneratorProvider, ProviderModelMixin):
return cls.default_model
@classmethod
- def is_image_model(cls, model: str) -> bool:
- return model in cls.image_models
-
- @classmethod
async def create_async_generator(
cls,
model: str,
@@ -87,6 +45,7 @@ class GizAI(AsyncGeneratorProvider, ProviderModelMixin):
'Cache-Control': 'no-cache',
'Connection': 'keep-alive',
'Content-Type': 'application/json',
+ 'DNT': '1',
'Origin': 'https://app.giz.ai',
'Pragma': 'no-cache',
'Sec-Fetch-Dest': 'empty',
@@ -97,55 +56,21 @@ class GizAI(AsyncGeneratorProvider, ProviderModelMixin):
'sec-ch-ua-mobile': '?0',
'sec-ch-ua-platform': '"Linux"'
}
-
- async with ClientSession() as session:
- if cls.is_image_model(model):
- # Image generation
- prompt = messages[-1]["content"]
- data = {
- "model": model,
- "input": {
- "width": "1024",
- "height": "1024",
- "steps": 4,
- "output_format": "webp",
- "batch_size": 1,
- "mode": "plan",
- "prompt": prompt
- }
- }
- async with session.post(
- cls.api_endpoint,
- headers=headers,
- data=json.dumps(data),
- proxy=proxy
- ) as response:
- response.raise_for_status()
- response_data = await response.json()
- if response_data.get('status') == 'completed' and response_data.get('output'):
- for url in response_data['output']:
- yield ImageResponse(images=url, alt="Generated Image")
- else:
- # Chat completion
- data = {
- "model": model,
- "input": {
- "messages": [
- {
- "type": "human",
- "content": format_prompt(messages)
- }
- ],
- "mode": "plan"
- },
- "noStream": True
- }
- async with session.post(
- cls.api_endpoint,
- headers=headers,
- data=json.dumps(data),
- proxy=proxy
- ) as response:
- response.raise_for_status()
+
+ prompt = format_prompt(messages)
+
+ async with ClientSession(headers=headers) as session:
+ data = {
+ "model": model,
+ "input": {
+ "messages": [{"type": "human", "content": prompt}],
+ "mode": "plan"
+ },
+ "noStream": True
+ }
+ async with session.post(cls.api_endpoint, json=data, proxy=proxy) as response:
+ if response.status == 201:
result = await response.json()
- yield result.get('output', '')
+ yield result['output'].strip()
+ else:
+ raise Exception(f"Unexpected response status: {response.status}")