GoFlowGoFlow
GuideLLMs

Anthropic

Using Anthropic Claude models with GoFlow

Supported Models

ModelContextBest For
claude-3-5-sonnet-20241022200KBest balance of intelligence and speed
claude-3-5-haiku-20241022200KExtremely fast and affordable
claude-3-opus-20240229200KMost capable legacy model
claude-3-sonnet-20240229200KPrevious generation balanced model
claude-3-haiku-20240307200KPrevious fast model

Usage

Initialization

import "github.com/nuulab/goflow/pkg/llm/anthropic"
 
// Default: claude-3-5-sonnet
llm := anthropic.New("")
 
// Specify model
llm := anthropic.New("", anthropic.WithModel("claude-3-5-haiku-20241022"))
 
// With custom options
llm := anthropic.New("sk-ant-your-key",
    anthropic.WithModel("claude-3-opus-20240229"),
    anthropic.WithTimeout(120*time.Second),
)

System Prompts

Anthropic handles system prompts differently from user messages. GoFlow abstracts this away and automatically extracts system prompts from your message history.

response, err := llm.GenerateChat(ctx, []core.Message{
    {Role: core.RoleSystem, Content: "You are a pirate."},  // Automatically extracted and sent as system prompt
    {Role: core.RoleUser, Content: "Hello!"},
})
// Response: "Ahoy, matey!"

On this page