Skip to content

Commit

Permalink
fix(adapters): correctly format messages in OpenAI adapter
Browse files Browse the repository at this point in the history
Signed-off-by: Tomas Dvorak <[email protected]>
  • Loading branch information
Tomas2D committed Nov 26, 2024
1 parent d2eb5b3 commit 6728ef6
Showing 1 changed file with 9 additions and 6 deletions.
15 changes: 9 additions & 6 deletions src/adapters/openai/chat.ts
Original file line number Diff line number Diff line change
Expand Up @@ -164,17 +164,20 @@ export class OpenAIChatLLM extends ChatLLM<OpenAIChatLLMOutput> {
input: BaseMessage[],
options?: GenerateOptions,
): Client.Chat.ChatCompletionCreateParams {
type OpenAIMessage =
| Client.Chat.ChatCompletionSystemMessageParam
| Client.Chat.ChatCompletionUserMessageParam
| Client.Chat.ChatCompletionAssistantMessageParam;

return {
...this.parameters,
model: this.modelId,
stream: false,
messages: input.map(
(message) =>
({
role: message.role,
content: message.text,
response_metadata: message.meta,
}) as Client.Chat.ChatCompletionMessageParam,
(message): OpenAIMessage => ({
role: message.role as OpenAIMessage["role"],
content: message.text,
}),
),
response_format: (() => {
if (options?.guided?.json) {
Expand Down

0 comments on commit 6728ef6

Please sign in to comment.