llm

package
v1.8.1 Latest Latest
Warning

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

Go to latest
Published: Jun 7, 2026 License: MIT Imports: 7 Imported by: 0

Documentation

Overview

SPDX-License-Identifier: MIT Purpose: NVIDIA NIM-specific helpers. NIM exposes an OpenAI-compatible chat/completions endpoint at https://integrate.api.nvidia.com/v1 and serves many vendor models. Friendly aliases like "haiku" or "qwen" resolve to a working NIM model ID.

SPDX-License-Identifier: MIT Purpose: generic OpenAI-compatible LLM client. Single-shot chat completion request with bearer auth, JSON marshaling, and typed response decoding.

Index

Constants

View Source
const NIMDefaultBaseURL = "https://integrate.api.nvidia.com/v1"
View Source
const NIMDefaultModel = "meta/llama-3.3-70b-instruct"
View Source
const NIMGptOssModel = "openai/gpt-oss-120b"
View Source
const NIMHaikuModel = "nvidia/llama-3.1-nemotron-nano-8b-v1"
View Source
const NIMKimiModel = "moonshotai/kimi-k2.6"
View Source
const NIMNemotronModel = "nvidia/nemotron-3-nano-30b-a3b"
View Source
const NIMQwenModel = "qwen/qwen3-coder-480b-a35b-instruct"

Variables

View Source
var NIMModelAliases = map[string]string{
	"haiku":         NIMHaikuModel,
	"kimi":          NIMKimiModel,
	"qwen":          NIMQwenModel,
	"nemotron":      NIMNemotronModel,
	"gpt-oss":       NIMGptOssModel,
	"llama-70b":     NIMDefaultModel,
	"llama-3.3-70b": NIMDefaultModel,
	"llama-8b":      "meta/llama-3.1-8b-instruct",
	"default":       NIMDefaultModel,
}

Functions

func ResolveModel

func ResolveModel(name string) string

Types

type ChatRequest

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

type ChatResponse

type ChatResponse struct {
	ID      string `json:"id"`
	Object  string `json:"object"`
	Created int64  `json:"created"`
	Model   string `json:"model"`
	Choices []struct {
		Index        int     `json:"index"`
		Message      Message `json:"message"`
		FinishReason string  `json:"finish_reason"`
	} `json:"choices"`
	Usage struct {
		PromptTokens     int `json:"prompt_tokens"`
		CompletionTokens int `json:"completion_tokens"`
		TotalTokens      int `json:"total_tokens"`
	} `json:"usage"`
}

func (*ChatResponse) ExtractText

func (r *ChatResponse) ExtractText() string

type Client

type Client struct {
	BaseURL string
	APIKey  string
	HTTP    *http.Client
}

func NewClient

func NewClient(baseURL, apiKey string) *Client

func (*Client) Chat

func (c *Client) Chat(ctx context.Context, req ChatRequest) (*ChatResponse, error)

type Message

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

Jump to

Keyboard shortcuts

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