I’m using Assistant Api to get list of projects from my API in the json format.
[
{
"id": 1,
"createdAt": "2024-05-08T18:11:45.099Z",
"updatedAt": "2024-05-08T18:11:45.095Z",
"name": "Purchase",
},
{
"id": 2,
"createdAt": "2024-05-08T18:11:45.099Z",
"updatedAt": "2024-05-08T18:11:45.095Z",
"name": "Sales",
},
]
I have declared a function to my assistant api:
{
type: "function" as const,
function: {
name: "getProjects",
description:
"Get list of projects in a json format which needs to be additionally filtered by area parameter. After calling this function, filter it additionally with area by finding projects that correspond to this name",
parameters: {
type: "object",
properties: {
environment: {
type: "string",
description: "environment",
},
area: {
type: "string",
description: "The area of projects",
},
},
required: [],
},
},
handler: async ({ environment, area }: { environment: string; area: string }) => {
if (!environment) return "environment param missing. Ask user to provide it";
if (!area) return "area param missing. Ask user to provide it";
const projects = await client.getProjects();
const projectsPrompt = `Filter the following list of projects by ${area}: ${JSON.stringify(projects)}`;
return projectsPrompt;
},
},
Then I’m passing the result into toolsOutput and call
runResponse = await assistantsClient.submitToolOutputsToRun(
runResponse.threadId,
runResponse.id,
toolOutputs,
);
Additionally in the instructions for assistant I put:
If user asks for projects, make sure to filter them out by area
parameter. E.g if user passes Sales area, you should find projects in
the response of a function and find only projects related to Sales
Now after sending a message
Give me list of projects in Sales area and dev env
I’m getting
Here is the list of projects in the Sales area and dev environment:
Purchase
Sales
Please let me know if there's anything else I can assist you with.
But instead I want the model to filter out the projects so it displays only Sales.
If in the next message I say that it’s wrong, it’s corrected fine.
If I take json with projects as a string and put it directly in the message and ask to filter it, it will do it correctly. So it looks like sending prompt as an output of a tool doesn’t work. Is there a way to ask the model to do something with the result of my function?