ai

package
v1.2.0 Latest Latest
Warning

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

Go to latest
Published: Mar 5, 2025 License: Apache-2.0 Imports: 1 Imported by: 0

Documentation

Overview

Package ai provides an interface for interacting with AI providers.

Index

Constants

View Source
const (
	ProviderOpenAI    string = "openai"
	ProviderAnthropic string = "anthropic"
	ProviderDatadog   string = "datadog"
)

List of supported AI providers.

Variables

This section is empty.

Functions

This section is empty.

Types

type Provider

type Provider interface {
	// Name returns the name of the provider.
	Name() string

	// Do performs a single API request to the provider's API, returning a
	// response for the provided Request.
	//
	// Do should attempt to interpret the response from the provider and return
	// it as streaming strings to ctx.App.Writer if successful.
	Do(ctx *cli.Context, req *Request) error
}

Provider represents an LLM provider such as OpenAI, Anthropic, Mistral, etc.

type Request

type Request struct {
	// Context is a string that provides additional context for the request. It
	// is only used if Content is a base64-encoded image.
	Context string

	// Model is the full name of the LLM model to use for the request, e.g.
	// "gpt-4o-mini" or "claude-3-5-sonnet-20240620".
	Model string

	// SystemPrompt is a set of instructions for the AI model to follow when
	// generating a response.
	SystemPrompt string

	// UserPrompt is a second set of instructions for the AI model to follow
	// when generating a response.
	//
	// This prompt is sent to the AI provider after the system prompt and can be
	// used to provide additional context or constraints for the response.
	UserPrompt string

	// Text represents content that is sent to the AI provider together with the
	// user prompt for generating a response.
	Text []byte

	// Image represents an image attachment that is sent to the AI provider
	// together with the user prompt for generating a response.
	Image []byte

	// Temperature is a float between 0 and 1 that controls the randomness of
	// the response. A value of 0 will always return the most likely token,
	// while a value of 1 will sample from the distribution of tokens.
	Temperature float32
}

Request represents an HTTP request to an AI provider's API.

func NewRequest

func NewRequest(text []byte, model, userPrompt, systemPrompt string, temperature float32) *Request

NewRequest returns a new Request instance for a text-based user prompt.

func NewRequestWithImage

func NewRequestWithImage(image []byte, model, context, userPrompt, systemPrompt string, temperature float32) *Request

NewRequestWithImage returns a new Request instance for an user prompt with a base64-encoded image attachment.

Directories

Path Synopsis
Package anthropic provides a client wrapper for the Anthropic API that complies with the ai.Provider interface.
Package anthropic provides a client wrapper for the Anthropic API that complies with the ai.Provider interface.
Package datadog provides a client wrapper for the Datadog AI proxy API that complies with the ai.Provider interface.
Package datadog provides a client wrapper for the Datadog AI proxy API that complies with the ai.Provider interface.
Package openai provides a client wrapper for the OpenAI API that complies with the ai.Provider interface.
Package openai provides a client wrapper for the OpenAI API that complies with the ai.Provider interface.

Jump to

Keyboard shortcuts

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