https://github.com/devidw/functhem
ease the integration of hermes function calling prompt format into typescript ecosystem with typed function calls
https://github.com/devidw/functhem
Last synced: 2 months ago
JSON representation
ease the integration of hermes function calling prompt format into typescript ecosystem with typed function calls
- Host: GitHub
- URL: https://github.com/devidw/functhem
- Owner: devidw
- License: mit
- Created: 2024-05-06T17:55:39.000Z (about 1 year ago)
- Default Branch: main
- Last Pushed: 2024-05-06T17:55:41.000Z (about 1 year ago)
- Last Synced: 2024-10-18T21:04:23.917Z (8 months ago)
- Language: TypeScript
- Homepage: https://www.npmjs.com/package/functhem
- Size: 8.79 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
functhemease the integration of [hermes function calling prompt format](https://github.com/NousResearch/Hermes-Function-Calling#prompt-format-for-function-calling)
into typescript ecosystem with typed function calls## what it can do
- generate system message prompt with your defined tools, zod to json schema
- parse tool call output -> typed## installation
```console
pnpm add functhem
```## usage
```ts
import { z } from "zod"
import { Tool, Functhem } from "functhem"const happySchema = z.object({
name: z.literal("isHappy"),
arguments: z.object({
isHappy: z.boolean(),
}),
})const happyTool = new Tool({
name: "isHappy",
description: "Is the user happy?",
schema: happySchema,
})const movieSchema = z.object({
name: z.literal("watchMovie"),
arguments: z.object({
genre: z.string(),
}),
})const movieTool = new Tool({
name: "watchMovie",
description:
"Does the user express that they want to see a movie, if so, which genre?",
schema: movieSchema,
})const functhem = new Functhem([happyTool, movieTool])
const sysMsg = functhem.getSysMsg()
const output = await yourInferenceFunction({
messages: [
{
role: "system",
content: functhem.getSysMsg(), // <-- HERE
},
{
role: "user",
content: `Input: so stressed, just want to see a funny movie\nProcess the user input with your tools.`,
},
],
})const outCalls = functhem.parseOut(output) // <-- HERE
outCalls.forEach((one) => {
switch (one.name) {
case "isHappy": {
console.log(one.arguments.isHappy)
break
}
case "watchMovie": {
console.log(one.arguments.genre)
break
}
}
})
```