XFE Git
XFE Studio Git
Git 首页 全局搜索
XFE 主站 文档 NuGet
公开
关注 0 Fork 0 Star 1
返回提交历史

XFEstudio/gpt4free

Removed provider (g4f/Provider/nexra/NexraDalleMini.py g4f/Provider/nexra/NexraLLaMA31.py). Updated (g4f/Provider/nexra/__init__.py)

df89e58d
kqlio67 <kqlio67@users.noreply.github.com>
提交于

代码差异

3 个文件 +0 -159
Deleted g4f/Provider/nexra/NexraDalleMini.py +0 -66
@@ -1,66 +0,0 @@
1 from __future__ import annotations
2
3 from aiohttp import ClientSession
4 import json
5
6 from ...typing import AsyncResult, Messages
7 from ..base_provider import AsyncGeneratorProvider, ProviderModelMixin
8 from ...image import ImageResponse
9
10
11 class NexraDalleMini(AsyncGeneratorProvider, ProviderModelMixin):
12 label = "Nexra DALL-E Mini"
13 url = "https://nexra.aryahcr.cc/documentation/dall-e/en"
14 api_endpoint = "https://nexra.aryahcr.cc/api/image/complements"
15 working = False
16
17 default_model = 'dalle-mini'
18 models = [default_model]
19
20 @classmethod
21 def get_model(cls, model: str) -> str:
22 return cls.default_model
23
24 @classmethod
25 async def create_async_generator(
26 cls,
27 model: str,
28 messages: Messages,
29 proxy: str = None,
30 response: str = "url", # base64 or url
31 **kwargs
32 ) -> AsyncResult:
33 # Retrieve the correct model to use
34 model = cls.get_model(model)
35
36 # Format the prompt from the messages
37 prompt = messages[0]['content']
38
39 headers = {
40 "Content-Type": "application/json"
41 }
42 payload = {
43 "prompt": prompt,
44 "model": model,
45 "response": response
46 }
47
48 async with ClientSession(headers=headers) as session:
49 async with session.post(cls.api_endpoint, json=payload, proxy=proxy) as response:
50 response.raise_for_status()
51 text_data = await response.text()
52
53 try:
54 # Parse the JSON response
55 json_start = text_data.find('{')
56 json_data = text_data[json_start:]
57 data = json.loads(json_data)
58
59 # Check if the response contains images
60 if 'images' in data and len(data['images']) > 0:
61 image_url = data['images'][0]
62 yield ImageResponse(image_url, prompt)
63 else:
64 yield ImageResponse("No images found in the response.", prompt)
65 except json.JSONDecodeError:
66 yield ImageResponse("Failed to parse JSON. Response might not be in JSON format.", prompt)
Deleted g4f/Provider/nexra/NexraLLaMA31.py +0 -91
@@ -1,91 +0,0 @@
1 from __future__ import annotations
2
3 from aiohttp import ClientSession
4 import json
5
6 from ...typing import AsyncResult, Messages
7 from ..base_provider import AsyncGeneratorProvider, ProviderModelMixin
8 from ..helper import format_prompt
9
10
11 class NexraLLaMA31(AsyncGeneratorProvider, ProviderModelMixin):
12 label = "Nexra LLaMA 3.1"
13 url = "https://nexra.aryahcr.cc/documentation/llama-3.1/en"
14 api_endpoint = "https://nexra.aryahcr.cc/api/chat/complements"
15 working = False
16 supports_stream = True
17
18 default_model = 'llama-3.1'
19 models = [default_model]
20 model_aliases = {
21 "llama-3.1-8b": "llama-3.1",
22 }
23
24 @classmethod
25 def get_model(cls, model: str) -> str:
26 if model in cls.models:
27 return model
28 elif model in cls.model_aliases:
29 return cls.model_aliases.get(model, cls.default_model)
30 else:
31 return cls.default_model
32
33 @classmethod
34 async def create_async_generator(
35 cls,
36 model: str,
37 messages: Messages,
38 proxy: str = None,
39 stream: bool = False,
40 markdown: bool = False,
41 **kwargs
42 ) -> AsyncResult:
43 model = cls.get_model(model)
44
45 headers = {
46 "Content-Type": "application/json"
47 }
48
49 async with ClientSession(headers=headers) as session:
50 prompt = format_prompt(messages)
51 data = {
52 "messages": [
53 {
54 "role": "user",
55 "content": prompt
56 }
57 ],
58 "stream": stream,
59 "markdown": markdown,
60 "model": model
61 }
62
63 async with session.post(f"{cls.api_endpoint}", json=data, proxy=proxy) as response:
64 response.raise_for_status()
65
66 if stream:
67 # Streamed response handling
68 collected_message = ""
69 async for chunk in response.content.iter_any():
70 if chunk:
71 decoded_chunk = chunk.decode().strip().split("\x1e")
72 for part in decoded_chunk:
73 if part:
74 message_data = json.loads(part)
75
76 # Collect messages until 'finish': true
77 if 'message' in message_data and message_data['message']:
78 collected_message = message_data['message']
79
80 # When finish is true, yield the final collected message
81 if message_data.get('finish', False):
82 yield collected_message
83 return
84 else:
85 # Non-streamed response handling
86 response_data = await response.json(content_type=None)
87
88 # Yield the message directly from the response
89 if 'message' in response_data and response_data['message']:
90 yield response_data['message']
91 return
Modified g4f/Provider/nexra/__init__.py +0 -2
@@ -6,11 +6,9 @@ from .NexraChatGptV2 import NexraChatGptV2
6 6 from .NexraChatGptWeb import NexraChatGptWeb
7 7 from .NexraDallE import NexraDallE
8 8 from .NexraDallE2 import NexraDallE2
9 from .NexraDalleMini import NexraDalleMini
10 9 from .NexraEmi import NexraEmi
11 10 from .NexraFluxPro import NexraFluxPro
12 11 from .NexraGeminiPro import NexraGeminiPro
13 from .NexraLLaMA31 import NexraLLaMA31
14 12 from .NexraMidjourney import NexraMidjourney
15 13 from .NexraProdiaAI import NexraProdiaAI
16 14 from .NexraQwen import NexraQwen