| 86 | } |
| 87 | } |
| 88 | export async function functionCalling(query: string) { |
| 89 | try { |
| 90 | const messages = [ |
| 91 | { role: "system", content: "You are a function calling agent. You will be given a query and a list of functions. Your task is to call the appropriate function based on the query and return the result in JSON format. ONLY CALL A FUNCTION IF YOU ARE HIGHLY CONFIDENT IT WILL BE USED" }, |
| 92 | { role: "user", content: query }, |
| 93 | ]; |
| 94 | const tools = [ |
| 95 | { |
| 96 | type: "function", |
| 97 | function: { |
| 98 | name: "getTickers", |
| 99 | description: "Get a single market name and stock ticker if the user mentions a public company", |
| 100 | parameters: { |
| 101 | type: "object", |
| 102 | properties: { |
| 103 | ticker: { |
| 104 | type: "string", |
| 105 | description: "The stock ticker symbol and market name, example NYSE:K or NASDAQ:AAPL", |
| 106 | }, |
| 107 | }, |
| 108 | required: ["ticker"], |
| 109 | }, |
| 110 | }, |
| 111 | }, |
| 112 | { |
| 113 | type: "function", |
| 114 | function: { |
| 115 | name: "searchPlaces", |
| 116 | description: "ONLY SEARCH for places using the given query and location", |
| 117 | parameters: { |
| 118 | type: "object", |
| 119 | properties: { |
| 120 | query: { |
| 121 | type: "string", |
| 122 | description: "The search query for places", |
| 123 | }, |
| 124 | location: { |
| 125 | type: "string", |
| 126 | description: "The location to search for places", |
| 127 | }, |
| 128 | }, |
| 129 | required: ["query", "location"], |
| 130 | }, |
| 131 | }, |
| 132 | }, |
| 133 | { |
| 134 | type: "function", |
| 135 | function: { |
| 136 | name: "goShopping", |
| 137 | description: "Search for shopping items using the given query", |
| 138 | parameters: { |
| 139 | type: "object", |
| 140 | properties: { |
| 141 | query: { |
| 142 | type: "string", |
| 143 | description: "The search query for shopping items", |
| 144 | }, |
| 145 | }, |