chat

package module
v0.0.34 Latest Latest
Warning

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

Go to latest
Published: Apr 9, 2024 License: MIT Imports: 17 Imported by: 0

README

simple generic LLM chat harness

has built-in support for openai's and anthropic's LLM's. anthropic access is via aws/bedrockruntime.

have a look at example/main.go for an example of how to use this library.

running it looks like this, ">" as a line prefix indicates where it waits for you to enter something to continue the conversation:

chat% go run example/main.go

The included resource in this document is a Zen story titled "Finding a Diamond on a Muddy Road" sourced from https://ashidakim.com/zenkoans/2findingadiamond.html. The story is about Gudo, the emperor's teacher, who helps a problematic man in a village to understand the impermanence of life and the problems his gambling and drinking habits are causing his family.

Notable quotes from the resource:

  1. "Gudo was the emperor's teacher of his time. Nevertheless, he used to travel alone as a wandering mendicant."

  2. "Observing that the entire family was depressed, Gudo asked what was wrong."

  3. "I will help him," said Gudo. "Here is some money. Get me a gallon of fine wine and something good to eat. Then you may retire. I will meditate before the shrine."

  4. "Everything in this life is impermanent," he explained. "Life is very brief. If you keep on gambling and drinking, you will have no time left to accomplish anything else, and you will cause your family to suffer too."

  5. "Modern Zen teachings in Japan spring from the lineage of a famous master who was the successor of Gudo. His name was Mu-nan, the man who never turned back."

> what's the moral of the story, or the conclusion?

The moral of the story is about the impermanence of life and the importance of using one's time wisely. It underlines the fact that harmful habits not only affect the person indulging in them but also their loved ones. The story also highlights the transformative power of wisdom and guidance.

The conclusion of the story is that the man, deeply moved and awakened by Gudo's teachings, decides to follow him for the rest of his life, symbolizing his commitment to change. The text also reveals that the man, known as Mu-nan, becomes a significant figure in Zen teachings, showing that profound change and redemption are possible.

> what about leaving his wife behind?

The story doesn't explicitly address what happens to the man's wife after he decides to follow Gudo. However, it's possible to interpret this in different ways. One interpretation could be that by choosing to follow Gudo and leave his old life behind, the man is indirectly helping his family. By ending his harmful habits of gambling and drinking, he's no longer causing them pain and suffering.

However, another interpretation could focus on the man's decision to abandon his family to follow Gudo as a form of escapism, avoiding his responsibilities rather than facing them. The story doesn't provide enough details to determine which interpretation is correct.

> ...

Documentation

Index

Constants

View Source
const DefaultAnthropicModel = "anthropic.claude-v2:1"

Variables

This section is empty.

Functions

This section is empty.

Types

type APIConfig

type APIConfig struct {
	LLMInterface
	Prompt   string // prompt to use for the first request (optional)
	Print    bool   // whether to print the initial messages to stdout
	OneRound bool   // whether to just run for one round, no conversation
	JSONMode bool   // whether to have model respond in json
}

type File

type File interface {
	Metadata() string
	io.ReadCloser
}

type FinishReason added in v0.0.15

type FinishReason int
const (
	FinishReasonStop FinishReason
	FinishReasonLength
	FinishReasonUnknown
)

func (FinishReason) String added in v0.0.15

func (i FinishReason) String() string

type GPT4Mode added in v0.0.26

type GPT4Mode int
const (
	GPT4ModeTurbo GPT4Mode
)

func (GPT4Mode) String added in v0.0.26

func (i GPT4Mode) String() string

type LLMInterface added in v0.0.22

type LLMInterface interface {
	// the context window capacity of the LLM
	MaxTokens() int
	// estimates how many tokens are used by the messages
	TokenEstimate(messages []Message) (int, error)
	// streams the response of the LLM to the messages
	Streaming(messages []Message, stream io.Writer) (*Response, error)
}

func Claude2 added in v0.0.15

func Claude2(c *bedrockruntime.Client) (LLMInterface, error)

assumes that 1000 tokens are approximately 750 words.

func GPT4 added in v0.0.15

func GPT4(m GPT4Mode, c *openai.Client) (LLMInterface, error)

func NewMultiLLMInterface added in v0.0.23

func NewMultiLLMInterface(firstSmaller, secondLarger LLMInterface) (LLMInterface, error)

uses the first smaller capacity one, until tokens exceed its limit, then uses the second one; thus, can seemlessly switch between a lower capacity and a higher capacity model as chat grows over time.

type Message added in v0.0.15

type Message struct {
	Role    Role
	Content string
}

func Streaming

func Streaming(config APIConfig, promptFiles ...File) ([]Message, error)

manages a streaming chat via stdin/stdout. after the chat, returns messages thus far and error, if any.

type Response added in v0.0.15

type Response struct {
	Content      string
	FinishReason FinishReason
}

type Role added in v0.0.15

type Role int
const (
	RoleSystem Role
	RoleUser
	RoleAssistant
)

func (Role) String added in v0.0.15

func (i Role) String() string

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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