diff options
author | kqlio67 <kqlio67@users.noreply.github.com> | 2024-10-19 12:21:19 +0200 |
---|---|---|
committer | kqlio67 <kqlio67@users.noreply.github.com> | 2024-10-19 12:21:19 +0200 |
commit | d7573a003934f1bc569ccb08602ab8203361669d (patch) | |
tree | 1ed3343d1dfca7c546028e92891f5e176ff8ce2c /g4f/Provider/Nexra.py | |
parent | feat(g4f/Provider/Blackbox.py): enhance async generator with image processing (diff) | |
download | gpt4free-d7573a003934f1bc569ccb08602ab8203361669d.tar gpt4free-d7573a003934f1bc569ccb08602ab8203361669d.tar.gz gpt4free-d7573a003934f1bc569ccb08602ab8203361669d.tar.bz2 gpt4free-d7573a003934f1bc569ccb08602ab8203361669d.tar.lz gpt4free-d7573a003934f1bc569ccb08602ab8203361669d.tar.xz gpt4free-d7573a003934f1bc569ccb08602ab8203361669d.tar.zst gpt4free-d7573a003934f1bc569ccb08602ab8203361669d.zip |
Diffstat (limited to 'g4f/Provider/Nexra.py')
-rw-r--r-- | g4f/Provider/Nexra.py | 66 |
1 files changed, 0 insertions, 66 deletions
diff --git a/g4f/Provider/Nexra.py b/g4f/Provider/Nexra.py deleted file mode 100644 index 5fcdd242..00000000 --- a/g4f/Provider/Nexra.py +++ /dev/null @@ -1,66 +0,0 @@ -from __future__ import annotations - -from aiohttp import ClientSession -import json - -from ..typing import AsyncResult, Messages -from .base_provider import AsyncGeneratorProvider, ProviderModelMixin -from ..image import ImageResponse - - -class Nexra(AsyncGeneratorProvider, ProviderModelMixin): - label = "Nexra Animagine XL" - url = "https://nexra.aryahcr.cc/documentation/midjourney/en" - api_endpoint = "https://nexra.aryahcr.cc/api/image/complements" - working = True - - default_model = 'animagine-xl' - models = [default_model] - - @classmethod - def get_model(cls, model: str) -> str: - return cls.default_model - - @classmethod - async def create_async_generator( - cls, - model: str, - messages: Messages, - proxy: str = None, - response: str = "url", # base64 or url - **kwargs - ) -> AsyncResult: - # Retrieve the correct model to use - model = cls.get_model(model) - - # Format the prompt from the messages - prompt = messages[0]['content'] - - headers = { - "Content-Type": "application/json" - } - payload = { - "prompt": prompt, - "model": model, - "response": response - } - - async with ClientSession(headers=headers) as session: - async with session.post(cls.api_endpoint, json=payload, proxy=proxy) as response: - response.raise_for_status() - text_data = await response.text() - - try: - # Parse the JSON response - json_start = text_data.find('{') - json_data = text_data[json_start:] - data = json.loads(json_data) - - # Check if the response contains images - if 'images' in data and len(data['images']) > 0: - image_url = data['images'][0] - yield ImageResponse(image_url, prompt) - else: - yield ImageResponse("No images found in the response.", prompt) - except json.JSONDecodeError: - yield ImageResponse("Failed to parse JSON. Response might not be in JSON format.", prompt) |