simple send req non chatgpt test

Lu Yao Chen 2 years ago
parent fd3a4d7c0a
commit 9754499e81
No known key found for this signature in database
GPG Key ID: 0D8EDAEEE816135F

3
.gitignore vendored

@ -11,4 +11,5 @@ usage.txt
/dalleimages
/indexes
/audiotemp
/pickles
/pickles
.idea

@ -633,10 +633,14 @@ class Model:
else:
await self.usage_service.update_usage(tokens_used)
except Exception as e:
raise ValueError(
"The API returned an invalid response: "
+ str(response["error"]["message"])
) from e
traceback.print_exc()
if 'error' in response:
raise ValueError(
"The API returned an invalid response: "
+ str(response["error"]["message"])
) from e
else:
raise ValueError("The API returned an invalid response") from e
@backoff.on_exception(
backoff.expo,
@ -1010,8 +1014,6 @@ class Model:
stop=None,
custom_api_key=None,
is_chatgpt_request=False,
) -> (
Tuple[dict, bool]
): # The response, and a boolean indicating whether or not the context limit was reached.
# Validate that all the parameters are in a good state before we send the request
@ -1057,7 +1059,7 @@ class Model:
headers=headers,
) as resp:
response = await resp.json()
# print(f"Payload -> {payload}")
print(f"Payload -> {payload}")
# Parse the total tokens used for this request and response pair from the response
await self.valid_text_request(
response, model=self.model if model is None else model

@ -0,0 +1,21 @@
from pathlib import Path
import pytest
from models.openai_model import Models, Model
from transformers import GPT2TokenizerFast
import asyncio
from services.usage_service import UsageService
import os
# Non-ChatGPT
@pytest.mark.asyncio
async def test_send_req():
usage_service = UsageService(Path("../tests"))
model = Model(usage_service)
prompt = 'how many hours are in a day?'
tokens = len(GPT2TokenizerFast.from_pretrained("gpt2")(prompt)["input_ids"])
# tokens = 60
res = await model.send_request(prompt, tokens)
assert '24' in res['choices'][0]['text']
Loading…
Cancel
Save