nova-api/api/providers/helpers/utils.py

57 lines
1.2 KiB
Python
Raw Normal View History

2023-10-06 23:05:38 +02:00
try:
from db import providerkeys
except ModuleNotFoundError:
from ...db import providerkeys
2023-10-05 15:06:33 +02:00
2023-10-16 23:34:54 +02:00
# Sort the models by their value/cost/rarity.
2023-10-05 15:06:33 +02:00
GPT_3 = [
2023-11-07 00:56:43 +01:00
'dall-e-2',
'code-davinci-002',
'text-davinci-002',
'text-davinci-003',
2023-10-05 15:06:33 +02:00
'gpt-3.5-turbo',
'gpt-3.5-turbo-16k',
'gpt-3.5-turbo-0613',
'gpt-3.5-turbo-0301',
'gpt-3.5-turbo-16k-0613',
2023-11-07 00:56:43 +01:00
'gpt-3.5-turbo-instruct',
2023-10-05 15:06:33 +02:00
]
GPT_4 = GPT_3 + [
'gpt-4',
'gpt-4-0314',
'gpt-4-0613',
2023-11-07 00:56:43 +01:00
'gpt-4-1106-preview',
'gpt-4-vision-preview'
2023-10-05 15:06:33 +02:00
]
GPT_4_32K = GPT_4 + [
'gpt-4-32k',
'gpt-4-32k-0314',
'gpt-4-32k-0613',
]
2023-10-14 01:15:59 +02:00
AZURE_API = '2023-08-01-preview'
2023-10-05 15:06:33 +02:00
async def random_secret_for(name: str) -> str:
2023-10-08 00:28:13 +02:00
return await providerkeys.manager.get_key(name)
2023-10-14 01:15:59 +02:00
async def azure_chat_completion(endpoint: str, provider: str, payload: dict) -> dict:
key = await random_secret_for(provider)
model = payload['model']
2023-10-15 22:35:18 +02:00
del payload['model']
deployment = model.replace('.', '')
2023-10-14 01:15:59 +02:00
return {
'method': 'POST',
'url': f'{endpoint}/openai/deployments/{deployment}/chat/completions?api-version={AZURE_API}',
'payload': payload,
'headers': {
'api-key': key
},
'provider_auth': f'{provider}>{key}'
}