biome format
This commit is contained in:
+53
-41
@@ -79,49 +79,61 @@ export const factTriggers = router({
|
||||
return { ok: true };
|
||||
}),
|
||||
generateFromFact: publicProcedure
|
||||
.input((x) => x as {
|
||||
previousRunningSummary: string;
|
||||
messagesSincePreviousRunningSummary: Array<DraftMessage>;
|
||||
mainResponseContent: string;
|
||||
fact: Fact;
|
||||
})
|
||||
.mutation(async ({ input: { previousRunningSummary, messagesSincePreviousRunningSummary, mainResponseContent, fact } }) => {
|
||||
const factTriggers = await generateObject<{
|
||||
factTriggers: Array<string>;
|
||||
}>({
|
||||
model: openrouter("mistralai/mistral-nemo"),
|
||||
messages: [
|
||||
{
|
||||
role: "system" as const,
|
||||
content: factTriggersSystemPrompt({
|
||||
previousRunningSummary,
|
||||
messagesSincePreviousRunningSummary,
|
||||
mainResponseContent,
|
||||
}),
|
||||
},
|
||||
{
|
||||
role: "user" as const,
|
||||
content: factTriggersUserPrompt({
|
||||
factContent: fact.content,
|
||||
}),
|
||||
},
|
||||
],
|
||||
schema: jsonSchema({
|
||||
type: "object",
|
||||
properties: {
|
||||
factTriggers: {
|
||||
type: "array",
|
||||
items: {
|
||||
type: "string",
|
||||
},
|
||||
.input(
|
||||
(x) =>
|
||||
x as {
|
||||
previousRunningSummary: string;
|
||||
messagesSincePreviousRunningSummary: Array<DraftMessage>;
|
||||
mainResponseContent: string;
|
||||
fact: Fact;
|
||||
},
|
||||
)
|
||||
.mutation(
|
||||
async ({
|
||||
input: {
|
||||
previousRunningSummary,
|
||||
messagesSincePreviousRunningSummary,
|
||||
mainResponseContent,
|
||||
fact,
|
||||
},
|
||||
}) => {
|
||||
const factTriggers = await generateObject<{
|
||||
factTriggers: Array<string>;
|
||||
}>({
|
||||
model: openrouter("mistralai/mistral-nemo"),
|
||||
messages: [
|
||||
{
|
||||
role: "system" as const,
|
||||
content: factTriggersSystemPrompt({
|
||||
previousRunningSummary,
|
||||
messagesSincePreviousRunningSummary,
|
||||
mainResponseContent,
|
||||
}),
|
||||
},
|
||||
{
|
||||
role: "user" as const,
|
||||
content: factTriggersUserPrompt({
|
||||
factContent: fact.content,
|
||||
}),
|
||||
},
|
||||
],
|
||||
schema: jsonSchema({
|
||||
type: "object",
|
||||
properties: {
|
||||
factTriggers: {
|
||||
type: "array",
|
||||
items: {
|
||||
type: "string",
|
||||
},
|
||||
},
|
||||
}),
|
||||
// maxSteps: 3,
|
||||
// tools: undefined,
|
||||
});
|
||||
return factTriggers;
|
||||
})
|
||||
},
|
||||
}),
|
||||
// maxSteps: 3,
|
||||
// tools: undefined,
|
||||
});
|
||||
return factTriggers;
|
||||
},
|
||||
),
|
||||
});
|
||||
|
||||
export const createCaller = createCallerFactory(factTriggers);
|
||||
|
||||
+21
-13
@@ -6,9 +6,7 @@ import {
|
||||
import { createCaller as createConversationsCaller } from "./conversations.js";
|
||||
import { openrouter } from "./provider.js";
|
||||
import { generateObject, generateText, jsonSchema } from "ai";
|
||||
import type {
|
||||
DraftMessage,
|
||||
} from "../../types.js";
|
||||
import type { DraftMessage } from "../../types.js";
|
||||
|
||||
const runningSummarySystemPrompt = ({
|
||||
previousRunningSummary,
|
||||
@@ -47,7 +45,6 @@ ${mainResponseContent}
|
||||
|
||||
Generate a new running summary of the conversation.`;
|
||||
|
||||
|
||||
export const messages = router({
|
||||
fetchByConversationId: publicProcedure
|
||||
.input((x) => x as { conversationId: string })
|
||||
@@ -58,13 +55,23 @@ export const messages = router({
|
||||
});
|
||||
}),
|
||||
generateRunningSummary: publicProcedure
|
||||
.input((x) => x as {
|
||||
previousRunningSummary: string;
|
||||
messagesSincePreviousRunningSummary: Array<DraftMessage>;
|
||||
mainResponseContent: string;
|
||||
})
|
||||
.mutation(async ({ input: { previousRunningSummary, messagesSincePreviousRunningSummary, mainResponseContent } }) => {
|
||||
const runningSummaryResponse = await generateText({
|
||||
.input(
|
||||
(x) =>
|
||||
x as {
|
||||
previousRunningSummary: string;
|
||||
messagesSincePreviousRunningSummary: Array<DraftMessage>;
|
||||
mainResponseContent: string;
|
||||
},
|
||||
)
|
||||
.mutation(
|
||||
async ({
|
||||
input: {
|
||||
previousRunningSummary,
|
||||
messagesSincePreviousRunningSummary,
|
||||
mainResponseContent,
|
||||
},
|
||||
}) => {
|
||||
const runningSummaryResponse = await generateText({
|
||||
model: openrouter("mistralai/mistral-nemo"),
|
||||
messages: [
|
||||
{
|
||||
@@ -84,8 +91,9 @@ export const messages = router({
|
||||
maxSteps: 3,
|
||||
tools: undefined,
|
||||
});
|
||||
return runningSummaryResponse;
|
||||
}),
|
||||
return runningSummaryResponse;
|
||||
},
|
||||
),
|
||||
});
|
||||
|
||||
export const createCaller = createCallerFactory(messages);
|
||||
|
||||
+7
-7
@@ -38,7 +38,6 @@ ${previousRunningSummary}
|
||||
</running_summary>
|
||||
`;
|
||||
|
||||
|
||||
export const chat = router({
|
||||
conversations,
|
||||
messages,
|
||||
@@ -139,11 +138,12 @@ export const chat = router({
|
||||
* with the model's response to the database. The new running summary is
|
||||
* based on the previous running summary combined with the all messages
|
||||
* since that summary was produced. */
|
||||
const runningSummaryResponse = await messagesCaller.generateRunningSummary({
|
||||
messagesSincePreviousRunningSummary,
|
||||
mainResponseContent: mainResponse.text,
|
||||
previousRunningSummary,
|
||||
});
|
||||
const runningSummaryResponse =
|
||||
await messagesCaller.generateRunningSummary({
|
||||
messagesSincePreviousRunningSummary,
|
||||
mainResponseContent: mainResponse.text,
|
||||
previousRunningSummary,
|
||||
});
|
||||
const insertedAssistantMessage: CommittedMessage = {
|
||||
id: nanoid(),
|
||||
conversationId,
|
||||
@@ -193,7 +193,7 @@ export const chat = router({
|
||||
mainResponseContent: mainResponse.text,
|
||||
previousRunningSummary,
|
||||
messagesSincePreviousRunningSummary,
|
||||
fact
|
||||
fact,
|
||||
});
|
||||
const insertedFactTriggers: Array<FactTrigger> =
|
||||
factTriggers.object.factTriggers.map((factTrigger) => ({
|
||||
|
||||
Reference in New Issue
Block a user