fix(main.py): fix translation to text_completions format for async text completion calls

This commit is contained in:
Krrish Dholakia 2024-03-30 09:02:51 -07:00
parent 89471ba4c5
commit c0204310ee
3 changed files with 41 additions and 9 deletions

View file

@ -2,7 +2,8 @@
## Tests /chat/completions by generating a key and then making a chat completions request
import pytest
import asyncio
import aiohttp
import aiohttp, openai
from openai import OpenAI
async def generate_key(session):
@ -114,14 +115,14 @@ async def completion(session, key):
async with session.post(url, headers=headers, json=data) as response:
status = response.status
response_text = await response.text()
print(response_text)
print()
if status != 200:
raise Exception(f"Request did not return a 200 status code: {status}")
response = await response.json()
return response
@pytest.mark.asyncio
async def test_completion():
@ -137,7 +138,17 @@ async def test_completion():
await completion(session=session, key=key)
key_gen = await new_user(session=session)
key_2 = key_gen["key"]
await completion(session=session, key=key_2)
# response = await completion(session=session, key=key_2)
## validate openai format ##
client = OpenAI(api_key=key_2, base_url="http://0.0.0.0:4000")
client.completions.create(
model="gpt-4",
prompt="Say this is a test",
max_tokens=7,
temperature=0,
)
async def embeddings(session, key):