Update app.py
Browse files
app.py
CHANGED
@@ -228,6 +228,12 @@ def handle_request():
|
|
228 |
if not model or not messages or len(messages) == 0:
|
229 |
return jsonify({"error": "Bad Request: Missing required fields"}), 400
|
230 |
|
|
|
|
|
|
|
|
|
|
|
|
|
231 |
prompt = messages[-1]['content']
|
232 |
image_size, clean_prompt, use_original, size_param = extract_params_from_prompt(prompt)
|
233 |
|
@@ -241,7 +247,7 @@ def handle_request():
|
|
241 |
else:
|
242 |
enhanced_prompt = translate_and_enhance_prompt(clean_prompt, random_token)
|
243 |
|
244 |
-
new_url = f'https://api.siliconflow.cn/v1/{
|
245 |
new_request_body = {
|
246 |
"prompt": enhanced_prompt,
|
247 |
"image_size": image_size,
|
@@ -279,7 +285,7 @@ def handle_request():
|
|
279 |
params.append("-o")
|
280 |
params_str = " ".join(params) if params else "no params"
|
281 |
|
282 |
-
app.logger.info(f"Status: 200 - Token: {random_token} - Model: {
|
283 |
|
284 |
if stream:
|
285 |
return stream_response(unique_id, image_data, clean_prompt, enhanced_prompt, image_size, current_timestamp, model, system_fingerprint, use_original)
|
|
|
228 |
if not model or not messages or len(messages) == 0:
|
229 |
return jsonify({"error": "Bad Request: Missing required fields"}), 400
|
230 |
|
231 |
+
# 映射 model
|
232 |
+
if model in MODEL_MAPPING:
|
233 |
+
mapped_model = MODEL_MAPPING[model]['mapping']
|
234 |
+
else:
|
235 |
+
return jsonify({"error": f"Model '{model}' not found"}), 400
|
236 |
+
|
237 |
prompt = messages[-1]['content']
|
238 |
image_size, clean_prompt, use_original, size_param = extract_params_from_prompt(prompt)
|
239 |
|
|
|
247 |
else:
|
248 |
enhanced_prompt = translate_and_enhance_prompt(clean_prompt, random_token)
|
249 |
|
250 |
+
new_url = f'https://api.siliconflow.cn/v1/{mapped_model}/text-to-image'
|
251 |
new_request_body = {
|
252 |
"prompt": enhanced_prompt,
|
253 |
"image_size": image_size,
|
|
|
285 |
params.append("-o")
|
286 |
params_str = " ".join(params) if params else "no params"
|
287 |
|
288 |
+
app.logger.info(f"Status: 200 - Token: {random_token} - Model: {mapped_model} - Params: {params_str} - Image URL: {image_url}")
|
289 |
|
290 |
if stream:
|
291 |
return stream_response(unique_id, image_data, clean_prompt, enhanced_prompt, image_size, current_timestamp, model, system_fingerprint, use_original)
|