chatgo

package
v0.3.0 Latest Latest
Warning

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

Go to latest
Published: Mar 11, 2023 License: Apache-2.0 Imports: 8 Imported by: 0

Documentation

Overview

Package chatgo is a chatbot based on openai api

Index

Constants

View Source
const (
	// RoleAssistant is the assistant role
	RoleAssistant = "assistant"
	// RoleUser is the user role
	RoleUser = "user"
	// RoleSystem is the system role
	RoleSystem = "system"
)
View Source
const HistoryPath = "~/.chatgo/%s.%s.history"

HistoryPath is the path of history

View Source
const TokenPath = "~/.chatgo/token"

TokenPath is the path of token

View Source
const Version = "v0.2.0-alpha"

Version is the version of chatgo

Variables

This section is empty.

Functions

This section is empty.

Types

type ChatRequest

type ChatRequest struct {
	Token   string `json:"token"`
	Model   string `json:"model"`
	Role    string `json:"role"`
	Content string `json:"content"`
}

ChatRequest is the request body for chatgpt

type ChatResponse

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

ChatResponse is the response body for chatgpt

type ChatStreamResponse

type ChatStreamResponse struct {
	ID      string `json:"id"`
	Object  string `json:"object"`
	Created int    `json:"created"`
	Model   string `json:"model"`
	Choices []struct {
		Delta struct {
			Role    string `json:"role"`
			Content string `json:"content"`
		} `json:"delta"`
		Index        int `json:"index"`
		FinishReason any `json:"finish_reason"`
	} `json:"choices"`
}

ChatStreamResponse is the response body for chatgpt stream

type Robot

type Robot struct {
	CreateAt time.Time `json:"create_at"`
	// contains filtered or unexported fields
}

Robot is a chatgpt robot

func NewRobot

func NewRobot() *Robot

NewRobot creates a new robot

func (*Robot) GetModel

func (r *Robot) GetModel() string

GetModel gets the robot openai model

func (*Robot) Init

func (r *Robot) Init()

Init initializes the robot

func (*Robot) Name

func (r *Robot) Name() string

Name gets the robot name

func (*Robot) Replay

func (r *Robot) Replay()

Replay 回放之前的聊天记录

func (*Robot) Save

func (r *Robot) Save(path string) error

Save saves the messages to file

func (*Robot) SetMessagesFromFile

func (r *Robot) SetMessagesFromFile(path string) *Robot

SetMessagesFromFile sets the robot messages

func (*Robot) SetModel

func (r *Robot) SetModel(model string) *Robot

SetModel sets the robot openai model

func (*Robot) SetName

func (r *Robot) SetName(name string) *Robot

SetName sets the robot name

func (*Robot) SetToken

func (r *Robot) SetToken(token string) *Robot

SetToken sets the robot openai token

func (*Robot) Tell

func (r *Robot) Tell(sentence string) []string

Tell tells the robot something

func (*Robot) TellStream

func (r *Robot) TellStream(sentence string) (<-chan string, error)

TellStream tells the robot something and returns a stream

Jump to

Keyboard shortcuts

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