llm

package
v0.0.2 Latest Latest
Warning

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

Go to latest
Published: Jun 11, 2026 License: Apache-2.0 Imports: 12 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type ChatRequest

type ChatRequest struct {
	Model  string `json:"model"`
	Prompt string `json:"prompt"`
	Stream bool   `json:"stream"`
}

ChatRequest is the payload sent to Ollama.

type ChatResponse

type ChatResponse struct {
	Response string `json:"response"`
	Done     bool   `json:"done"`
}

ChatResponse represents one chunk of streamed output.

type NIMChatMessage

type NIMChatMessage struct {
	Role    string `json:"role"`
	Content string `json:"content"`
}

type NIMChatRequest

type NIMChatRequest struct {
	Model       string           `json:"model"`
	Messages    []NIMChatMessage `json:"messages"`
	Stream      bool             `json:"stream"`
	MaxTokens   int              `json:"max_tokens,omitempty"`
	Temperature float64          `json:"temperature,omitempty"`
}

type NIMChatResponse

type NIMChatResponse struct {
	ID      string `json:"id"`
	Object  string `json:"object"`
	Created int64  `json:"created"`
	Model   string `json:"model"`
	Choices []struct {
		Index        int            `json:"index"`
		Message      NIMChatMessage `json:"message"`
		FinishReason string         `json:"finish_reason"`
	} `json:"choices"`
	Error *struct {
		Message string `json:"message"`
		Type    string `json:"type"`
		Param   string `json:"param,omitempty"`
		Code    string `json:"code,omitempty"`
	} `json:"error,omitempty"`
}

type NIMProvider

type NIMProvider struct {
	// contains filtered or unexported fields
}

NIMProvider handles LLM interactions with NVIDIA NIM API.

func NewNIMProvider

func NewNIMProvider(baseURL, apiKey string) (*NIMProvider, error)

NewNIMProvider creates a new NVIDIA NIM provider. The baseURL should be the API endpoint (e.g., "https://api.nvidia.com/v1") The apiKey is the NVIDIA API key. If empty, it reads from NVIDIA_API_KEY env var. Returns an error if the API key is missing.

func (*NIMProvider) Generate

func (p *NIMProvider) Generate(ctx context.Context, prompt, model string) error

Generate streams response from the NIM API.

func (*NIMProvider) GenerateSync

func (p *NIMProvider) GenerateSync(ctx context.Context, prompt, model string) (string, error)

GenerateSync returns the full response as a string (non-streaming).

type NIMStreamChunk

type NIMStreamChunk struct {
	ID      string `json:"id"`
	Object  string `json:"object"`
	Created int64  `json:"created"`
	Model   string `json:"model"`
	Choices []struct {
		Index        int            `json:"index"`
		Delta        NIMChatMessage `json:"delta"`
		FinishReason string         `json:"finish_reason"`
	} `json:"choices"`
}

type Provider

type Provider struct {
	// contains filtered or unexported fields
}

Provider handles LLM interactions.

func NewProvider

func NewProvider(baseURL string) *Provider

NewProvider creates a new LLM provider.

func (*Provider) Generate

func (p *Provider) Generate(ctx context.Context, prompt, model string) error

Generate streams response from the LLM.

func (*Provider) GenerateSync

func (p *Provider) GenerateSync(ctx context.Context, prompt, model string) (string, error)

GenerateSync returns the full response as a string (non-streaming).

type ProviderInterface

type ProviderInterface interface {
	Generate(ctx context.Context, prompt, model string) error
	GenerateSync(ctx context.Context, prompt, model string) (string, error)
}

ProviderInterface defines the contract for LLM providers.

Jump to

Keyboard shortcuts

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