mirror of
https://github.com/rowboatlabs/rowboat.git
synced 2026-06-03 19:25:19 +02:00
housekeeping
This commit is contained in:
parent
43498f44fc
commit
5802964932
1 changed files with 0 additions and 52 deletions
|
|
@ -1,8 +1,3 @@
|
|||
import { z } from "zod";
|
||||
import { generateObject } from "ai";
|
||||
import { openai } from "@ai-sdk/openai";
|
||||
import { Message } from "./types/types";
|
||||
|
||||
// create a PrefixLogger class that wraps console.log with a prefix
|
||||
// and allows chaining with a parent logger
|
||||
export class PrefixLogger {
|
||||
|
|
@ -28,51 +23,4 @@ export class PrefixLogger {
|
|||
child(childPrefix: string): PrefixLogger {
|
||||
return new PrefixLogger(childPrefix, this);
|
||||
}
|
||||
}
|
||||
|
||||
export async function mockToolResponse(toolId: string, messages: z.infer<typeof Message>[], mockInstructions: string): Promise<string> {
|
||||
const prompt = `Given below is a chat between a user and a customer support assistant.
|
||||
The assistant has requested a tool call with ID {{toolID}}.
|
||||
|
||||
Your job is to come up with the data that the tool call should return.
|
||||
|
||||
In order to help you mock the responses, the user has provided some contextual information,
|
||||
and also some instructions on how to mock the tool call.
|
||||
|
||||
>>>CHAT_HISTORY
|
||||
{{messages}}
|
||||
<<<END_OF_CHAT_HISTORY
|
||||
|
||||
>>>MOCK_INSTRUCTIONS
|
||||
{{mockInstructions}}
|
||||
<<<END_OF_MOCK_INSTRUCTIONS
|
||||
|
||||
The current date is {{date}}.
|
||||
`
|
||||
.replace('{{toolID}}', toolId)
|
||||
.replace(`{{date}}`, new Date().toISOString())
|
||||
.replace('{{mockInstructions}}', mockInstructions)
|
||||
.replace('{{messages}}', JSON.stringify(messages.map((m) => {
|
||||
let tool_calls;
|
||||
if ('tool_calls' in m && m.role == 'assistant') {
|
||||
tool_calls = m.tool_calls;
|
||||
}
|
||||
let { role, content } = m;
|
||||
return {
|
||||
role,
|
||||
content,
|
||||
tool_calls,
|
||||
}
|
||||
})));
|
||||
// console.log(prompt);
|
||||
|
||||
const { object } = await generateObject({
|
||||
model: openai("gpt-4o"),
|
||||
prompt: prompt,
|
||||
schema: z.object({
|
||||
result: z.any(),
|
||||
}),
|
||||
});
|
||||
|
||||
return JSON.stringify(object);
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue