oa.stores¶
Data object layers for openai resources
Functions
|
Filter objects by date. |
|
|
|
Decorator that will extract the id from the first non-instance argument of a method. |
|
Extract the embeddings from a HttpxBinaryResponseContent object |
|
Extract the json data from a response |
|
Is a dict (or Mapping) the schema of an openai API 'task' |
Is a list (or iterable) of dicts (or Mappings) the schema of an openai API 'task' |
|
|
This function extracts the object (value) from a {object: V, index: i, V} dict which is the format you'll find in the ['response']['body']['data'] of a response. |
|
|
|
|
|
Classes
dicts that have two required fields: 'object' and 'index' |
|
A DataObject with object='embeddings' and an 'embeddings' key that is a list of floats |
|
|
A key-value store for OpenAI batches metadata. |
|
|
|
|
|
A key-value store for OpenAI files content data. |
|
|
|
A key-value store for OpenAI files content data. |
|
A key-value store for OpenAI files metadata. |
|
A key-value store for OpenAI files content data. |
|
A key-value store for OpenAI files content data. |
|
|
|
Mapping interface for files within a vector store. |
|
A key-value store for OpenAI vector stores. |
|
Base class for OpenAI vector stores mapping interface. |
- class oa.stores.DataObject[source]¶
Bases:
TypedDictdicts that have two required fields: ‘object’ and ‘index’
- class oa.stores.EmbeddingsDataObject[source]¶
Bases:
TypedDictA DataObject with object=’embeddings’ and an ‘embeddings’ key that is a list of floats
- class oa.stores.MutuableMappingHooks[source]¶
Bases:
MappingHooks
- class oa.stores.OaBatches(client=None, **extra_kwargs)[source]¶
Bases:
StoreA key-value store for OpenAI batches metadata. Keys are the batch IDs.
- append(input_file_id, *, endpoint='/v1/embeddings', completion_window='24h', metadata=None)¶
Create and submit a new batch via submitting the input file (obj or id).
- metadata(batch_id)¶
Retrieve metadata for a batch.
- Return type:
Batch
- class oa.stores.OaBatchesBase(client=None, **extra_kwargs)[source]¶
Bases:
OaMapping
- class oa.stores.OaFiles(client=None, purpose='batch', iter_filter_purpose=False, encoding='utf-8', *, file, expires_after=<openai.Omit object>, extra_headers=None, extra_query=None, extra_body=None, timeout=NOT_GIVEN)[source]¶
Bases:
StoreA key-value store for OpenAI files content data. Keys are the file IDs.
- class oa.stores.OaFilesBase(client=None, purpose='batch', iter_filter_purpose=False, encoding='utf-8', *, file, expires_after=<openai.Omit object>, extra_headers=None, extra_query=None, extra_body=None, timeout=NOT_GIVEN)[source]¶
Bases:
OaMapping
- class oa.stores.OaFilesJsonData(client=None, purpose='batch', iter_filter_purpose=False, encoding='utf-8', *, file, expires_after=<openai.Omit object>, extra_headers=None, extra_query=None, extra_body=None, timeout=NOT_GIVEN)[source]¶
Bases:
StoreA key-value store for OpenAI files content data. Keys are the file IDs. Values are the data extracted from the HttpxBinaryResponseContent object.
- class oa.stores.OaFilesMetadata(client=None, purpose='batch', iter_filter_purpose=False, encoding='utf-8', *, file, expires_after=<openai.Omit object>, extra_headers=None, extra_query=None, extra_body=None, timeout=NOT_GIVEN)[source]¶
Bases:
OaFilesBaseA key-value store for OpenAI files metadata.
- class oa.stores.OaJsonFiles(client=None, purpose='batch', iter_filter_purpose=False, encoding='utf-8', *, file, expires_after=<openai.Omit object>, extra_headers=None, extra_query=None, extra_body=None, timeout=NOT_GIVEN)[source]¶
Bases:
StoreA key-value store for OpenAI files content data. Keys are the file IDs.
- class oa.stores.OaJsonLFiles(client=None, purpose='batch', iter_filter_purpose=False, encoding='utf-8', *, file, expires_after=<openai.Omit object>, extra_headers=None, extra_query=None, extra_body=None, timeout=NOT_GIVEN)[source]¶
Bases:
StoreA key-value store for OpenAI files content data. Keys are the file IDs.
- class oa.stores.OaMapping[source]¶
Bases:
MappingHooks,KvReader
- class oa.stores.OaVectorStoreFiles(vector_store_id, client=None, **extra_kwargs)[source]¶
Bases:
OaMappingMapping interface for files within a vector store.
- class oa.stores.OaVectorStores(client=None, **extra_kwargs)[source]¶
Bases:
StoreA key-value store for OpenAI vector stores. Keys are the vector store IDs.
- get_by_name(name)¶
Get vector store by name (since OpenAI API doesn’t support this directly).
- class oa.stores.OaVectorStoresBase(client=None, **extra_kwargs)[source]¶
Bases:
OaMappingBase class for OpenAI vector stores mapping interface.
- oa.stores.date_filter(objs, min_date=None, max_date=None, *, date_extractor='created_at', stop_on_first_out_of_range=False)[source]¶
Filter objects by date.
- Parameters:
- oa.stores.extract_id(method=None, *, is_id=<function _is_string>, has_id=<function _has_id_attr>, get_id=operator.attrgetter('id'))[source]¶
Decorator that will extract the id from the first non-instance argument of a method.
>>> @extract_id ... def veni(self, vidi, vici): ... return f"{vidi=}, {vici=}" >>> assert ( ... veni(None, 'hi', vici=3) # calling the function ... == veni.__wrapped__(None, 'hi', vici=3) # outputs the same as calling the original ... == "vidi='hi', vici=3" ... )Except it now has extra powers; if your id is contained in a attribute, it’ll be extracted.
>>> from types import SimpleNamespace >>> obj = SimpleNamespace(id='hi') >>> obj.id 'hi' >>> assert veni(None, obj, vici=3) == "vidi='hi', vici=3"You can also customize the filters and the id getter. The following will resolve a string representation of an integer as an id.
>>> @extract_id(is_id=lambda x: isinstance(x, int), has_id=str.isnumeric, get_id=int) ... def add_one(self, x): ... return x ... >>> assert add_one(None, 3) == 3 >>> assert add_one(None, "42") == 42
- oa.stores.get_json_data_from_response(response)[source]¶
Extract the embeddings from a HttpxBinaryResponseContent object
- Return type:
- oa.stores.is_task_dict_list(x)[source]¶
Is a list (or iterable) of dicts (or Mappings) the schema of an openai API ‘task’
- oa.stores.object_of_data(data)[source]¶
This function extracts the object (value) from a {object: V, index: i, V} dict which is the format you’ll find in the [‘response’][‘body’][‘data’] of a response.
- Return type:
TypeVar(DataObjectValue)
>>> object_of_data({'object': 'embeddings', 'index': 3, 'embeddings': [1, 2, 3]}) [1, 2, 3]