ajuste para verificar formdata e json na chamada groq
This commit is contained in:
parent
a4ba9d02bc
commit
a25dc9c4e7
@ -40,9 +40,10 @@ async def get_working_groq_key(storage) -> Optional[str]:
|
|||||||
storage.add_log("ERROR", "No working GROQ keys available")
|
storage.add_log("ERROR", "No working GROQ keys available")
|
||||||
return None
|
return None
|
||||||
|
|
||||||
async def handle_groq_request(url: str, headers: dict, data: dict, storage) -> Tuple[bool, dict, str]:
|
async def handle_groq_request(url: str, headers: dict, data, storage, is_form_data: bool = False) -> Tuple[bool, dict, str]:
|
||||||
"""
|
"""
|
||||||
Handle GROQ API request with retries and key rotation.
|
Handle GROQ API request with retries and key rotation.
|
||||||
|
Suporta tanto JSON quanto FormData.
|
||||||
Returns: (success, response_data, error_message)
|
Returns: (success, response_data, error_message)
|
||||||
"""
|
"""
|
||||||
max_retries = len(storage.get_groq_keys())
|
max_retries = len(storage.get_groq_keys())
|
||||||
@ -50,6 +51,10 @@ async def handle_groq_request(url: str, headers: dict, data: dict, storage) -> T
|
|||||||
for attempt in range(max_retries):
|
for attempt in range(max_retries):
|
||||||
try:
|
try:
|
||||||
async with aiohttp.ClientSession() as session:
|
async with aiohttp.ClientSession() as session:
|
||||||
|
if is_form_data:
|
||||||
|
async with session.post(url, headers=headers, data=data) as response:
|
||||||
|
response_data = await response.json()
|
||||||
|
else:
|
||||||
async with session.post(url, headers=headers, json=data) as response:
|
async with session.post(url, headers=headers, json=data) as response:
|
||||||
response_data = await response.json()
|
response_data = await response.json()
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user