Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings
This repository was archived by the owner on Apr 27, 2025. It is now read-only.
/ gpt Public archive

将github.com/sashabaranov/go-openai封装为Goner提供给Gone框架使用

Notifications You must be signed in to change notification settings

gone-io/gpt

Folders and files

NameName
Last commit message
Last commit date

Latest commit

History

2 Commits

Repository files navigation

gpt

将github.com/sashabaranov/go-openai封装为Goner提供给Gone框架使用

使用和编写示例

  1. 在配置文件中,写入配置项,参考通过内置Goners支持配置文件
  2. 在需要使用的结构体中注入ChatGPT并调用相关接口,代码示例如下:
package example
import (
	"context"
	"github.com/gone-io/gone"
	"github.com/gone-io/gpt"
	"github.com/sashabaranov/go-openai"
)
type Chat struct {
	gone.Flag
	gPT gpt.ChatGPT `gone:"gone-gpt"`
}
func (c *Chat) Use(ask string) error {
	response, err := c.gPT.CreateChatCompletion(context.TODO(), openai.ChatCompletionRequest{
		Model: openai.GPT3Dot5Turbo,
		Messages: []openai.ChatCompletionMessage{
			{
				Role: openai.ChatMessageRoleSystem,
				Content: "you are a helpful chatbot",
			},
			{
				Role: openai.ChatMessageRoleUser,
				Content: ask,
			},
		},
	})
	if err != nil {
		return err
	}
	println(response.Choices[0].Message.Content)
	return nil
}

About

将github.com/sashabaranov/go-openai封装为Goner提供给Gone框架使用

Resources

Stars

Watchers

Forks

Packages

No packages published

Languages

AltStyle によって変換されたページ (->オリジナル) /