Last active
July 28, 2023 11:12
-
-
Save tarasglek/5b2761d8e899581929ef20704046e80e to your computer and use it in GitHub Desktop.
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 = "turnIntoChatCraftModule"; | |
/* 2. Description of function, used to describe what it does to an LLM */ | |
export const description = "Exports a javascript/typescript function+docs into a chatcraft module consisting of javascript function with json-schema params"; | |
/** | |
* 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": { | |
"anonymousDefaultFunction": { | |
"type": "string", | |
"description": `Javascript code for the function in \`export default async function (data) { ... }\` format. | |
Not the function foo(param1, param2) format | |
` | |
}, | |
"params": { | |
"type": "object", | |
"description": "Arguments passed into the function. Should translate javascript arguments into JSON-schema. This is a required param." | |
}, | |
"description": { | |
"type": "string", | |
"description": "Description of what the function does" | |
}, | |
"name": { | |
"type": "string", | |
"description": "Name for the function" | |
} | |
}, | |
"required": ["function", "params", "description", "name"] | |
}; | |
/** | |
* 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) { | |
return '```javascript\n' + ` | |
export const name = "${data['name']}" | |
export const parameters = ${JSON.stringify(data['params'], null, 2)} | |
export const description = ${data['description']} | |
${data['anonymousDefaultFunction']} | |
`.trim() + '\n```' | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment