Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 54fd1d3

Browse files
LeVinhGithubHarry Le
andauthored
task: expand e2e Assistant (menloresearch#2084)
* test: check on ci * test: check all in ci * test: fix * test: fix 2 * test: fix 3 --------- Co-authored-by: Harry Le <[email protected]>
1 parent 0c5dac4 commit 54fd1d3

File tree

6 files changed

+548
-0
lines changed

6 files changed

+548
-0
lines changed
Lines changed: 165 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,165 @@
1+
import pytest
2+
import requests
3+
from utils.test_runner import start_server, stop_server
4+
import jsonschema
5+
from utils.logger import log_response
6+
from utils.assertion import assert_equal
7+
8+
9+
class TestApiCreateAssistant:
10+
11+
@pytest.fixture(autouse=True)
12+
def setup_and_teardown(self):
13+
# Setup
14+
success = start_server()
15+
if not success:
16+
raise Exception("Failed to start server")
17+
18+
yield
19+
20+
# Teardown
21+
stop_server()
22+
23+
def test_api_create_assistant_successfully(self):
24+
headers = {
25+
"Content-Type": "application/json",
26+
}
27+
28+
data = {
29+
"description": "",
30+
"instructions": "",
31+
"metadata": {
32+
"ANY_ADDITIONAL_PROPERTY": "anything"
33+
},
34+
"model": "tinyllama:1b",
35+
"name": "test_assistant",
36+
"response_format": "auto",
37+
"temperature": 1,
38+
"tool_resources": {
39+
"code_interpreter": {},
40+
"file_search": {}
41+
},
42+
"tools": [
43+
{
44+
"type": "code_interpreter"
45+
}
46+
],
47+
"top_p": 1
48+
}
49+
50+
post_assistant_url = "http://localhost:3928/v1/assistants"
51+
res=requests.get(post_assistant_url)
52+
log_response(res.text, "test_api_create_assistant_successfully")
53+
54+
55+
response = requests.post(
56+
post_assistant_url, headers=headers, json=data
57+
)
58+
log_response(response.text, "test_api_create_assistant_successfully")
59+
json_data = response.json()
60+
assert_equal(response.status_code,200)
61+
62+
schema = {
63+
"properties": {
64+
"created_at": {
65+
"description": "Unix timestamp (in seconds) of when the assistant was created.",
66+
"type": "integer"
67+
},
68+
"description": {
69+
"description": "The description of the assistant.",
70+
"type": "string"
71+
},
72+
"id": {
73+
"description": "The unique identifier of the assistant.",
74+
"type": "string"
75+
},
76+
"instructions": {
77+
"description": "Instructions for the assistant's behavior.",
78+
"type": "string"
79+
},
80+
"metadata": {
81+
"additionalProperties": True,
82+
"description": "Set of key-value pairs that can be attached to the assistant.",
83+
"type": "object"
84+
},
85+
"model": {
86+
"description": "The model identifier used by the assistant.",
87+
"type": "string"
88+
},
89+
"name": {
90+
"description": "The name of the assistant.",
91+
"type": "string"
92+
},
93+
"object": {
94+
"description": "The object type, which is always 'assistant'.",
95+
"enum": [
96+
"assistant"
97+
],
98+
"type": "string"
99+
},
100+
"response_format": {
101+
"oneOf": [
102+
{
103+
"enum": [
104+
"auto"
105+
],
106+
"type": "string"
107+
},
108+
{
109+
"type": "object"
110+
}
111+
]
112+
},
113+
"temperature": {
114+
"description": "Temperature parameter for response generation.",
115+
"format": "float",
116+
"type": "number"
117+
},
118+
"tool_resources": {
119+
"description": "Resources used by the assistant's tools.",
120+
"properties": {
121+
"code_interpreter": {
122+
"type": "object"
123+
},
124+
"file_search": {
125+
"type": "object"
126+
}
127+
},
128+
"type": "object"
129+
},
130+
"tools": {
131+
"description": "A list of tools enabled on the assistant.",
132+
"items": {
133+
"properties": {
134+
"type": {
135+
"enum": [
136+
"code_interpreter",
137+
"file_search",
138+
"function"
139+
],
140+
"type": "string"
141+
}
142+
},
143+
"type": "object"
144+
},
145+
"type": "array"
146+
},
147+
"top_p": {
148+
"description": "Top p parameter for response generation.",
149+
"format": "float",
150+
"type": "number"
151+
}
152+
},
153+
"required": [
154+
"id",
155+
"object",
156+
"created_at",
157+
"model",
158+
"metadata"
159+
],
160+
"type": "object"
161+
}
162+
163+
# Validate response schema
164+
jsonschema.validate(instance=json_data, schema=schema)
165+
Lines changed: 95 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,95 @@
1+
import pytest
2+
import requests
3+
from utils.test_runner import start_server, stop_server
4+
import jsonschema
5+
from utils.logger import log_response
6+
from utils.assertion import assert_equal
7+
8+
9+
class TestApiDeleteAssistant:
10+
11+
@pytest.fixture(autouse=True)
12+
def setup_and_teardown(self):
13+
# Setup
14+
success = start_server()
15+
if not success:
16+
raise Exception("Failed to start server")
17+
18+
yield
19+
20+
# Teardown
21+
stop_server()
22+
23+
def test_api_delete_assistant_successfully(self):
24+
headers = {
25+
"Content-Type": "application/json",
26+
}
27+
28+
data = {
29+
"description": "",
30+
"instructions": "",
31+
"metadata": {
32+
"ANY_ADDITIONAL_PROPERTY": "anything"
33+
},
34+
"model": "tinyllama:1b",
35+
"name": "test_assistant",
36+
"response_format": "auto",
37+
"temperature": 1,
38+
"tool_resources": {
39+
"code_interpreter": {},
40+
"file_search": {}
41+
},
42+
"tools": [
43+
{
44+
"type": "code_interpreter"
45+
}
46+
],
47+
"top_p": 1
48+
}
49+
50+
assistant_url = "http://localhost:3928/v1/assistants"
51+
response = requests.post(
52+
assistant_url, headers=headers, json=data
53+
)
54+
json_data = response.json()
55+
log_response(json_data, "test_api_delete_assistant_successfully")
56+
assert_equal(response.status_code,200)
57+
58+
assistant_id=json_data["id"]
59+
60+
# Get list assistant
61+
assistantid_url=f"http://localhost:3928/v1/assistants/{assistant_id}"
62+
response_del_assistant = requests.delete(
63+
assistantid_url
64+
)
65+
json_data_del_assistant = response_del_assistant.json()
66+
log_response(json_data_del_assistant, "test_api_delete_assistant_successfully")
67+
assert_equal(response_del_assistant.status_code,200)
68+
69+
schema = {
70+
"$schema": "http://json-schema.org/draft-07/schema#",
71+
"type": "object",
72+
"properties": {
73+
"deleted": {
74+
"type": "boolean"
75+
},
76+
"id": {
77+
"type": "string"
78+
},
79+
"object": {
80+
"type": "string",
81+
"enum": ["assistant.deleted"]
82+
}
83+
},
84+
"required": ["deleted", "id", "object"]
85+
}
86+
87+
88+
# Validate response schema
89+
jsonschema.validate(instance=json_data_del_assistant, schema=schema)
90+
91+
# Assert content
92+
assert_equal(json_data_del_assistant["deleted"], True)
93+
assert_equal(json_data_del_assistant["id"], assistant_id)
94+
assert_equal(json_data_del_assistant["object"], "assistant.deleted")
95+
Lines changed: 112 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,112 @@
1+
import pytest
2+
import requests
3+
from utils.test_runner import start_server, stop_server
4+
import jsonschema
5+
from utils.logger import log_response
6+
from utils.assertion import assert_equal
7+
8+
9+
class TestApiGetAssistant:
10+
11+
@pytest.fixture(autouse=True)
12+
def setup_and_teardown(self):
13+
# Setup
14+
success = start_server()
15+
if not success:
16+
raise Exception("Failed to start server")
17+
18+
yield
19+
20+
# Teardown
21+
stop_server()
22+
23+
def test_api_get_assistant_successfully(self):
24+
headers = {
25+
"Content-Type": "application/json",
26+
}
27+
28+
data = {
29+
"description": "",
30+
"instructions": "",
31+
"metadata": {
32+
"ANY_ADDITIONAL_PROPERTY": "anything"
33+
},
34+
"model": "tinyllama:1b",
35+
"name": "test_assistant",
36+
"response_format": "auto",
37+
"temperature": 1,
38+
"tool_resources": {
39+
"code_interpreter": {},
40+
"file_search": {}
41+
},
42+
"tools": [
43+
{
44+
"type": "code_interpreter"
45+
}
46+
],
47+
"top_p": 1
48+
}
49+
50+
assistant_url = "http://localhost:3928/v1/assistants"
51+
response = requests.post(
52+
assistant_url, headers=headers, json=data
53+
)
54+
json_data = response.json()
55+
log_response(json_data, "test_api_get_assistant_successfully")
56+
assert_equal(response.status_code,200)
57+
58+
assistant_id=json_data["id"]
59+
60+
# Get list assistant
61+
headers = {
62+
"OpenAI-Beta": "assistants=v2"
63+
}
64+
assistantid_url=f"http://localhost:3928/v1/assistants/{assistant_id}"
65+
response_assistant = requests.get(
66+
assistantid_url, headers= headers
67+
)
68+
json_data_assistant = response_assistant.json()
69+
log_response(json_data_assistant, "test_api_get_assistant_successfully")
70+
assert_equal(response_assistant.status_code,200)
71+
72+
schema = {
73+
"properties": {
74+
"created_at": {
75+
"description": "Unix timestamp (in seconds) of when the assistant was created.",
76+
"type": "integer"
77+
},
78+
"id": {
79+
"description": "The unique identifier of the assistant.",
80+
"type": "string"
81+
},
82+
"metadata": {
83+
"additionalProperties": True,
84+
"description": "Set of key-value pairs attached to the assistant.",
85+
"type": "object"
86+
},
87+
"model": {
88+
"description": "The model identifier used by the assistant.",
89+
"type": "string"
90+
},
91+
"object": {
92+
"description": "The object type, which is always 'assistant'.",
93+
"enum": [
94+
"assistant"
95+
],
96+
"type": "string"
97+
}
98+
},
99+
"required": [
100+
"id",
101+
"object",
102+
"created_at",
103+
"model",
104+
"metadata"
105+
],
106+
"type": "object"
107+
}
108+
109+
# Validate response schema
110+
jsonschema.validate(instance=json_data_assistant, schema=schema)
111+
assert_equal(json_data_assistant["id"], assistant_id)
112+

0 commit comments

Comments
 (0)