返回提交历史
Modified
g4f/Provider/nexra/NexraProdiaAI.py
+48
-44
XFEstudio/gpt4free
Restored provider (g4f/Provider/nexra/NexraProdiaAI.py)
ab3e0545
代码差异
1 个文件
+48
-44
@@ -1,18 +1,16 @@
1
1
from __future__ import annotations
2
2
3
from aiohttp import ClientSession
4
3
import json
5
6
from ...typing import AsyncResult, Messages
7
from ..base_provider import AsyncGeneratorProvider, ProviderModelMixin
4
import requests
5
from ...typing import CreateResult, Messages
6
from ..base_provider import ProviderModelMixin, AbstractProvider
8
7
from ...image import ImageResponse
9
8
10
11
class NexraProdiaAI(AsyncGeneratorProvider, ProviderModelMixin):
9
class NexraProdiaAI(AbstractProvider, ProviderModelMixin):
12
10
label = "Nexra Prodia AI"
13
11
url = "https://nexra.aryahcr.cc/documentation/prodia/en"
14
12
api_endpoint = "https://nexra.aryahcr.cc/api/image/complements"
15
working = False
13
working = True
16
14
17
15
default_model = 'absolutereality_v181.safetensors [3d9d4d2b]'
18
16
models = [
@@ -83,8 +81,7 @@ class NexraProdiaAI(AsyncGeneratorProvider, ProviderModelMixin):
83
81
'toonyou_beta6.safetensors [980f6b15]',
84
82
]
85
83
86
model_aliases = {
87
}
84
model_aliases = {}
88
85
89
86
@classmethod
90
87
def get_model(cls, model: str) -> str:
@@ -96,9 +93,13 @@ class NexraProdiaAI(AsyncGeneratorProvider, ProviderModelMixin):
96
93
return cls.default_model
97
94
98
95
@classmethod
99
async def create_async_generator(
96
def get_model(cls, model: str) -> str:
97
return cls.default_model
98
99
@classmethod
100
def create_completion(
100
101
cls,
101
model: str, # Select from the list of models
102
model: str,
102
103
messages: Messages,
103
104
proxy: str = None,
104
105
response: str = "url", # base64 or url
@@ -107,41 +108,44 @@ class NexraProdiaAI(AsyncGeneratorProvider, ProviderModelMixin):
107
108
sampler: str = "DPM++ 2M Karras", # Select from these: "Euler","Euler a","Heun","DPM++ 2M Karras","DPM++ SDE Karras","DDIM"
108
109
negative_prompt: str = "", # Indicates what the AI should not do
109
110
**kwargs
110
) -> AsyncResult:
111
) -> CreateResult:
111
112
model = cls.get_model(model)
112
113
113
114
headers = {
114
"Content-Type": "application/json"
115
'Content-Type': 'application/json'
115
116
}
116
async with ClientSession(headers=headers) as session:
117
prompt = messages[0]['content']
118
data = {
119
"prompt": prompt,
120
"model": "prodia",
121
"response": response,
122
"data": {
123
"model": model,
124
"steps": steps,
125
"cfg_scale": cfg_scale,
126
"sampler": sampler,
127
"negative_prompt": negative_prompt
128
}
117
118
data = {
119
"prompt": messages[-1]["content"],
120
"model": "prodia",
121
"response": response,
122
"data": {
123
"model": model,
124
"steps": steps,
125
"cfg_scale": cfg_scale,
126
"sampler": sampler,
127
"negative_prompt": negative_prompt
129
128
}
130
async with session.post(cls.api_endpoint, json=data, proxy=proxy) as response:
131
text_data = await response.text()
132
133
if response.status == 200:
134
try:
135
json_start = text_data.find('{')
136
json_data = text_data[json_start:]
137
138
data = json.loads(json_data)
139
if 'images' in data and len(data['images']) > 0:
140
image_url = data['images'][-1]
141
yield ImageResponse(image_url, prompt)
142
else:
143
yield ImageResponse("No images found in the response.", prompt)
144
except json.JSONDecodeError:
145
yield ImageResponse("Failed to parse JSON. Response might not be in JSON format.", prompt)
129
}
130
131
response = requests.post(cls.api_endpoint, headers=headers, json=data)
132
133
result = cls.process_response(response)
134
yield result
135
136
@classmethod
137
def process_response(cls, response):
138
if response.status_code == 200:
139
try:
140
content = response.text.strip()
141
content = content.lstrip('_') # Remove leading underscores
142
data = json.loads(content)
143
if data.get('status') and data.get('images'):
144
image_url = data['images'][0]
145
return ImageResponse(images=[image_url], alt="Generated Image")
146
146
else:
147
yield ImageResponse(f"Request failed with status: {response.status}", prompt)
147
return "Error: No image URL found in the response"
148
except json.JSONDecodeError as e:
149
return f"Error: Unable to decode JSON response. Details: {str(e)}"
150
else:
151
return f"Error: {response.status_code}, Response: {response.text}"