atri

package module
v1.2.0 Latest Latest
Warning

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

Go to latest
Published: Feb 23, 2026 License: MIT Imports: 16 Imported by: 0

README

Atri Core

Atri Core 是一个用于实现聊天机器人的 Go 库.

最小示例

package main

import (
	"context"

	"github.com/chhongzh/atri-core"
	"github.com/glebarez/sqlite"
	"github.com/openai/openai-go/v3"
	"github.com/openai/openai-go/v3/option"
	"go.uber.org/zap"
	"gorm.io/gorm"
)

func main() {
	botToken := "YOUR_TELEGRAM_BOT_TOKEN"
	apiBaseURL := "https://your-openai-compatible-endpoint"
	apiKey := "YOUR_OPENAI_API_KEY"
	apiModel := "gpt-4.1"

	ctx := context.Background()
	logger := zap.Must(zap.NewDevelopment())

	openaiClient := openai.NewClient(
		option.WithBaseURL(apiBaseURL),
		option.WithAPIKey(apiKey),
	)

	db, err := gorm.Open(sqlite.Open("atri-core.db"))
	if err != nil {
		logger.Fatal("初始化DB失败", zap.Error(err))
	}

	cfg := atri.Config{
		Model:        apiModel,
		MaxRounds:    16,                 // 0 表示不限制
		SystemPrompt: "你是一个聊天机器人",  // 支持的占位符 {{USERNAME}} / {{MEMORIES}}
	}

	core := atri.New(ctx, logger, &openaiClient, db, botToken, cfg)
	ch, err := core.Start()
	if err != nil {
		logger.Fatal("启动Atri失败", zap.Error(err))
	}

	<-ch
}

启动后,在聊天中输入 /help 可以查看所有可用命令和功能说明。

Documentation

Overview

Package atri 是Atri的实现

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Atri

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

Atri 是Atri的实例

func New

func New(ctx context.Context, logger *zap.Logger, openaiClient *openai.Client, db *gorm.DB, botToken string, cfg Config) *Atri

New 创建一个新的Atri实例

func (*Atri) Start

func (a *Atri) Start() (<-chan struct{}, error)

Start 启动Telegram Bot并返回一个在停止时关闭的通道

type Config

type Config struct {
	Model            string
	MaxRounds        int
	SystemPrompt     string
	CheckInitTimeout time.Duration
}

Config 用于配置Atri实例的模型、最大保留轮数和系统提示词

Jump to

Keyboard shortcuts

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