mirror of
https://github.com/NovaOSS/nova-api.git
synced 2024-11-25 16:23:57 +01:00
Fixed non-stream responses
This commit is contained in:
parent
98d7588ecf
commit
7d914bc147
|
@ -126,6 +126,9 @@ async def stream(
|
||||||
if response.content_type == 'application/json':
|
if response.content_type == 'application/json':
|
||||||
data = await response.json()
|
data = await response.json()
|
||||||
|
|
||||||
|
if 'method_not_supported' in str(data):
|
||||||
|
await errors.error(500, 'Sorry, this endpoint does not support this method.', data['error']['message'])
|
||||||
|
|
||||||
if 'invalid_api_key' in str(data) or 'account_deactivated' in str(data):
|
if 'invalid_api_key' in str(data) or 'account_deactivated' in str(data):
|
||||||
print('[!] invalid api key', target_request.get('provider_auth'))
|
print('[!] invalid api key', target_request.get('provider_auth'))
|
||||||
await provider_auth.invalidate_key(target_request.get('provider_auth'))
|
await provider_auth.invalidate_key(target_request.get('provider_auth'))
|
||||||
|
@ -153,18 +156,21 @@ async def stream(
|
||||||
break
|
break
|
||||||
|
|
||||||
except Exception as exc:
|
except Exception as exc:
|
||||||
print(f'[!] {type(exc)} - {exc}')
|
# print(f'[!] {type(exc)} - {exc}')
|
||||||
continue
|
continue
|
||||||
|
|
||||||
if (not json_response) and is_chat:
|
if (not json_response) and is_chat:
|
||||||
print('[!] chat response is empty')
|
print('[!] chat response is empty')
|
||||||
continue
|
continue
|
||||||
|
else:
|
||||||
|
yield await errors.yield_error(500, 'Sorry, the API is not responding.', 'Please try again later.')
|
||||||
|
return
|
||||||
|
|
||||||
if is_chat and is_stream:
|
if is_chat and is_stream:
|
||||||
yield await chat.create_chat_chunk(chat_id=chat_id, model=model, content=chat.CompletionStop)
|
yield await chat.create_chat_chunk(chat_id=chat_id, model=model, content=chat.CompletionStop)
|
||||||
yield 'data: [DONE]\n\n'
|
yield 'data: [DONE]\n\n'
|
||||||
|
|
||||||
if not is_stream and json_response:
|
if (not is_stream) and json_response:
|
||||||
yield json.dumps(json_response)
|
yield json.dumps(json_response)
|
||||||
|
|
||||||
await after_request.after_request(
|
await after_request.after_request(
|
||||||
|
|
Loading…
Reference in a new issue