openai / Exports / OpenAIConversationAdapter
Class: OpenAIConversationAdapter
OpenAI Conversation Adapter
Converts between UniversalMessage format and OpenAI native types. Provides bidirectional conversion for seamless integration.
Table of contents
Constructors
Methods
Constructors
constructor
• new OpenAIConversationAdapter(): OpenAIConversationAdapter
Returns
Methods
filterMessagesForOpenAI
▸ filterMessagesForOpenAI(messages): UniversalMessage[]
Filter messages for OpenAI compatibility
OpenAI has specific requirements:
- Tool messages must have valid toolCallId
- Messages must be in proper sequence
- Tool messages without toolCallId should be excluded
Parameters
| Name | Type |
|---|---|
messages | UniversalMessage[] |
Returns
UniversalMessage[]
Defined in
toOpenAIFormat
▸ toOpenAIFormat(messages): ChatCompletionMessageParam[]
Convert UniversalMessage array to OpenAI message format Now properly handles tool messages for OpenAI's tool calling feature
Parameters
| Name | Type |
|---|---|
messages | UniversalMessage[] |
Returns
ChatCompletionMessageParam[]
Defined in
convertMessage
▸ convertMessage(msg): ChatCompletionMessageParam
Convert a single UniversalMessage to OpenAI format Handles all message types including tool messages
Parameters
| Name | Type |
|---|---|
msg | UniversalMessage |
Returns
ChatCompletionMessageParam
Defined in
addSystemPromptIfNeeded
▸ addSystemPromptIfNeeded(messages, systemPrompt?): ChatCompletionMessageParam[]
Add system prompt to message array if needed
Parameters
| Name | Type |
|---|---|
messages | ChatCompletionMessageParam[] |
systemPrompt? | string |
Returns
ChatCompletionMessageParam[]