OpenAIChatCompletion Class

OpenAI Chat completion class.

Inheritance
OpenAIChatCompletion
OpenAIChatCompletion
OpenAIChatCompletion

Constructor

OpenAIChatCompletion(ai_model_id: str | None = None, service_id: str | None = None, api_key: str | None = None, org_id: str | None = None, default_headers: Mapping[str, str] | None = None, async_client: AsyncOpenAI | None = None, env_file_path: str | None = None, env_file_encoding: str | None = None)

Parameters

Name Description
ai_model_id
str, <xref:optional>

OpenAI model name. See https://platform.openai.com/docs/models.

Default value: None
service_id
str, <xref:optional>

Service ID tied to the execution settings.

Default value: None
api_key
str, <xref:optional>

The optional API key to use. If provided, it will override the environment variables or .env file value.

Default value: None
org_id
str, <xref:optional>

The optional organization ID to use. If provided, it will override the environment variables or .env file value.

Default value: None
default_headers
Mapping[str, str], <xref:optional>

A mapping of string keys to string values for HTTP requests.

Default value: None
async_client
<xref:AsyncOpenAI>, <xref:optional>

An existing async client to use.

Default value: None
env_file_path
str, <xref:optional>

The environment settings file to use as a fallback to environment variables.

Default value: None
env_file_encoding
str, <xref:optional>

The encoding of the environment settings file.

Default value: None

Methods

from_dict

Initialize an Open AI service from a dictionary of settings.

from_dict

Initialize an Open AI service from a dictionary of settings.

from_dict(settings: dict[str, Any]) -> OpenAIChatCompletion

Parameters

Name Description
settings
Required

A dictionary of settings for the service.

Returns

Type Description

An instance of OpenAIChatCompletion.

Attributes

model_computed_fields

A dictionary of computed field names and their corresponding ComputedFieldInfo objects.

model_computed_fields: ClassVar[Dict[str, ComputedFieldInfo]] = {}

model_config

Configuration for the model, should be a dictionary conforming to [ConfigDict][pydantic.config.ConfigDict].

model_config: ClassVar[ConfigDict] = {'arbitrary_types_allowed': True, 'populate_by_name': True, 'validate_assignment': True}

model_fields

Metadata about the fields defined on the model, mapping of field names to [FieldInfo][pydantic.fields.FieldInfo] objects.

This replaces Model.fields from Pydantic V1.

model_fields: ClassVar[Dict[str, FieldInfo]] = {'ai_model_id': FieldInfo(annotation=str, required=True, metadata=[StringConstraints(strip_whitespace=True, to_upper=None, to_lower=None, strict=None, min_length=1, max_length=None, pattern=None)]), 'ai_model_type': FieldInfo(annotation=OpenAIModelTypes, required=False, default=<OpenAIModelTypes.CHAT: 'chat'>), 'client': FieldInfo(annotation=AsyncOpenAI, required=True), 'completion_tokens': FieldInfo(annotation=int, required=False, default=0), 'prompt_tokens': FieldInfo(annotation=int, required=False, default=0), 'service_id': FieldInfo(annotation=str, required=False, default=''), 'total_tokens': FieldInfo(annotation=int, required=False, default=0)}