Big News: Socket raises $60M Series C at a $1B valuation to secure software supply chains for AI-driven development.Announcement
Sign In

functhem

Package Overview
Dependencies
Maintainers
1
Versions
1
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

functhem

functhem

latest
npmnpm
Version
12024.5.6
Version published
Maintainers
1
Created
Source

functhem

ease the integration of hermes function calling prompt format 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

pnpm add functhem

usage

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<typeof happySchema>({
  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<typeof movieSchema>({
  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
    }
  }
})

FAQs

Package last updated on 06 May 2024

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts