openrouter

package
v0.6.1 Latest Latest
Warning

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

Go to latest
Published: Jul 7, 2026 License: BSD-3-Clause Imports: 17 Imported by: 0

Documentation

Overview

Copyright 2025 National Technology and Engineering Solutions of Sandia SPDX-License-Identifier: BSD-3-Clause

Copyright 2025 National Technology and Engineering Solutions of Sandia SPDX-License-Identifier: BSD-3-Clause

Copyright 2025 National Technology and Engineering Solutions of Sandia SPDX-License-Identifier: BSD-3-Clause

Copyright 2025 National Technology and Engineering Solutions of Sandia SPDX-License-Identifier: BSD-3-Clause

Copyright 2025 National Technology and Engineering Solutions of Sandia SPDX-License-Identifier: BSD-3-Clause

Copyright 2025 National Technology and Engineering Solutions of Sandia SPDX-License-Identifier: BSD-3-Clause

Copyright 2025 National Technology and Engineering Solutions of Sandia SPDX-License-Identifier: BSD-3-Clause

Copyright 2025 National Technology and Engineering Solutions of Sandia SPDX-License-Identifier: BSD-3-Clause

Copyright 2025 National Technology and Engineering Solutions of Sandia SPDX-License-Identifier: BSD-3-Clause

Copyright 2025 National Technology and Engineering Solutions of Sandia SPDX-License-Identifier: BSD-3-Clause

Copyright 2025 National Technology and Engineering Solutions of Sandia SPDX-License-Identifier: BSD-3-Clause

Copyright 2025 National Technology and Engineering Solutions of Sandia SPDX-License-Identifier: BSD-3-Clause

Copyright 2025 National Technology and Engineering Solutions of Sandia SPDX-License-Identifier: BSD-3-Clause

Copyright 2025 National Technology and Engineering Solutions of Sandia SPDX-License-Identifier: BSD-3-Clause

Copyright 2025 National Technology and Engineering Solutions of Sandia SPDX-License-Identifier: BSD-3-Clause

Copyright 2025 National Technology and Engineering Solutions of Sandia SPDX-License-Identifier: BSD-3-Clause

Copyright 2025 National Technology and Engineering Solutions of Sandia SPDX-License-Identifier: BSD-3-Clause

Copyright 2025 National Technology and Engineering Solutions of Sandia SPDX-License-Identifier: BSD-3-Clause

Index

Constants

View Source
const (
	BibIdFormatUnknown      string = bibliography.BibIDFormatUnknown
	BibIdFormatNumeric      string = bibliography.BibIDFormatNumeric
	BibIdFormatAlphanumeric string = bibliography.BibIDFormatAlphanumeric
)
View Source
const (
	ModelLlama3170BInstruct string = "meta-llama/llama-3.1-70b-instruct"
	ModelGemini25Flash      string = "google/gemini-2.5-flash"

	ProviderAmazonBedrock string = "amazon-bedrock"
)

Variables

This section is empty.

Functions

This section is empty.

Types

type ChatRequest

type ChatRequest struct {
	Model          string          `json:"model"`
	Messages       []Message       `json:"messages"`
	Plugins        []Plugin        `json:"plugins,omitempty"`
	ResponseFormat *ResponseFormat `json:"response_format,omitempty"`
	Provider       Provider        `json:"provider,omitempty"`
	Temperature    *int            `json:"temperature,omitempty"`
	Reasoning      *Reasoning      `json:"reasoning,omitempty"`
}

ChatRequest represents the request payload

type ChatResponse

type ChatResponse struct {
	ID      string   `json:"id"`
	Choices []Choice `json:"choices"`
}

ChatResponse represents the API response

type Choice

type Choice struct {
	Message Message `json:"message"`
}

Choice represents a response choice

type Client

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

Client represents an OpenRouter API client

func NewClient

func NewClient(apiKey string, options ...Opt) *Client

NewClient creates a new OpenRouter client

func (*Client) BibIdFormat added in v0.3.0

func (c *Client) BibIdFormat(b *documents.Bibliography) (string, error)

func (*Client) ChatCompletion

func (c *Client) ChatCompletion(req ChatRequest, baseURL string) (*ChatResponse, error)

ChatCompletion sends a chat completion request

func (*Client) Classify

func (c *Client) Classify(text string) (string, error)

func (*Client) EntryFromBibliography added in v0.3.0

func (c *Client) EntryFromBibliography(b *documents.Bibliography, i int) (string, error)

func (*Client) EntryFromRaw

func (c *Client) EntryFromRaw(b64 string, i int) (string, error)

func (*Client) ExtractBib added in v0.3.0

func (c *Client) ExtractBib(b *documents.Bibliography) ([]Entry, error)

func (*Client) ExtractDocumentMetadata

func (c *Client) ExtractDocumentMetadata(encoded string) (*documents.Metadata, error)

func (*Client) HTMLMetadata

func (c *Client) HTMLMetadata(html []byte) (*documents.Metadata, error)

func (*Client) NumBibliographyEntries added in v0.3.0

func (c *Client) NumBibliographyEntries(b *documents.Bibliography) (int, error)

func (*Client) NumEntries

func (c *Client) NumEntries(b64 string) (int, error)

func (*Client) PDFMetadata

func (c *Client) PDFMetadata(raw []byte) (*documents.Metadata, error)

func (*Client) ParseAuthors added in v0.2.0

func (c *Client) ParseAuthors(text string) (*entries.Authors, error)

func (*Client) ParseOnline added in v0.2.0

func (c *Client) ParseOnline(text string) (*entries.Online, error)

func (*Client) ParsePub added in v0.2.0

func (c *Client) ParsePub(text string) (string, error)

ParsePub returns the title of a journal or a book from a bibliography entry

func (*Client) ParseSoftware

func (c *Client) ParseSoftware(text string) (*entries.Software, error)

func (*Client) ParseTitle added in v0.2.0

func (c *Client) ParseTitle(text string) (string, error)

func (*Client) ParseURL

func (c *Client) ParseURL(text string) (string, error)

func (*Client) PrepareBibliography added in v0.3.0

func (c *Client) PrepareBibliography(filePath string) (*documents.Bibliography, error)

func (*Client) PrepareBibliographyContent added in v0.3.0

func (c *Client) PrepareBibliographyContent(pdf []byte) (*documents.Bibliography, error)

func (*Client) SearchEntry

func (c *Client) SearchEntry(text string) (bool, string, error)

func (*Client) SearchOnline added in v0.2.0

func (c *Client) SearchOnline(website *entries.Online) (bool, string, error)

func (*Client) SearchSoftware

func (c *Client) SearchSoftware(software *entries.Software) (bool, string, error)

func (*Client) Summarize added in v0.3.0

func (c *Client) Summarize(lr *lookup.Result) (bool, string, error)

Summarize returns (mismatch, comment, error).

type Entry added in v0.3.0

type Entry struct {
	EntryId   string `json:"entry_id"`
	EntryText string `json:"entry_text"`
}

type File

type File struct {
	Filename string `json:"filename"`
	FileData string `json:"file_data"`
}

type FileContent

type FileContent struct {
	Type string `json:"type"`
	File File   `json:"file"`
}

func MakeFileContent

func MakeFileContent(b64 string) FileContent

type Message

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

Message represents a chat message

type Opt added in v0.2.2

type Opt func(*Client)

func WithBaseURL added in v0.2.2

func WithBaseURL(baseURL string) Opt

type PDFEngine added in v0.3.0

type PDFEngine string
const (
	PDFEngineCloudflareAI PDFEngine = "cloudflare-ai"
	PDFEngineMistralOCR   PDFEngine = "mistral-ocr"
	PDFEngineNative       PDFEngine = "native"
)

type PDFPlugin added in v0.3.0

type PDFPlugin struct {
	Engine PDFEngine `json:"engine,omitempty"`
}

type Plugin added in v0.3.0

type Plugin struct {
	ID  string     `json:"id"`
	PDF *PDFPlugin `json:"pdf,omitempty"`
}

func FileParserPlugin added in v0.3.0

func FileParserPlugin(engine PDFEngine) Plugin

func PDFParserPlugins added in v0.3.0

func PDFParserPlugins(engine PDFEngine) []Plugin

type Provider

type Provider struct {
	RequireParameters bool     `json:"require_parameters"`
	Sort              string   `json:"sort,omitempty"`
	Only              []string `json:"only,omitempty"`
}

Provider represents provider configuration

type Reasoning added in v0.3.0

type Reasoning struct {
	Effort    string `json:"effort,omitempty"`
	MaxTokens *int   `json:"max_tokens,omitempty"`
	Exclude   *bool  `json:"exclude,omitempty"`
	Enabled   *bool  `json:"enabled,omitempty"`
}

type ResponseFormat

type ResponseFormat struct {
	Type       string                 `json:"type"`
	JSONSchema map[string]interface{} `json:"json_schema"`
}

ResponseFormat represents the expected response format

func NewBibEntryTextResponseFormat

func NewBibEntryTextResponseFormat() *ResponseFormat

func NewBibIDFormatResponseFormat added in v0.3.0

func NewBibIDFormatResponseFormat() *ResponseFormat

func NewBibliographyPageResponseFormat added in v0.3.0

func NewBibliographyPageResponseFormat() *ResponseFormat

func NewClassifyEntryResponseFormat

func NewClassifyEntryResponseFormat() *ResponseFormat

func NewExtractBibResponseFormat added in v0.3.0

func NewExtractBibResponseFormat() *ResponseFormat

func NewExtractDocumentMetadataRF

func NewExtractDocumentMetadataRF() *ResponseFormat

func NewNumEntriesResponseFormat

func NewNumEntriesResponseFormat() *ResponseFormat

func NewParseAuthorsRF added in v0.3.0

func NewParseAuthorsRF() *ResponseFormat

func NewParseOnlineRF added in v0.2.0

func NewParseOnlineRF() *ResponseFormat

func NewParsePubRF added in v0.3.0

func NewParsePubRF() *ResponseFormat

func NewParseSoftwareRF

func NewParseSoftwareRF() *ResponseFormat

func NewParseTitleRF added in v0.3.0

func NewParseTitleRF() *ResponseFormat

func NewParseURLRF

func NewParseURLRF() *ResponseFormat

type TextContent

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

func MakeTextContent

func MakeTextContent(text string) TextContent

Jump to

Keyboard shortcuts

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