feat: add reasoning model (#750)
Co-authored-by: Matt Apperson <me@mattapperson.com>
This commit is contained in:
parent
76804269c4
commit
c61d4f91d4
19 changed files with 342 additions and 209 deletions
22
lib/utils.ts
22
lib/utils.ts
|
|
@ -1,9 +1,10 @@
|
|||
import type {
|
||||
CoreAssistantMessage,
|
||||
CoreMessage,
|
||||
CoreToolMessage,
|
||||
Message,
|
||||
TextStreamPart,
|
||||
ToolInvocation,
|
||||
ToolSet,
|
||||
} from 'ai';
|
||||
import { type ClassValue, clsx } from 'clsx';
|
||||
import { twMerge } from 'tailwind-merge';
|
||||
|
|
@ -96,6 +97,7 @@ export function convertToUIMessages(
|
|||
}
|
||||
|
||||
let textContent = '';
|
||||
let reasoning: string | undefined = undefined;
|
||||
const toolInvocations: Array<ToolInvocation> = [];
|
||||
|
||||
if (typeof message.content === 'string') {
|
||||
|
|
@ -111,6 +113,8 @@ export function convertToUIMessages(
|
|||
toolName: content.toolName,
|
||||
args: content.args,
|
||||
});
|
||||
} else if (content.type === 'reasoning') {
|
||||
reasoning = content.reasoning;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -119,6 +123,7 @@ export function convertToUIMessages(
|
|||
id: message.id,
|
||||
role: message.role as Message['role'],
|
||||
content: textContent,
|
||||
reasoning,
|
||||
toolInvocations,
|
||||
});
|
||||
|
||||
|
|
@ -129,9 +134,13 @@ export function convertToUIMessages(
|
|||
type ResponseMessageWithoutId = CoreToolMessage | CoreAssistantMessage;
|
||||
type ResponseMessage = ResponseMessageWithoutId & { id: string };
|
||||
|
||||
export function sanitizeResponseMessages(
|
||||
messages: Array<ResponseMessage>,
|
||||
): Array<ResponseMessage> {
|
||||
export function sanitizeResponseMessages({
|
||||
messages,
|
||||
reasoning,
|
||||
}: {
|
||||
messages: Array<ResponseMessage>;
|
||||
reasoning: string | undefined;
|
||||
}) {
|
||||
const toolResultIds: Array<string> = [];
|
||||
|
||||
for (const message of messages) {
|
||||
|
|
@ -157,6 +166,11 @@ export function sanitizeResponseMessages(
|
|||
: true,
|
||||
);
|
||||
|
||||
if (reasoning) {
|
||||
// @ts-expect-error: reasoning message parts in sdk is wip
|
||||
sanitizedContent.push({ type: 'reasoning', reasoning });
|
||||
}
|
||||
|
||||
return {
|
||||
...message,
|
||||
content: sanitizedContent,
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue