merge main and remove book resturant and accommodation tools/uis
This commit is contained in:
@@ -63,7 +63,9 @@ export async function extraction(
|
||||
.describe("The end date of the trip. Should be in YYYY-MM-DD format"),
|
||||
numberOfGuests: z
|
||||
.number()
|
||||
.describe("The number of guests for the trip. Should default to 2 if not specified"),
|
||||
.describe(
|
||||
"The number of guests for the trip. Should default to 2 if not specified",
|
||||
),
|
||||
});
|
||||
|
||||
const model = new ChatOpenAI({ model: "gpt-4o", temperature: 0 }).bindTools([
|
||||
@@ -126,6 +128,6 @@ Extract only what is specified by the user. It is okay to leave fields blank if
|
||||
|
||||
return {
|
||||
tripDetails: extractionDetailsWithDefaults,
|
||||
messages: [response, extractToolResponse]
|
||||
messages: [response, extractToolResponse],
|
||||
};
|
||||
}
|
||||
|
||||
@@ -7,14 +7,12 @@ import { LangGraphRunnableConfig } from "@langchain/langgraph";
|
||||
import { getAccommodationsListProps } from "../utils/get-accommodations";
|
||||
import { findToolCall } from "../../find-tool-call";
|
||||
|
||||
const listAccommodationsSchema = z.object({}).describe("A tool to list accommodations for the user")
|
||||
const bookAccommodationSchema = z.object({
|
||||
accommodationName: z.string().describe("The name of the accommodation to book a reservation for"),
|
||||
}).describe("A tool to book a reservation for an accommodation");
|
||||
const listRestaurantsSchema = z.object({}).describe("A tool to list restaurants for the user");
|
||||
const bookRestaurantSchema = z.object({
|
||||
restaurantName: z.string().describe("The name of the restaurant to book a reservation for"),
|
||||
}).describe("A tool to book a reservation for a restaurant");
|
||||
const listAccommodationsSchema = z
|
||||
.object({})
|
||||
.describe("A tool to list accommodations for the user");
|
||||
const listRestaurantsSchema = z
|
||||
.object({})
|
||||
.describe("A tool to list restaurants for the user");
|
||||
|
||||
const ACCOMMODATIONS_TOOLS = [
|
||||
{
|
||||
@@ -22,21 +20,11 @@ const ACCOMMODATIONS_TOOLS = [
|
||||
description: "A tool to list accommodations for the user",
|
||||
schema: listAccommodationsSchema,
|
||||
},
|
||||
{
|
||||
name: "book-accommodation",
|
||||
description: "A tool to book a reservation for an accommodation",
|
||||
schema: bookAccommodationSchema,
|
||||
},
|
||||
{
|
||||
name: "list-restaurants",
|
||||
description: "A tool to list restaurants for the user",
|
||||
schema: listRestaurantsSchema,
|
||||
},
|
||||
{
|
||||
name: "book-restaurant",
|
||||
description: "A tool to book a reservation for a restaurant",
|
||||
schema: bookRestaurantSchema,
|
||||
},
|
||||
];
|
||||
|
||||
export async function callTools(
|
||||
@@ -49,7 +37,9 @@ export async function callTools(
|
||||
|
||||
const ui = typedUi<typeof ComponentMap>(config);
|
||||
|
||||
const llm = new ChatOpenAI({ model: "gpt-4o", temperature: 0 }).bindTools(ACCOMMODATIONS_TOOLS);
|
||||
const llm = new ChatOpenAI({ model: "gpt-4o", temperature: 0 }).bindTools(
|
||||
ACCOMMODATIONS_TOOLS,
|
||||
);
|
||||
|
||||
const response = await llm.invoke([
|
||||
{
|
||||
@@ -63,47 +53,40 @@ export async function callTools(
|
||||
const listAccommodationsToolCall = response.tool_calls?.find(
|
||||
findToolCall("list-accommodations")<typeof listAccommodationsSchema>,
|
||||
);
|
||||
const bookAccommodationToolCall = response.tool_calls?.find(
|
||||
findToolCall("book-accommodation")<typeof bookAccommodationSchema>,
|
||||
);
|
||||
const listRestaurantsToolCall = response.tool_calls?.find(
|
||||
findToolCall("list-restaurants")<typeof listRestaurantsSchema>,
|
||||
);
|
||||
const bookRestaurantToolCall = response.tool_calls?.find(
|
||||
findToolCall("book-restaurant")<typeof bookRestaurantSchema>,
|
||||
);
|
||||
|
||||
if (!listAccommodationsToolCall && !bookAccommodationToolCall && !listRestaurantsToolCall && !bookRestaurantToolCall) {
|
||||
if (!listAccommodationsToolCall && !listRestaurantsToolCall) {
|
||||
throw new Error("No tool calls found");
|
||||
}
|
||||
|
||||
if (listAccommodationsToolCall) {
|
||||
ui.write("accommodations-list", {
|
||||
toolCallId: listAccommodationsToolCall.id ?? "",
|
||||
...getAccommodationsListProps(state.tripDetails),
|
||||
});
|
||||
}
|
||||
if (bookAccommodationToolCall && bookAccommodationToolCall.args.accommodationName) {
|
||||
ui.write("book-accommodation", {
|
||||
tripDetails: state.tripDetails,
|
||||
accommodationName: bookAccommodationToolCall.args.accommodationName,
|
||||
});
|
||||
ui.push(
|
||||
{
|
||||
name: "accommodations-list",
|
||||
content: {
|
||||
toolCallId: listAccommodationsToolCall.id ?? "",
|
||||
...getAccommodationsListProps(state.tripDetails),
|
||||
},
|
||||
},
|
||||
{ message: response },
|
||||
);
|
||||
}
|
||||
|
||||
if (listRestaurantsToolCall) {
|
||||
ui.write("restaurants-list", { tripDetails: state.tripDetails });
|
||||
}
|
||||
|
||||
if (bookRestaurantToolCall && bookRestaurantToolCall.args.restaurantName) {
|
||||
ui.write("book-restaurant", {
|
||||
tripDetails: state.tripDetails,
|
||||
restaurantName: bookRestaurantToolCall.args.restaurantName,
|
||||
});
|
||||
ui.push(
|
||||
{
|
||||
name: "restaurants-list",
|
||||
content: { tripDetails: state.tripDetails },
|
||||
},
|
||||
{ message: response },
|
||||
);
|
||||
}
|
||||
|
||||
return {
|
||||
messages: [response],
|
||||
ui: ui.collect as TripPlannerUpdate["ui"],
|
||||
ui: ui.items,
|
||||
timestamp: Date.now(),
|
||||
};
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user