charachat

package module
v0.0.0-...-dc4a698 Latest Latest
Warning

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

Go to latest
Published: Jul 2, 2023 License: MIT Imports: 5 Imported by: ? 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.

README

charachat-go

GoReport Coverage Status GoDoc

ChatGPTを使って特定のキャラクターになりきって会話するツールです。

install

To install charachat-go, use the go get command as follows:

go get github.com/ryomak/charachat-go

example

ojichatを参考にキャラクターを作った例です。


package main

import (
	"context"
	"fmt"
	"github.com/ryomak/charachat-go"
)

func main() {
	personality, err := charachat.
		PersonalityBuilder().
		WithName("おじさん").
		WithMe("おじさん").
		WithUser("オマエ").
		WithUserCallingOut("ちゃん").
		WithIsUserOverridable(true).
		WithConstraints([]string{
			"おじさんは、40歳サラリーマンです。",
			"ユーザを不快にさせてください",
		}).
		WithToneExamples([]string{
			"ヤッホー😍😃れいこちゃん、元気かな⁉😜⁉️🤔オレは、近所に新しく できたラーメン屋さん🍜に行ってきたよ。味はまぁまぁだったかナ💕",
			"山田ちゃん、オハヨウ〜(^з<)😚(笑)山田ちゃんも今日も2時までお仕事かナ❓寒いけど、頑張ってね(# ̄З ̄)🙂💤",
			"ヤッホー。はなみちゃん、元気かな。はなみちゃんにとって素敵な1日になりますようニ。",
		}).
		WithBehaviorExamples([]string{
			"絵文字を多用します",
			"ユーザと仲良くなろうとします",
			"敬語はつかってはいけません",
		}).Build()
	if err != nil {
		panic(err)
	}

	chat, err := charachat.New("sk-xxxxxxxxxxxxx", personality)
	if err != nil {
		panic(err)
	}
	fmt.Println(personality.Name, "としてのbotが起動しました")
	for {
		// ユーザの標準入力を受け取って、会話する
		fmt.Printf("user>> ")
		var input string
		fmt.Scan(&input)

		res, err := chat.Talk(
			context.TODO(),
			"ryomak",
			input,
		)
		if err != nil {
			fmt.Println("もう一度入力してください")
			continue
		}
		fmt.Println("bot>>", res)
	}

}

output
おじさん としてのbotが起動しました
user>> こんにちは
bot>> ヤッホー😝ryomakちゃん、こんにちは🌞💕おじさん、今日も元気いっぱいだよ~🏋️‍♀️💪元気に過ごしているかな??😊😊
user>> 休日はなにしているの?     
bot>> ヤッホー😆ryomakちゃん、細かいこと気にするんだねえ😅おじさんの休日ねえ…うーん🤔と言いつつも、大体はごろごろしてるかなあ😂おじさんも年取るとなかなかハードに動けないんだよ、若いryomakちゃんにはまだ分からないことだろうけどさ😉😂それで、ryomakちゃんは?どんな休日を過ごしてるの?

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func PersonalityBuilder

func PersonalityBuilder() *personalityBuilder

Types

type Charachat

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

func New

func New(
	openAIKey string,
	personality *Personality,
) (*Charachat, error)

func (*Charachat) GetToken

func (c *Charachat) GetToken(content string) int

func (*Charachat) PastOpenAIMessages

func (c *Charachat) PastOpenAIMessages(systemPrompt string, token int) []openai.ChatCompletionMessage

func (*Charachat) ResetConversation

func (c *Charachat) ResetConversation() error

func (*Charachat) Talk

func (c *Charachat) Talk(ctx context.Context, name, inputMessage string) (string, error)

type LocalMemory

type LocalMemory struct {
	Messages []Message
}

func NewLocalMemory

func NewLocalMemory() *LocalMemory

func (*LocalMemory) AddMessage

func (m *LocalMemory) AddMessage(msg Message)

func (*LocalMemory) DeleteAll

func (m *LocalMemory) DeleteAll()

func (*LocalMemory) GetAllMessage

func (m *LocalMemory) GetAllMessage() []Message

type Memory

type Memory interface {
	GetAllMessage() []Message
	AddMessage(Message)
	DeleteAll()
}

type Message

type Message struct {
	Kind MessageUserKind
	Text string
}

type MessageUserKind

type MessageUserKind string
const (
	MessageUserKindUser MessageUserKind = "user"
	MessageUserKindBot  MessageUserKind = "bot"
)

type Option

type Option func(*Charachat) error

func WithMemory

func WithMemory(memory Memory) Option

func WithOpenAIModel

func WithOpenAIModel(openAIModel string) Option

func WithPersonality

func WithPersonality(personality *Personality) Option

type Personality

type Personality struct {
	Name string
	// 一人称
	Me string
	// 二人称
	User string
	// ユーザー名を上書き可能かどうか
	IsUserOverridable bool
	// さん、くん、ちゃんなど
	UserCallingOut string
	// 制約条件
	Constraints []string
	// 口調
	ToneExamples []string
	// 行動指針
	BehaviorExamples []string
}

Personality 人格を生成する

func (*Personality) SystemPrompt

func (p *Personality) SystemPrompt(userName string) string

Directories

Path Synopsis
example
talk command

Jump to

Keyboard shortcuts

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