Skip to content

Instantly share code, notes, and snippets.

@humphd
Created July 23, 2023 14:56
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save humphd/647bbaddc3099c783b9bb1908f25b64e to your computer and use it in GitHub Desktop.
Save humphd/647bbaddc3099c783b9bb1908f25b64e to your computer and use it in GitHub Desktop.
ChatCraft sum function
/**
* 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