modelstest

package
v0.3.0 Latest Latest
Warning

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

Go to latest
Published: Dec 3, 2026 License: Apache-2.0 Imports: 14 Imported by: 0 modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Overview

Package modelstest fakes the HTTP APIs of the cloud model providers the embedded gateway calls: Azure OpenAI's v1 API, Amazon Bedrock's Converse and InvokeModel, and Vertex AI's generateContent with a Google OAuth token endpoint. Each fake records the requests it gets, answers a request that offers tools with a call of the first tool and any other with "OK", and can be told to fail. They cover what kōjō sends and reads, not the APIs.

Index

Constants

View Source
const VertexToken = "ya29.fake-vertex-access-token"

VertexToken is the access token the Vertex fake's token endpoint issues.

Variables

This section is empty.

Functions

func AWSCredentials

func AWSCredentials(t *testing.T, keyID, secret string)

AWSCredentials gives the AWS SDK's default chain static credentials from the environment and nothing else to find: no shared config files, no instance metadata, no Bedrock API key, no endpoint override.

func GoogleCredentials

func GoogleCredentials(t *testing.T, s *Server)

GoogleCredentials points Application Default Credentials at a key file whose tokens come from the Vertex fake, and clears the variables that would change where requests go.

func VertexCredentials

func VertexCredentials(t *testing.T, s *Server) string

VertexCredentials writes a service account key file whose token endpoint is the fake's, and returns its path: point GOOGLE_APPLICATION_CREDENTIALS at it and Application Default Credentials get their token from the fake.

func VertexPath

func VertexPath(project, location, model, method string) string

VertexPath is the path of a Vertex AI model method under the pinned API version.

Types

type Request

type Request struct {
	Method string
	// Path is the decoded path; RawPath is as sent.
	Path    string
	RawPath string
	Header  http.Header
	Body    map[string]any
}

Request is one request a fake received.

type Server

type Server struct {
	URL string
	// contains filtered or unexported fields
}

Server is a fake provider API.

func Azure

func Azure(t *testing.T) *Server

Azure fakes the v1 API of an Azure OpenAI or Foundry resource: POST /openai/v1/chat/completions and /openai/v1/embeddings.

func Bedrock

func Bedrock(t *testing.T) *Server

Bedrock fakes Bedrock Runtime: POST /model/{id}/converse, and /model/{id}/invoke for Amazon Titan text embeddings.

func BedrockTLS

func BedrockTLS(t *testing.T) (*Server, string)

BedrockTLS is Bedrock over https, which a Bedrock API key needs. It returns the file of the certificate to trust (AWS_CA_BUNDLE).

func Vertex

func Vertex(t *testing.T) *Server

Vertex fakes Vertex AI under /v1beta1/projects/{p}/locations/{l}/publishers/google/models/{m} (generateContent, and predict and embedContent for embeddings) and an OAuth token endpoint at /token, for the key file of VertexCredentials.

func (*Server) Fail

func (s *Server) Fail(status int, body string)

Fail makes every model and embedding request answer with this status and body; 0 turns it off. Token requests still succeed.

func (*Server) Last

func (s *Server) Last(part string) (Request, bool)

Last returns the last request whose path contains part.

func (*Server) Requests

func (s *Server) Requests() []Request

Requests returns what the fake received so far.

Jump to

Keyboard shortcuts

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