百科.dev
全部条目在线工具AI 编程趋势榜开源项目技术资讯提交条目
登录
< 返回工具列表
G

gpt-go

> AI 编程
开源

ZZTERM1型电力机车 / ZZTERM2型电力机车 / GPT-3 SDK 与 GPT-4/GPT-3 API 客户端进行交互.

356 stars0 点赞1 次浏览
访问官网GitHub

工具介绍

ZZTERM1型电力机车 / ZZTERM2型电力机车 / GPT-3 SDK 与 GPT-4/GPT-3 API 客户端进行交互.

GPT-Go: OpenAI ChatGPT/GPT-4/GPT-3 SDK Go Client to Interact with the GPT-4/GPT-3 APIs.

English | 中文

OpenAI Docs API Reference: https://platform.openai.com/docs/api-reference/introduction

Note: Already support GPT-4 API, please use Chat Completions API.

Quick Start

bash
# clone the project
git clone https://github.com/hanyuancheung/gpt-go.git

# go to the project directory
cd gpt-go

# set API_KEY as environment variable
export API_KEY={YOUR_API_KEY} chatgpt

# go build example binary
make chatgpt-example

# run example
./chatgpt

Snapshot

How To Get API_KEY

https://platform.openai.com/account/api-keys

Documentation

Check out the go docs for more detailed documentation on the types and methods provided: https://pkg.go.dev/github.com/hanyuancheung/gpt-go

Support

  • List Engines API
  • Get Engine API
  • Completion API (this is the main gpt-3 API)
  • Streaming support for the Completion API
  • Document Search API
  • Image generation API
  • Overriding default url, user-agent, timeout, and other options

Usage Examples

ChatGPT streaming completion

go
func main() {
	client := gpt.NewClient("API_KEY")
	err := client.ChatCompletionStream(context.Background(), &gpt.ChatCompletionRequest{
		Model: gpt.GPT3Dot5Turbo,
		Messages: []gpt.ChatCompletionRequestMessage{
			{
				Role:    "user",
				Content: "Hello!",
			},
		},
	}, func(response *gpt.ChatCompletionStreamResponse) {
		fmt.Print(response.Choices[0].Delta.Content)
	})
	if err != nil {
		fmt.Printf("ChatCompletionStream error: %v\n", err)
		return
	}
}

GPT-3 completion

go
func main() {
	client := gpt.NewClient("API_KEY")
	rsp, err := client.CompletionWithEngine(context.Background(), &gpt.CompletionRequest{
		Model:  gpt.TextDavinci003Engine,
		Prompt: []string{"Hello!"},
	})
	if err != nil {
		fmt.Printf("ChatCompletionStream error: %v\n", err)
		return
	}
	fmt.Print(rsp.Choices[0].Text)
}

DALL-E 2 image generation

go
func main() {
	client := gpt.NewClient("API_KEY")
	rsp, err := client.Image(context.Background(), &gpt.ImageRequest{
		Prompt: "Chicken",
	})
	if err != nil {
		fmt.Printf("ChatCompletionStream error: %v\n", err)
		return
	}
	fmt.Print(rsp.Data[0].URL)
}

Contributor

Contribute

Please open up an issue on GitHub before you put a lot of efforts on pull request. The code submitting to PR must be filtered with gofmt.

Star History

License

This package is licensed under MIT license. See LICENSE for details.

Show your support

Give a ⭐️ if this project helped you!

Issues· 0 开放

查看全部 Issues在 GitHub 打开

暂无开放 Issues,或尚未同步最近议题。

> 标签

Gochatgptchatgpt-apigolanggpt-3

暂无评论,来聊聊你的看法吧

> 工具信息

发布日期2026年8月1日
最后更新2026年9月17日
分类AI 编程
定价开源

> 相关工具

G
GitHub Copilot
GitHub 官方 AI 编程助手,覆盖补全、Chat 与 Agent 模式。
C
Cursor
AI 原生代码编辑器,对话改代码、多文件 Agent 与规则体系是其核心。
S
skills
Skills for Real Engineers. Straight from my .agents directory.