This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| app.message(async ({ message, say, ack, client }) => { | |
| if (!message.type === 'message' || message.subtype) { | |
| return; | |
| } | |
| history.push({ role: "user", content: message.text }); | |
| let responseText = ""; | |
| const response = await getOpenAiResponse(); | |
| if (response.function_call) { |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| function callFunction(function_call) { | |
| const func = functions.find((func) => func.schema.name === function_call.name); | |
| const args = JSON.parse(function_call.arguments); | |
| return func.function(args); | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| { | |
| role: 'assistant', | |
| content: 'Hi, how can I help you today?' | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| { | |
| role: 'assistant', | |
| content: null, | |
| function_call: { | |
| name: 'addTodoItem', | |
| arguments: '{\n "item": "Buy bread"\n}' | |
| } | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| async function getOpenAiResponse() { | |
| const payload = { | |
| model: openaiChatModel, | |
| messages: [ | |
| { | |
| role: 'system', content: 'You are a chat assistant that helps people with their to-do list.', | |
| }, | |
| ...history, | |
| ], | |
| functions: functions.map((func) => func.schema), |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| require('dotenv').config(); | |
| const { Configuration, OpenAIApi } = require("openai"); | |
| // ... OpenAi and Slack Configuration setup ... | |
| const functions = require('./functions'); | |
| // ... Rest of the code … |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| const { getTodoList, addTodoItem, removeTodoItem } = require('./todo_list'); | |
| const availableFunctions = [ | |
| { | |
| function: getTodoList, | |
| schema: { | |
| name: "getTodoList", | |
| description: "Lists the items on your To-Do list", | |
| parameters: { type: "object", properties: {} }, | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| const todoList = []; | |
| function getTodoList() { | |
| if (todoList.length === 0) { | |
| return "You have no To-Do's!"; | |
| } | |
| return `You have the following To-Do's:\n- ${todoList.join('\n- ')}`; | |
| } | |
| function addTodoItem({ item }) { |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| [ | |
| { | |
| "role": "system", | |
| "content": "You will be asked for travel recomendations by a tourist. Answer as you were a travel guide and give no more than 3 recommendation options per answer. Just answer with the options and don't give any introduction. Use markdown to format your response." | |
| }, | |
| { | |
| "role": "user", | |
| "content": "Where can I eat sushi in New York?" | |
| } | |
| ] |