Embedding module for PyRIT to provide OpenAI text embedding class.
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 | `Optional[str | Callable[[], str |
endpoint | Optional[str] | The API endpoint URL. For Azure: https://{resource}.openai.azure.com/openai/v1 For platform OpenAI: https://None. |
model_name | Optional[str] | The model/deployment name (e.g., “text-embedding-3-small”). Defaults to OPENAI_EMBEDDING_MODEL environment variable. Defaults to None. |
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