-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(routes): add vector store and vector store file routes (#48)
* chore(poetry): bump faker-openai-api-provider minor version * feat(stores): add vector store state store * feat(types): add partial vector store * feat(routes): add create vector store route * chore(docs): mark create vector store route as supported * chore(docs): mark vector stores route as supported * feat(routes): add remaining vector store routes * chore(docs): add note about vector store endpoints support * feat(routes): add vector store files create route * feat(routes): add vector store files list route * feat(types): make partial pagination generic * feat(routes): add vector store file retrieve route * feat(routes): add vector store file delete route * chore(docs): add note about vector store file endpoints support * fix(types): typeddict with variadic generic support https://stackoverflow.com/a/78065164
- Loading branch information
Showing
23 changed files
with
891 additions
and
90 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,70 @@ | ||
import openai | ||
|
||
import openai_responses | ||
from openai_responses import OpenAIMock | ||
|
||
|
||
@openai_responses.mock() | ||
def test_create_vector_store(openai_mock: OpenAIMock): | ||
client = openai.Client(api_key="sk-fake123") | ||
|
||
vector_store = client.beta.vector_stores.create(name="Support FAQ") | ||
|
||
assert vector_store.name == "Support FAQ" | ||
assert openai_mock.beta.vector_stores.create.route.call_count == 1 | ||
|
||
|
||
@openai_responses.mock() | ||
def test_list_vector_stores(openai_mock: OpenAIMock): | ||
client = openai.Client(api_key="sk-fake123") | ||
|
||
for i in range(10): | ||
client.beta.vector_stores.create(name=f"vector-store-{i}") | ||
|
||
vector_stores = client.beta.vector_stores.list() | ||
|
||
assert len(vector_stores.data) == 10 | ||
assert openai_mock.beta.vector_stores.create.route.call_count == 10 | ||
assert openai_mock.beta.vector_stores.list.route.call_count == 1 | ||
|
||
|
||
@openai_responses.mock() | ||
def test_retrieve_vector_store(openai_mock: OpenAIMock): | ||
client = openai.Client(api_key="sk-fake123") | ||
|
||
vector_store = client.beta.vector_stores.create(name="Support FAQ") | ||
|
||
found = client.beta.vector_stores.retrieve(vector_store.id) | ||
|
||
assert vector_store.name == "Support FAQ" | ||
assert found.name == vector_store.name | ||
assert openai_mock.beta.vector_stores.create.route.call_count == 1 | ||
assert openai_mock.beta.vector_stores.retrieve.route.call_count == 1 | ||
|
||
|
||
@openai_responses.mock() | ||
def test_update_vector_store(openai_mock: OpenAIMock): | ||
client = openai.Client(api_key="sk-fake123") | ||
|
||
vector_store = client.beta.vector_stores.create(name="Support FAQ") | ||
|
||
updated = client.beta.vector_stores.update( | ||
vector_store.id, | ||
name="Support FAQ Updated", | ||
) | ||
|
||
assert updated.id == vector_store.id | ||
assert updated.name == "Support FAQ Updated" | ||
assert openai_mock.beta.vector_stores.create.route.call_count == 1 | ||
assert openai_mock.beta.vector_stores.update.route.call_count == 1 | ||
|
||
|
||
@openai_responses.mock() | ||
def test_delete_vector_store(openai_mock: OpenAIMock): | ||
client = openai.Client(api_key="sk-fake123") | ||
|
||
vector_store = client.beta.vector_stores.create(name="Support FAQ") | ||
|
||
assert client.beta.vector_stores.delete(vector_store.id).deleted | ||
assert openai_mock.beta.vector_stores.create.route.call_count == 1 | ||
assert openai_mock.beta.vector_stores.delete.route.call_count == 1 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.