bedrock

package module
v1.0.1 Latest Latest
Warning

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

Go to latest
Published: Jul 31, 2024 License: MIT Imports: 11 Imported by: 0

README

Go Bedrock

Docs

Interact with the Amazon Bedrock and Bedrockruntime API for text.

go get github.com/So-Sahari/go-bedrock@latest

Documentation

Overview

Package bedrock contains aws logic

Package bedrock contains aws logic

Index

Constants

This section is empty.

Variables

View Source
var SupportedModels = []string{"sonnet", "anthropic", "cohere", "mistral"}

SupportedModels contains all supported models implemented

Functions

func CreateBedrockClient

func CreateBedrockClient(ctx context.Context, region string) (*bedrock.Client, error)

CreateBedrockClient creates a bedrock client based on region

func CreateBedrockruntimeClient

func CreateBedrockruntimeClient(ctx context.Context, region string) (*bedrockruntime.Client, error)

CreateBedrockruntimeClient creates a bedrockruntime client based on region

Types

type AWSModelConfig

type AWSModelConfig struct {
	ModelID     string  // ModelID is the ID of the model to invoke
	Temperature float64 // Temperature is part of model settings (Anthropic, Cohere)
	TopP        float64 // TopP is part of model settings (Anthropic, Cohere)
	TopK        int     // TopK is part of model settings (Anthropic, Cohere)
	MaxTokens   int     // MaxTokens is part of model settings (Anthropic, Cohere)
}

AWSModelConfig contains all settings for AWS Models

func NewModel

func NewModel(modelID string, temp, topP float64, topK, tokens int) AWSModelConfig

NewModel is a factory for AWS Models

func (*AWSModelConfig) InvokeModel

func (m *AWSModelConfig) InvokeModel(ctx context.Context, api ClientRuntimeAPI, message string) (string, error)

InvokeModel runs prompt with settings with InvokeModelWithResponseStream

type ClientAPI

type ClientAPI interface {
	ListFoundationModels(ctx context.Context, params *bedrock.ListFoundationModelsInput, optFns ...func(*bedrock.Options)) (*bedrock.ListFoundationModelsOutput, error)
}

ClientAPI is used to interface with bedrock client

type ClientRuntimeAPI

type ClientRuntimeAPI interface {
	InvokeModelWithResponseStream(ctx context.Context, params *bedrockruntime.InvokeModelWithResponseStreamInput, optFns ...func(*bedrockruntime.Options)) (*bedrockruntime.InvokeModelWithResponseStreamOutput, error)
}

ClientRuntimeAPI interface is for support mocking of API calls

type Delta added in v1.0.1

type Delta struct {
	Type       string `json:"type,omitempty"`
	Text       string `json:"text,omitempty"`
	StopReason string `json:"stop_reason,omitempty"`
}

type FoundationModel

type FoundationModel struct {
	Name     string
	Provider string
	ID       string
	Modality string
}

FoundationModel contains model fields

func ListModels

func ListModels(ctx context.Context, api ClientAPI) ([]FoundationModel, error)

type PartialResponse added in v1.0.1

type PartialResponse struct {
	Type    string                 `json:"type"`
	Message PartialResponseMessage `json:"message,omitempty"`
	Index   int                    `json:"index,omitempty"`
	Delta   Delta                  `json:"delta,omitempty"`
	Usage   PartialResponseUsage   `json:"usage,omitempty"`
}

type PartialResponseMessage added in v1.0.1

type PartialResponseMessage struct {
	ID           string               `json:"id,omitempty"`
	Type         string               `json:"type,omitempty"`
	Role         string               `json:"role,omitempty"`
	Content      []interface{}        `json:"content,omitempty"`
	Model        string               `json:"model,omitempty"`
	StopReason   string               `json:"stop_reason,omitempty"`
	StopSequence interface{}          `json:"stop_sequence,omitempty"`
	Usage        PartialResponseUsage `json:"usage,omitempty"`
}

type PartialResponseUsage added in v1.0.1

type PartialResponseUsage struct {
	InputTokens  int `json:"input_tokens,omitempty"`
	OutputTokens int `json:"output_tokens,omitempty"`
}

type StreamingOutputHandler

type StreamingOutputHandler func(ctx context.Context, part []byte) error

StreamingOutputHandler used for processing streaming output

Directories

Path Synopsis
Package models contains structs on model requests/responses
Package models contains structs on model requests/responses

Jump to

Keyboard shortcuts

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