Skip to content

Fantasy

Fantasy is Charm's Go library for LLM inference. Hyper has first-class support for it.

Installation

bash
go get charm.land/fantasy

Usage

go
package main

import (
	"context"
	"fmt"
	"os"

	"charm.land/fantasy"
	"charm.land/fantasy/providers/openaicompat"
)

func main() {
	provider, _ := openaicompat.New(
		openaicompat.WithBaseURL("https://hyper.charm.land/v1"),
		openaicompat.WithAPIKey("sk-hyper-xxxxxxxxxxxxxxxxxxxxxxxx"),
	)

	ctx := context.Background()
	model, _ := provider.LanguageModel(ctx, "deepseek-v4-pro")

	agent := fantasy.NewAgent(model)
	result, err := agent.Generate(ctx, fantasy.AgentCall{Prompt: "Hello!"})
	if err != nil {
		fmt.Fprintln(os.Stderr, err)
		os.Exit(1)
	}
	fmt.Println(result.Response.Content.Text())
}