Embedding module for PyRIT to provide OpenAI text embedding class.
Functions¶
get_lazy_dir¶
get_lazy_dir(module_globals: dict[str, Any], exports: Mapping[str, LazyExport]) → list[str]Return package attributes and unresolved public exports.
| Parameter | Type | Description |
|---|---|---|
module_globals | dict[str, Any] | The package globals. |
exports | Mapping[str, LazyExport] | Public names and their implementation locations. |
Returns:
list[str]— list[str]: Sorted package attribute names.
resolve_lazy_export¶
resolve_lazy_export(name: str, module_name: str, module_globals: dict[str, Any], exports: Mapping[str, LazyExport]) → AnyResolve and cache one package export.
| Parameter | Type | Description |
|---|---|---|
name | str | Public attribute requested from the package. |
module_name | str | Package name used in an AttributeError. |
module_globals | dict[str, Any] | Package globals where the resolved value is cached. |
exports | Mapping[str, LazyExport] | Public names and their implementation locations. |
Returns:
Any— The resolved public value.
Raises:
AttributeError— Ifnameis not a declared lazy export.
OpenAITextEmbedding¶
Bases: EmbeddingSupport
Text embedding class that works with both Azure OpenAI and platform OpenAI endpoints. Uses the AsyncOpenAI client under the hood for both providers since they share the same API.
Constructor Parameters:
| Parameter | Type | Description |
|---|---|---|
api_key | `str | Callable[[], str |
endpoint | `str | None` |
model_name | `str | None` |
Examples:
Methods:
generate_text_embedding¶
generate_text_embedding(text: str, kwargs: Any = {}) → EmbeddingResponseGenerate text embedding synchronously by calling the async method.
| Parameter | Type | Description |
|---|---|---|
text | str | The text to generate the embedding for |
**kwargs | Any | Additional arguments to pass to the embeddings API Defaults to {}. |
Returns:
EmbeddingResponse— The embedding response
generate_text_embedding_async¶
generate_text_embedding_async(text: str, kwargs: Any = {}) → EmbeddingResponseGenerate text embedding asynchronously.
| Parameter | Type | Description |
|---|---|---|
text | str | The text to generate the embedding for |
**kwargs | Any | Additional arguments to pass to the embeddings API Defaults to {}. |
Returns:
EmbeddingResponse— The embedding response