Created
July 23, 2023 14:56
-
-
Save humphd/647bbaddc3099c783b9bb1908f25b64e to your computer and use it in GitHub Desktop.
ChatCraft sum function
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
/** | |
* Example Function Module. Each function needs you to define 4 things: | |
*/ | |
/* 1. Name of your function */ | |
export const name = "sum"; | |
/* 2. Description of function, used to describe what it does to an LLM */ | |
export const description = "Adds all numbers passed to it, returning the total."; | |
/** | |
* 3. A JSON Schema defining the function's parameters. See: | |
* | |
* - https://platform.openai.com/docs/guides/gpt/function-calling | |
* - https://json-schema.org/learn/getting-started-step-by-step | |
*/ | |
export const parameters = { | |
type: "object", | |
properties: { | |
"numbers": { | |
items: { | |
type: "number" | |
}, | |
description: "Array of numbers", | |
} | |
} | |
}; | |
/** | |
* 4. The function itself. Accepts an Object matching the schema | |
* defined in params, returning a Promise<string> (i.e., should be | |
* an async function). | |
*/ | |
export default async function (data) { | |
const { numbers } = data; | |
const result = numbers.reduce((acc, current) => acc + current, 0); | |
return result.toLocaleString(); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment