Skip to content

Commit

Permalink
Fix experimental_buildOpenAIMessages (update OpenAI SDK types to 4.29…
Browse files Browse the repository at this point in the history
….0) (#1148)
  • Loading branch information
lgrammel committed Mar 13, 2024
1 parent ce009e2 commit 3f9bf3e
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 21 deletions.
5 changes: 5 additions & 0 deletions .changeset/polite-meals-melt.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'ai': patch
---

Updates types to OpenAI SDK 4.29.0
56 changes: 35 additions & 21 deletions packages/core/prompts/openai.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,6 @@ export function experimental_buildOpenAIMessages(
return {
role: message.role,
content: message.content,
name: message.name,
tool_call_id: message.tool_call_id,
} satisfies ChatCompletionMessageParam;
}
Expand All @@ -87,24 +86,36 @@ export interface ChatCompletionSystemMessageParam {
/**
* The contents of the system message.
*/
content: string | null;
content: string;

/**
* The role of the messages author, in this case `system`.
*/
role: 'system';

/**
* An optional name for the participant. Provides the model information to
* differentiate between participants of the same role.
*/
name?: string;
}

export interface ChatCompletionUserMessageParam {
/**
* The contents of the user message.
*/
content: string | Array<ChatCompletionContentPart> | null;
content: string | Array<ChatCompletionContentPart>;

/**
* The role of the messages author, in this case `user`.
*/
role: 'user';

/**
* An optional name for the participant. Provides the model information to
* differentiate between participants of the same role.
*/
name?: string;
}

export type ChatCompletionContentPart =
Expand Down Expand Up @@ -135,34 +146,42 @@ export interface ChatCompletionContentPartImage {
export namespace ChatCompletionContentPartImage {
export interface ImageURL {
/**
* Specifies the detail level of the image.
* Either a URL of the image or the base64 encoded image data.
*/
detail?: 'auto' | 'low' | 'high';
url: string;

/**
* Either a URL of the image or the base64 encoded image data.
* Specifies the detail level of the image. Learn more in the
* [Vision guide](https://platform.openai.com/docs/guides/vision/low-or-high-fidelity-image-understanding).
*/
url?: string;
detail?: 'auto' | 'low' | 'high';
}
}

export interface ChatCompletionAssistantMessageParam {
/**
* The contents of the assistant message.
* The role of the messages author, in this case `assistant`.
*/
content: string | null;
role: 'assistant';

/**
* The role of the messages author, in this case `assistant`.
* The contents of the assistant message. Required unless `tool_calls` or
* `function_call` is specified.
*/
role: 'assistant';
content?: string | null;

/**
* Deprecated and replaced by `tool_calls`. The name and arguments of a function
* that should be called, as generated by the model.
* @deprecated: Deprecated and replaced by `tool_calls`. The name and arguments of
* a function that should be called, as generated by the model.
*/
function_call?: ChatCompletionAssistantMessageParam.FunctionCall;

/**
* An optional name for the participant. Provides the model information to
* differentiate between participants of the same role.
*/
name?: string;

/**
* The tool calls generated by the model, such as function calls.
*/
Expand All @@ -171,8 +190,8 @@ export interface ChatCompletionAssistantMessageParam {

export namespace ChatCompletionAssistantMessageParam {
/**
* Deprecated and replaced by `tool_calls`. The name and arguments of a function
* that should be called, as generated by the model.
* @deprecated: Deprecated and replaced by `tool_calls`. The name and arguments of
* a function that should be called, as generated by the model.
*/
export interface FunctionCall {
/**
Expand Down Expand Up @@ -231,18 +250,13 @@ export interface ChatCompletionToolMessageParam {
/**
* The contents of the tool message.
*/
content: string | null;
content: string;

/**
* The role of the messages author, in this case `tool`.
*/
role: 'tool';

/**
* The name of the function that this message is responding to.
*/

name: string;
/**
* Tool call that this message is responding to.
*/
Expand Down

0 comments on commit 3f9bf3e

Please sign in to comment.