mirror of
https://github.com/NovaOSS/nova-api.git
synced 2024-11-25 16:23:57 +01:00
Compare commits
2 commits
a16ba559fb
...
fffd7a276a
Author | SHA1 | Date | |
---|---|---|---|
fffd7a276a | |||
91ea380b79 |
|
@ -1,2 +1,2 @@
|
||||||
from . import ails
|
from . import ails, closed, closed4
|
||||||
MODULES = [ails]
|
MODULES = [closed, closed4]
|
||||||
|
|
|
@ -68,7 +68,8 @@ async def respond(
|
||||||
'insufficient_quota': 0,
|
'insufficient_quota': 0,
|
||||||
'billing_not_active': 0,
|
'billing_not_active': 0,
|
||||||
'critical_provider_error': 0,
|
'critical_provider_error': 0,
|
||||||
'timeout': 0
|
'timeout': 0,
|
||||||
|
'other_errors': []
|
||||||
}
|
}
|
||||||
|
|
||||||
input_tokens = 0
|
input_tokens = 0
|
||||||
|
@ -168,6 +169,11 @@ async def respond(
|
||||||
output_tokens = client_json_response['usage']['completion_tokens']
|
output_tokens = client_json_response['usage']['completion_tokens']
|
||||||
|
|
||||||
server_json_response = client_json_response
|
server_json_response = client_json_response
|
||||||
|
elif response.content_type == 'text/plain':
|
||||||
|
data = (await response.read()).decode("utf-8")
|
||||||
|
print(f'[!] {data}')
|
||||||
|
skipped_errors['other_errors'] = skipped_errors['other_errors'].append(data)
|
||||||
|
continue
|
||||||
|
|
||||||
if is_stream:
|
if is_stream:
|
||||||
input_tokens = await count_tokens_for_messages(payload['messages'], model=model)
|
input_tokens = await count_tokens_for_messages(payload['messages'], model=model)
|
||||||
|
@ -175,7 +181,7 @@ async def respond(
|
||||||
chunk_no = 0
|
chunk_no = 0
|
||||||
buffer = ''
|
buffer = ''
|
||||||
|
|
||||||
async for chunk in response.content.iter_chunked(1024):
|
async for chunk in response.content.iter_chunked(1024):
|
||||||
chunk_no += 1
|
chunk_no += 1
|
||||||
|
|
||||||
chunk = chunk.decode('utf8')
|
chunk = chunk.decode('utf8')
|
||||||
|
@ -205,7 +211,8 @@ async def respond(
|
||||||
continue
|
continue
|
||||||
|
|
||||||
else:
|
else:
|
||||||
skipped_errors = {k: v for k, v in skipped_errors.items() if v > 0}
|
skipped_errors = {k: v for k, v in skipped_errors.items() if ((isinstance(v, int) and v > 0) or
|
||||||
|
(isinstance(v, list) and len(v) > 0))}
|
||||||
skipped_errors = ujson.dumps(skipped_errors, indent=4)
|
skipped_errors = ujson.dumps(skipped_errors, indent=4)
|
||||||
yield await errors.yield_error(500,
|
yield await errors.yield_error(500,
|
||||||
f'Sorry, our API seems to have issues connecting to "{model}".',
|
f'Sorry, our API seems to have issues connecting to "{model}".',
|
||||||
|
@ -216,7 +223,6 @@ async def respond(
|
||||||
if (not is_stream) and server_json_response:
|
if (not is_stream) and server_json_response:
|
||||||
yield json.dumps(server_json_response)
|
yield json.dumps(server_json_response)
|
||||||
|
|
||||||
|
|
||||||
role = user.get('role', 'default')
|
role = user.get('role', 'default')
|
||||||
|
|
||||||
model_multipliers = config['costs']
|
model_multipliers = config['costs']
|
||||||
|
@ -251,8 +257,6 @@ async def respond(
|
||||||
|
|
||||||
credits_cost = round(credits_cost * role_cost_multiplier)
|
credits_cost = round(credits_cost * role_cost_multiplier)
|
||||||
|
|
||||||
print(f'[bold]Credits cost[/bold]: {credits_cost}')
|
|
||||||
|
|
||||||
create_background_task(
|
create_background_task(
|
||||||
after_request.after_request(
|
after_request.after_request(
|
||||||
provider=provider_name,
|
provider=provider_name,
|
||||||
|
|
|
@ -222,7 +222,7 @@ async def demo():
|
||||||
for func in [
|
for func in [
|
||||||
test_chat_stream_gpt3,
|
test_chat_stream_gpt3,
|
||||||
test_chat_non_stream_gpt4,
|
test_chat_non_stream_gpt4,
|
||||||
test_function_calling,
|
# test_function_calling,
|
||||||
]:
|
]:
|
||||||
print(f'[*] {func.__name__}')
|
print(f'[*] {func.__name__}')
|
||||||
result = await func()
|
result = await func()
|
||||||
|
|
Loading…
Reference in a new issue