api

package
v0.4.18 Latest Latest
Warning

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

Go to latest
Published: Oct 22, 2024 License: MIT Imports: 10 Imported by: 1

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type BaseContent

type BaseContent struct {
	Type_ ContentType `json:"type"`
}

func (BaseContent) MarshalZerologObject

func (bc BaseContent) MarshalZerologObject(e *zerolog.Event)

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

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

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

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

type Content

type Content interface {
	Type() ContentType
}

func NewImageContent

func NewImageContent(mediaType, base64Data string) Content

func NewTextContent

func NewTextContent(text string) Content

func NewToolResultContent

func NewToolResultContent(toolUseID, content string) Content

func NewToolUseContent

func NewToolUseContent(toolID, toolName string, toolInput string) Content

type ContentBlock

type ContentBlock struct {
	Type  ContentType `json:"type"`
	ID    string      `json:"id,omitempty"`
	Name  string      `json:"name,omitempty"`
	Input string      `json:"input,omitempty"`
	Text  string      `json:"text,omitempty"`
}

func (ContentBlock) MarshalZerologObject

func (cb ContentBlock) MarshalZerologObject(e *zerolog.Event)

type ContentType

type ContentType string
const (
	ContentTypeText       ContentType = "text"
	ContentTypeImage      ContentType = "image"
	ContentTypeToolUse    ContentType = "tool_use"
	ContentTypeToolResult ContentType = "tool_result"
)

type Delta

type Delta struct {
	Type         StreamingDeltaType `json:"type"`
	Text         string             `json:"text,omitempty"`
	PartialJSON  string             `json:"partial_json"`
	StopReason   string             `json:"stop_reason,omitempty"`
	StopSequence string             `json:"stop_sequence,omitempty"`
}

func (Delta) MarshalZerologObject

func (d Delta) MarshalZerologObject(e *zerolog.Event)

type Error

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

func (Error) MarshalZerologObject

func (err Error) MarshalZerologObject(e *zerolog.Event)

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 // message_start
	ID    string
	Retry int
}

Event represents a server-sent event.

type ImageContent

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

func (ImageContent) MarshalZerologObject

func (ic ImageContent) MarshalZerologObject(e *zerolog.Event)

func (ImageContent) Type

func (i ImageContent) Type() ContentType

type ImageSource

type ImageSource struct {
	BaseContent
	Type      string `json:"type"`
	MediaType string `json:"media_type"`
	Data      string `json:"data"`
}

func (ImageSource) MarshalZerologObject

func (is ImageSource) MarshalZerologObject(e *zerolog.Event)

type Message

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

Message represents a single message in the conversation.

func (*Message) UnmarshalJSON

func (m *Message) UnmarshalJSON(data []byte) error

type MessageRequest

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

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.

func (MessageResponse) FullText

func (m MessageResponse) FullText() string

FullText is a way to quickly get the entire text of the message response, for our current streaming system which only deals with full strings.

func (MessageResponse) MarshalZerologObject

func (s MessageResponse) MarshalZerologObject(e *zerolog.Event)

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 StreamingDeltaType

type StreamingDeltaType string
const (
	TextDeltaType      StreamingDeltaType = "text_delta"
	InputJSONDeltaType StreamingDeltaType = "input_json_delta"
)

type StreamingEvent

type StreamingEvent struct {
	Type         StreamingEventType `json:"type"`
	Message      *MessageResponse   `json:"message,omitempty"`
	Delta        *Delta             `json:"delta,omitempty"`
	Error        *Error             `json:"error,omitempty"`
	Index        int                `json:"index,omitempty"`
	Usage        *Usage             `json:"usage,omitempty"`
	ContentBlock *ContentBlock      `json:"content_block,omitempty"`
}

func (StreamingEvent) MarshalZerologObject

func (s StreamingEvent) MarshalZerologObject(e *zerolog.Event)

type StreamingEventType

type StreamingEventType string
const (
	PingType              StreamingEventType = "ping"
	MessageStartType      StreamingEventType = "message_start"
	ContentBlockStartType StreamingEventType = "content_block_start"
	ContentBlockDeltaType StreamingEventType = "content_block_delta"
	ContentBlockStopType  StreamingEventType = "content_block_stop"
	MessageDeltaType      StreamingEventType = "message_delta"
	MessageStopType       StreamingEventType = "message_stop"
	ErrorType             StreamingEventType = "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 TextContent

type TextContent struct {
	BaseContent
	Text string `json:"text"`
}

func (TextContent) MarshalZerologObject

func (tc TextContent) MarshalZerologObject(e *zerolog.Event)

func (TextContent) Type

func (t TextContent) Type() ContentType

type Tool

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

Tool represents a tool that the model can use.

type ToolResultContent

type ToolResultContent struct {
	BaseContent
	ToolUseID string `json:"tool_use_id"`
	Content   string `json:"content"`
}

func (ToolResultContent) MarshalZerologObject

func (trc ToolResultContent) MarshalZerologObject(e *zerolog.Event)

func (ToolResultContent) Type

func (t ToolResultContent) Type() ContentType

type ToolUseContent

type ToolUseContent struct {
	BaseContent
	ID    string `json:"id"`
	Name  string `json:"name"`
	Input string `json:"input"`
}

func (ToolUseContent) MarshalZerologObject

func (tuc ToolUseContent) MarshalZerologObject(e *zerolog.Event)

func (ToolUseContent) Type

func (t ToolUseContent) Type() ContentType

type Usage

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

Usage represents the billing and rate-limit usage information.

func (Usage) MarshalZerologObject

func (u Usage) MarshalZerologObject(e *zerolog.Event)

Jump to

Keyboard shortcuts

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