Unverified Commit 5ff25cdf authored by yichuan~'s avatar yichuan~ Committed by GitHub
Browse files

[Minor] add delete test and delete tmp file on ci server (#1227)

parent 2f1d9283
import openai
client = openai.Client(base_url="http://127.0.0.1:30000/v1", api_key="EMPTY")
# Text completion
response = client.completions.create(
model="default",
prompt="I am a robot and I want to study like humans. Now let's tell a story. Once upon a time, there was a little",
n=1,
temperature=0.8,
max_tokens=32,
)
print(response)
# Text completion
response = client.completions.create(
model="default",
prompt="I am a robot and I want to study like humans. Now let's tell a story. Once upon a time, there was a little",
n=5,
temperature=0.8,
max_tokens=320,
)
print(response)
# Text completion
response = client.completions.create(
model="default",
prompt="I am a robot and I want to study like humans. Now let's tell a story. Once upon a time, there was a little",
n=3,
temperature=0.8,
max_tokens=32,
)
print(response)
# Text completion
response = client.completions.create(
model="default",
prompt=["The name of the famous soccer player is"],
n=1,
temperature=0.8,
max_tokens=128,
)
print(response)
# Text completion
response = client.completions.create(
model="default",
prompt=["The name of the famous soccer player is ", "The capital of US is"],
n=1,
temperature=0.8,
max_tokens=32,
)
print(response)
# Text completion
response = client.completions.create(
model="default",
prompt=["The name of the famous soccer player is ", "The capital of US is"],
n=3,
temperature=0.8,
max_tokens=32,
)
print(response)
response = client.completions.create(
model="default",
prompt=[
"prompt1: I am a robot and I want to learn like humans. Now let's begin a tale. Once upon a time, there was a small",
"prompt2: As a robot, my goal is to understand human learning. Let's start a story. In a faraway land, there lived a tiny",
"prompt3: Being a robot, I aspire to study like people. Let's share a story. Long ago, there was a little",
"prompt4: I am a robot aiming to learn like humans. Let's narrate a story. Once, in a distant kingdom, there was a young",
"prompt5: As a robot, I seek to learn in human ways. Let's tell a story. Once upon a time, in a small village, there was a young",
],
n=1,
temperature=0.8,
max_tokens=320,
)
print(response)
# Text completion
response = client.completions.create(
model="default",
prompt=[
"The capital of France is",
"The capital of Germany is",
"The capital of US is",
],
n=3,
temperature=0.8,
max_tokens=32,
)
print(response)
# Chat completion
response = client.chat.completions.create(
model="default",
messages=[
{"role": "system", "content": "You are a helpful AI assistant"},
{"role": "user", "content": "List 3 countries and their capitals."},
],
temperature=0.8,
max_tokens=1,
logprobs=True,
top_logprobs=3,
)
print(response)
# Chat completion
response = client.chat.completions.create(
model="default",
messages=[
{"role": "system", "content": "You are a helpful AI assistant"},
{"role": "user", "content": "List 3 countries and their capitals."},
],
temperature=0.8,
max_tokens=1,
n=1,
)
print(response)
# Chat completion
response = client.chat.completions.create(
model="default",
messages=[
{"role": "system", "content": "You are a helpful AI assistant"},
{"role": "user", "content": "List 3 countries and their capitals."},
],
temperature=0.8,
max_tokens=1,
logprobs=True,
top_logprobs=3,
)
print(response)
# Chat completion
response = client.chat.completions.create(
model="default",
messages=[
{"role": "system", "content": "You are a helpful AI assistant"},
{"role": "user", "content": "List 3 countries and their capitals."},
],
temperature=0.8,
max_tokens=1,
n=4,
)
print(response)
...@@ -350,11 +350,11 @@ class TestOpenAIServer(unittest.TestCase): ...@@ -350,11 +350,11 @@ class TestOpenAIServer(unittest.TestCase):
completion_window=completion_window, completion_window=completion_window,
) )
return batch_job, content return batch_job, content, uploaded_file
def run_batch(self, mode): def run_batch(self, mode):
client = openai.Client(api_key=self.api_key, base_url=self.base_url) client = openai.Client(api_key=self.api_key, base_url=self.base_url)
batch_job, content = self._create_batch(mode=mode, client=client) batch_job, content, uploaded_file = self._create_batch(mode=mode, client=client)
while batch_job.status not in ["completed", "failed", "cancelled"]: while batch_job.status not in ["completed", "failed", "cancelled"]:
time.sleep(3) time.sleep(3)
...@@ -378,10 +378,13 @@ class TestOpenAIServer(unittest.TestCase): ...@@ -378,10 +378,13 @@ class TestOpenAIServer(unittest.TestCase):
if line.strip() != "" if line.strip() != ""
] ]
assert len(results) == len(content) assert len(results) == len(content)
for delete_fid in [uploaded_file.id, result_file_id]:
del_pesponse = client.files.delete(delete_fid)
assert del_pesponse.deleted
def run_cancel_batch(self, mode): def run_cancel_batch(self, mode):
client = openai.Client(api_key=self.api_key, base_url=self.base_url) client = openai.Client(api_key=self.api_key, base_url=self.base_url)
batch_job, _ = self._create_batch(mode=mode, client=client) batch_job, _, uploaded_file = self._create_batch(mode=mode, client=client)
assert batch_job.status not in ["cancelling", "cancelled"] assert batch_job.status not in ["cancelling", "cancelled"]
...@@ -396,6 +399,8 @@ class TestOpenAIServer(unittest.TestCase): ...@@ -396,6 +399,8 @@ class TestOpenAIServer(unittest.TestCase):
time.sleep(3) time.sleep(3)
assert batch_job.status == "cancelled" assert batch_job.status == "cancelled"
del_response = client.files.delete(uploaded_file.id)
assert del_response.deleted
def test_completion(self): def test_completion(self):
for echo in [False, True]: for echo in [False, True]:
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment