Spaces:
Running
Running
Update main.py
Browse files
main.py
CHANGED
@@ -58,6 +58,7 @@ def get_env_vars():
|
|
58 |
'secret_api_endpoint_2': os.getenv('SECRET_API_ENDPOINT_2'),
|
59 |
'secret_api_endpoint_3': os.getenv('SECRET_API_ENDPOINT_3'),
|
60 |
'secret_api_endpoint_4': "https://text.pollinations.ai/openai",
|
|
|
61 |
'mistral_api': "https://api.mistral.ai",
|
62 |
'mistral_key': os.getenv('MISTRAL_KEY'),
|
63 |
'endpoint_origin': os.getenv('ENDPOINT_ORIGIN')
|
@@ -111,11 +112,18 @@ alternate_models = { # heh, should work now
|
|
111 |
"creitin-r1",
|
112 |
"fluffy.1-chat",
|
113 |
"plutotext-1-text",
|
114 |
-
"command-a",
|
115 |
"claude-3-7-sonnet-20250219",
|
116 |
"plutogpt-3.5-turbo"
|
117 |
}
|
118 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
119 |
|
120 |
# Request payload model
|
121 |
class Payload(BaseModel):
|
@@ -162,7 +170,7 @@ async def verify_api_key(
|
|
162 |
detail="No API key provided"
|
163 |
)
|
164 |
|
165 |
-
# Only clean if needed
|
166 |
if api_key.startswith('Bearer '):
|
167 |
api_key = api_key[7:] # Remove 'Bearer ' prefix
|
168 |
|
@@ -268,10 +276,10 @@ async def generate_search_async(query: str, systemprompt: Optional[str] = None,
|
|
268 |
await queue.put({"data": f"data: {json.dumps(cleaned_response)}\n\n", "text": content})
|
269 |
except json.JSONDecodeError:
|
270 |
continue
|
271 |
-
|
272 |
-
|
273 |
-
|
274 |
-
|
275 |
except Exception as e:
|
276 |
await queue.put({"error": str(e)})
|
277 |
await queue.put(None)
|
@@ -418,9 +426,12 @@ async def get_completion(payload: Payload, request: Request, authenticated: bool
|
|
418 |
elif model_to_use in alternate_models:
|
419 |
endpoint = env_vars['secret_api_endpoint_2']
|
420 |
custom_headers = {}
|
|
|
|
|
|
|
421 |
else:
|
422 |
endpoint = env_vars['secret_api_endpoint']
|
423 |
-
custom_headers = {
|
424 |
"Origin": header_url,
|
425 |
"Priority": "u=1, i",
|
426 |
"Referer": header_url
|
@@ -730,7 +741,7 @@ async def get_meme():
|
|
730 |
yield b''.join(chunks)
|
731 |
|
732 |
return StreamingResponse(
|
733 |
-
stream_with_larger_chunks(),
|
734 |
media_type=image_response.headers.get("content-type", "image/png"),
|
735 |
headers={'Cache-Control': 'max-age=3600'} # Add caching
|
736 |
)
|
@@ -760,6 +771,8 @@ async def startup_event():
|
|
760 |
available_model_ids.extend(list(alternate_models))
|
761 |
# Add mistral models to available_model_ids
|
762 |
available_model_ids.extend(list(mistral_models))
|
|
|
|
|
763 |
|
764 |
available_model_ids = list(set(available_model_ids)) # Remove duplicates
|
765 |
print(f"Total available models: {len(available_model_ids)}")
|
@@ -780,6 +793,8 @@ async def startup_event():
|
|
780 |
missing_vars.append('SECRET_API_ENDPOINT_3')
|
781 |
if not env_vars['secret_api_endpoint_4']:
|
782 |
missing_vars.append('SECRET_API_ENDPOINT_4')
|
|
|
|
|
783 |
if not env_vars['mistral_api'] and any(model in mistral_models for model in available_model_ids):
|
784 |
missing_vars.append('MISTRAL_API')
|
785 |
if not env_vars['mistral_key'] and any(model in mistral_models for model in available_model_ids):
|
@@ -824,6 +839,8 @@ async def health_check():
|
|
824 |
missing_critical_vars.append('SECRET_API_ENDPOINT_3')
|
825 |
if not env_vars['secret_api_endpoint_4']:
|
826 |
missing_critical_vars.append('SECRET_API_ENDPOINT_4')
|
|
|
|
|
827 |
if not env_vars['mistral_api']:
|
828 |
missing_critical_vars.append('MISTRAL_API')
|
829 |
if not env_vars['mistral_key']:
|
|
|
58 |
'secret_api_endpoint_2': os.getenv('SECRET_API_ENDPOINT_2'),
|
59 |
'secret_api_endpoint_3': os.getenv('SECRET_API_ENDPOINT_3'),
|
60 |
'secret_api_endpoint_4': "https://text.pollinations.ai/openai",
|
61 |
+
'secret_api_endpoint_5': os.getenv('SECRET_API_ENDPOINT_5'), # Added new endpoint
|
62 |
'mistral_api': "https://api.mistral.ai",
|
63 |
'mistral_key': os.getenv('MISTRAL_KEY'),
|
64 |
'endpoint_origin': os.getenv('ENDPOINT_ORIGIN')
|
|
|
112 |
"creitin-r1",
|
113 |
"fluffy.1-chat",
|
114 |
"plutotext-1-text",
|
115 |
+
"command-a",
|
116 |
"claude-3-7-sonnet-20250219",
|
117 |
"plutogpt-3.5-turbo"
|
118 |
}
|
119 |
|
120 |
+
claude_3_models = { # Models for the new endpoint
|
121 |
+
"claude-3-7-sonnet",
|
122 |
+
"claude-3-7-sonnet-thinking",
|
123 |
+
"claude-3-5-haiku",
|
124 |
+
"claude-3-5-sonnet"
|
125 |
+
}
|
126 |
+
|
127 |
|
128 |
# Request payload model
|
129 |
class Payload(BaseModel):
|
|
|
170 |
detail="No API key provided"
|
171 |
)
|
172 |
|
173 |
+
# Only clean if needed
|
174 |
if api_key.startswith('Bearer '):
|
175 |
api_key = api_key[7:] # Remove 'Bearer ' prefix
|
176 |
|
|
|
276 |
await queue.put({"data": f"data: {json.dumps(cleaned_response)}\n\n", "text": content})
|
277 |
except json.JSONDecodeError:
|
278 |
continue
|
279 |
+
|
280 |
+
# Signal completion
|
281 |
+
await queue.put(None)
|
282 |
+
|
283 |
except Exception as e:
|
284 |
await queue.put({"error": str(e)})
|
285 |
await queue.put(None)
|
|
|
426 |
elif model_to_use in alternate_models:
|
427 |
endpoint = env_vars['secret_api_endpoint_2']
|
428 |
custom_headers = {}
|
429 |
+
elif model_to_use in claude_3_models: # Use the new endpoint
|
430 |
+
endpoint = env_vars['secret_api_endpoint_5']
|
431 |
+
custom_headers = {}
|
432 |
else:
|
433 |
endpoint = env_vars['secret_api_endpoint']
|
434 |
+
custom_headers = {
|
435 |
"Origin": header_url,
|
436 |
"Priority": "u=1, i",
|
437 |
"Referer": header_url
|
|
|
741 |
yield b''.join(chunks)
|
742 |
|
743 |
return StreamingResponse(
|
744 |
+
stream_with_larger_chunks(),
|
745 |
media_type=image_response.headers.get("content-type", "image/png"),
|
746 |
headers={'Cache-Control': 'max-age=3600'} # Add caching
|
747 |
)
|
|
|
771 |
available_model_ids.extend(list(alternate_models))
|
772 |
# Add mistral models to available_model_ids
|
773 |
available_model_ids.extend(list(mistral_models))
|
774 |
+
# Add claude models
|
775 |
+
available_model_ids.extend(list(claude_3_models))
|
776 |
|
777 |
available_model_ids = list(set(available_model_ids)) # Remove duplicates
|
778 |
print(f"Total available models: {len(available_model_ids)}")
|
|
|
793 |
missing_vars.append('SECRET_API_ENDPOINT_3')
|
794 |
if not env_vars['secret_api_endpoint_4']:
|
795 |
missing_vars.append('SECRET_API_ENDPOINT_4')
|
796 |
+
if not env_vars['secret_api_endpoint_5']: # Check for the new endpoint.
|
797 |
+
missing_vars.append('SECRET_API_ENDPOINT_5')
|
798 |
if not env_vars['mistral_api'] and any(model in mistral_models for model in available_model_ids):
|
799 |
missing_vars.append('MISTRAL_API')
|
800 |
if not env_vars['mistral_key'] and any(model in mistral_models for model in available_model_ids):
|
|
|
839 |
missing_critical_vars.append('SECRET_API_ENDPOINT_3')
|
840 |
if not env_vars['secret_api_endpoint_4']:
|
841 |
missing_critical_vars.append('SECRET_API_ENDPOINT_4')
|
842 |
+
if not env_vars['secret_api_endpoint_5']: # Check the new endpoint
|
843 |
+
missing_critical_vars.append('SECRET_API_ENDPOINT_5')
|
844 |
if not env_vars['mistral_api']:
|
845 |
missing_critical_vars.append('MISTRAL_API')
|
846 |
if not env_vars['mistral_key']:
|