Skip to article frontmatterSkip to article content
Site not loading correctly?

This may be due to an incorrect BASE_URL configuration. See the MyST Documentation for reference.

pyrit.embedding

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:

ParameterTypeDescription
api_key`Optional[strCallable[[], str
endpointOptional[str]The API endpoint URL. For Azure: https://{resource}.openai.azure.com/openai/v1 For platform OpenAI: https://api.openai.com/v1 Defaults to OPENAI_EMBEDDING_ENDPOINT environment variable. Defaults to None.
model_nameOptional[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 = {}) → EmbeddingResponse

Generate text embedding synchronously by calling the async method.

ParameterTypeDescription
textstrThe text to generate the embedding for
**kwargsAnyAdditional arguments to pass to the embeddings API Defaults to {}.

Returns:

generate_text_embedding_async

generate_text_embedding_async(text: str, kwargs: Any = {}) → EmbeddingResponse

Generate text embedding asynchronously.

ParameterTypeDescription
textstrThe text to generate the embedding for
**kwargsAnyAdditional arguments to pass to the embeddings API Defaults to {}.

Returns: