-
Notifications
You must be signed in to change notification settings - Fork 3
/
test_vector_store_files.py
110 lines (81 loc) · 3.52 KB
/
test_vector_store_files.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
import openai
import openai_responses
from openai_responses import OpenAIMock
@openai_responses.mock()
def test_create_vector_store_file(openai_mock: OpenAIMock):
client = openai.Client(api_key="sk-fake123")
vector_store = client.beta.vector_stores.create(name="Support FAQ")
file = client.files.create(
file=open("examples/example.json", "rb"),
purpose="assistants",
)
vector_store_file = client.beta.vector_stores.files.create(
vector_store_id=vector_store.id,
file_id=file.id,
)
assert vector_store_file.vector_store_id == vector_store.id
assert vector_store_file.id == file.id
assert openai_mock.files.create.route.call_count == 1
assert openai_mock.beta.vector_stores.create.route.call_count == 1
assert openai_mock.beta.vector_stores.files.create.route.call_count == 1
@openai_responses.mock()
def test_list_vector_store_files(openai_mock: OpenAIMock):
client = openai.Client(api_key="sk-fake123")
vector_store = client.beta.vector_stores.create(name="Support FAQ")
for _ in range(10):
file = client.files.create(
file=open("examples/example.json", "rb"),
purpose="assistants",
)
client.beta.vector_stores.files.create(
vector_store_id=vector_store.id,
file_id=file.id,
)
vector_store_files = client.beta.vector_stores.files.list(vector_store.id)
assert len(vector_store_files.data) == 10
assert openai_mock.files.create.route.call_count == 10
assert openai_mock.beta.vector_stores.create.route.call_count == 1
assert openai_mock.beta.vector_stores.files.create.route.call_count == 10
assert openai_mock.beta.vector_stores.files.list.route.call_count == 1
@openai_responses.mock()
def test_retrieve_vector_store_file(openai_mock: OpenAIMock):
client = openai.Client(api_key="sk-fake123")
vector_store = client.beta.vector_stores.create(name="Support FAQ")
file = client.files.create(
file=open("examples/example.json", "rb"),
purpose="assistants",
)
vector_store_file = client.beta.vector_stores.files.create(
vector_store_id=vector_store.id,
file_id=file.id,
)
found = client.beta.vector_stores.files.retrieve(
vector_store_file.id,
vector_store_id=vector_store.id,
)
assert found.id == vector_store_file.id
assert openai_mock.files.create.route.call_count == 1
assert openai_mock.beta.vector_stores.create.route.call_count == 1
assert openai_mock.beta.vector_stores.files.create.route.call_count == 1
assert openai_mock.beta.vector_stores.files.retrieve.route.call_count == 1
@openai_responses.mock()
def test_delete_vector_store_file(openai_mock: OpenAIMock):
client = openai.Client(api_key="sk-fake123")
vector_store = client.beta.vector_stores.create(name="Support FAQ")
file = client.files.create(
file=open("examples/example.json", "rb"),
purpose="assistants",
)
vector_store_file = client.beta.vector_stores.files.create(
vector_store_id=vector_store.id,
file_id=file.id,
)
deleted = client.beta.vector_stores.files.delete(
vector_store_file.id,
vector_store_id=vector_store.id,
)
assert deleted.deleted
assert openai_mock.files.create.route.call_count == 1
assert openai_mock.beta.vector_stores.create.route.call_count == 1
assert openai_mock.beta.vector_stores.files.create.route.call_count == 1
assert openai_mock.beta.vector_stores.files.delete.route.call_count == 1