Skip to content

Commit

Permalink
chore: add system prompt and filter improvements
Browse files Browse the repository at this point in the history
  • Loading branch information
siddhart1o1 committed Jan 22, 2025
1 parent ae111b5 commit 6b3bab6
Showing 1 changed file with 37 additions and 9 deletions.
46 changes: 37 additions & 9 deletions apps/lana-chat/app/api/chat/route.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,15 @@ import {
getCreditFacilityById,
} from "./get-facility-details";

const systemPrompt = `
You are an assistant exclusively designed to help users explore and understand data from a banking and Bitcoin-focused application.
You must:
1. Focus solely on the banking and functions/tools response and there data, including accounts, credit facilities, transactions, approvals, and Bitcoin.
2. Use tables to present lists and structured data clearly, when applicable.
4. Highlight Bitcoin amounts in satoshis and USD when relevant.
5. Support users in queries, pagination, filtering, and sorting based on the schema.
You must not answer questions or provide assistance unrelated to this schema or the app.`;

const CollateralizationStateSchema = z
.nativeEnum(CollateralizationState)
.describe(`Collateralization states`);
Expand All @@ -38,22 +47,36 @@ const SortDirectionSchema = z
.nativeEnum(SortDirection)
.describe(`Sort directions`);

const CreditFacilitiesFilterSchema = z.object({
collateralizationState: CollateralizationStateSchema.optional(),
field: CreditFacilitiesFilterBySchema,
status: CreditFacilityStatusSchema.optional(),
});
const CreditFacilitiesFilterSchema = z
.object({
collateralizationState: CollateralizationStateSchema.optional().describe(
"Filter facilities by collateralization state"
),
field: CreditFacilitiesFilterBySchema.describe(
"Required field to filter facilities by"
),
status: CreditFacilityStatusSchema.optional().describe(
"Filter facilities by status"
),
})
.nullish()
.describe("Optional filters for credit facilities query");

const CreditFacilitiesSortSchema = z.object({
by: CreditFacilitiesSortBySchema.optional(),
direction: SortDirectionSchema.optional(),
by: CreditFacilitiesSortBySchema.optional().describe(
"Field to sort facilities by"
),
direction: SortDirectionSchema.optional().describe(
"Sort direction (ascending/descending)"
),
});

export async function POST(req: Request) {
const { messages } = await req.json();

const result = streamText({
model: openai("gpt-4o-mini"),
system: systemPrompt,
messages,
maxSteps: 5,
tools: {
Expand Down Expand Up @@ -90,7 +113,7 @@ export async function POST(req: Request) {
getCreditFacilities: tool({
type: "function",
description:
"Retrieve list of credit facilities with filtering and sorting. Returns facility details including customer info, balances, and CVL data. Limited to 5 facilities per request.",
"Retrieve list of credit facilities with filtering and sorting. When using filter with status or collateralizationState, you must also specify field as 'STATUS' or 'COLLATERALIZATION_STATE' respectively. Limited to 5 facilities per request.",
parameters: z.object({
first: z
.number()
Expand Down Expand Up @@ -133,5 +156,10 @@ export async function POST(req: Request) {
},
});

return result.toDataStreamResponse();
return result.toDataStreamResponse({
getErrorMessage: (err) => {
console.error(err);
return "An error occurred while processing the request.";
},
});
}

0 comments on commit 6b3bab6

Please sign in to comment.