claude

package
v0.4.10 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jun 3, 2024 License: MIT Imports: 19 Imported by: 1

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func IsClaudeEngine

func IsClaudeEngine(engine string) bool

Types

type Client

type Client struct {
	APIKey     string
	APIVersion string
	BaseURL    string
	// contains filtered or unexported fields
}

Client represents the Claude API client.

func NewClient

func NewClient(apiKey string, baseURL string, apiVersion ...string) *Client

NewClient initializes and returns a new API client.

func (*Client) Complete

func (c *Client) Complete(req *Request) (*SuccessfulResponse, error)

Complete sends a completion request and returns the response.

func (*Client) SendMessage added in v0.4.6

func (c *Client) SendMessage(ctx context.Context, req *MessageRequest) (*MessageResponse, error)

SendMessage sends a message request and returns the response.

func (*Client) StreamComplete

func (c *Client) StreamComplete(req *Request) (<-chan Event, error)

func (*Client) StreamMessage added in v0.4.6

func (c *Client) StreamMessage(ctx context.Context, req *MessageRequest) (<-chan Event, error)

StreamMessage sends a message request and returns a channel of Events for streaming responses.

type Content added in v0.4.6

type Content struct {
	Type    string          `json:"type"`
	Text    *string         `json:"text,omitempty"`
	Image   *ImageContent   `json:"image,omitempty"`
	ToolUse *ToolUseContent `json:"tool_use,omitempty"`
}

Content represents a single block of content, which can be of various types.

func NewImageContent added in v0.4.6

func NewImageContent(mediaType, base64Data string) Content

NewImageContent creates a new image content block with base64-encoded data.

func NewTextContent added in v0.4.6

func NewTextContent(text string) Content

NewTextContent creates a new text content block.

func NewToolUseContent added in v0.4.6

func NewToolUseContent(toolID, toolName string, toolInput json.RawMessage) Content

NewToolUseContent creates a new tool use content block.

type ErrorDetail

type ErrorDetail struct {
	Type    string `json:"type"`
	Message string `json:"message"`
}

ErrorDetail contains error details.

type ErrorResponse

type ErrorResponse struct {
	Error ErrorDetail `json:"error"`
}

ErrorResponse represents the API's error response.

type Event

type Event struct {
	Data  string
	Event string
	ID    string
	Retry int
}

Event represents a server-sent event.

type ImageContent added in v0.4.6

type ImageContent struct {
	Source ImageSource `json:"source"`
}

ImageContent represents an image content block.

type ImageSource added in v0.4.6

type ImageSource struct {
	Type      string `json:"type"`       // e.g., "base64"
	MediaType string `json:"media_type"` // e.g., "image/jpeg"
	Data      string `json:"data"`
}

ImageSource represents the source of an image, which can be a base64-encoded string.

type Message added in v0.4.6

type Message struct {
	Role    string          `json:"role"`
	Content json.RawMessage `json:"content"` // Can be a string or an array of content blocks
}

Message represents a single message in the conversation.

type MessageRequest added in v0.4.6

type MessageRequest struct {
	Model         string    `json:"model"`
	Messages      []Message `json:"messages"`
	MaxTokens     int       `json:"max_tokens"`
	Metadata      *Metadata `json:"metadata,omitempty"`
	StopSequences []string  `json:"stop_sequences,omitempty"`
	Stream        bool      `json:"stream"`
	System        string    `json:"system,omitempty"`
	Temperature   *float64  `json:"temperature,omitempty"`
	Tools         []Tool    `json:"tools,omitempty"`
	TopK          *int      `json:"top_k,omitempty"`
	TopP          *float64  `json:"top_p,omitempty"`
}

MessageRequest represents the Messages API request payload.

type MessageResponse added in v0.4.6

type MessageResponse struct {
	ID           string    `json:"id"`
	Type         string    `json:"type"`
	Role         string    `json:"role"`
	Content      []Content `json:"content"`
	Model        string    `json:"model"`
	StopReason   string    `json:"stop_reason,omitempty"`
	StopSequence string    `json:"stop_sequence,omitempty"`
	Usage        Usage     `json:"usage"`
}

MessageResponse represents the Messages API response payload.

type Metadata

type Metadata struct {
}

Metadata represents the metadata object.

type Request

type Request struct {
	Model             string    `json:"model"`
	Prompt            string    `json:"prompt"`
	MaxTokensToSample int       `json:"max_tokens_to_sample"`
	StopSequences     []string  `json:"stop_sequences,omitempty"`
	Temperature       *float64  `json:"temperature,omitempty"`
	TopP              *float64  `json:"top_p,omitempty"`
	TopK              *int      `json:"top_k,omitempty"`
	Metadata          *Metadata `json:"metadata,omitempty"`
	Stream            bool      `json:"stream"`
}

Request represents the completion request payload.

type Step

type Step struct {
	Settings *settings.StepSettings
	// contains filtered or unexported fields
}

func NewStep added in v0.2.24

func NewStep(settings *settings.StepSettings) *Step

func (*Step) AddPublishedTopic added in v0.4.1

func (csf *Step) AddPublishedTopic(publisher message.Publisher, topic string) error

func (*Step) Interrupt added in v0.2.24

func (csf *Step) Interrupt()

func (*Step) Start

func (csf *Step) Start(
	ctx context.Context,
	messages conversation.Conversation,
) (steps.StepResult[string], error)

type SuccessfulResponse

type SuccessfulResponse struct {
	Completion string `json:"completion"`
	StopReason string `json:"stop_reason"`
	Model      string `json:"model"`
}

SuccessfulResponse represents the API's successful response.

type Tool added in v0.4.6

type Tool struct {
	Name        string          `json:"name"`
	Description string          `json:"description,omitempty"`
	InputSchema json.RawMessage `json:"input_schema"` // JSON schema for the tool input
}

Tool represents a tool that the model can use.

type ToolUseContent added in v0.4.6

type ToolUseContent struct {
	ID     string          `json:"id"`
	Name   string          `json:"name"`
	Input  json.RawMessage `json:"input"`            // JSON structure for the tool input
	Result *string         `json:"result,omitempty"` // Optional result of the tool use
}

ToolUseContent represents a content block where the model uses a tool.

type Usage added in v0.4.6

type Usage struct {
	InputTokens  int `json:"input_tokens"`
	OutputTokens int `json:"output_tokens"`
}

Usage represents the billing and rate-limit usage information.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL