GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — GitHub - itstack-org/openai-proxy: 基于 Go 实现 OpenAI API 代理(适用于腾讯云云函数)

BranchesTags
Open more actions menu
 
 

Latest commit

 

History

11 Commits
11 Commits

Folders and files

NameName
Last commit message
Last commit date
.gitignore
.gitignore
 
 
README.md
README.md
 
 
build.sh
build.sh
 
 
go.mod
go.mod
 
 
go.sum
go.sum
 
 
main.go
main.go
 
 
scf_bootstrap
scf_bootstrap
 
 

Repository files navigation

GO-OPENAI-PROXY

基于 Go + 腾讯云 API 网关 + 云函数(部署到海外节点)实现 OpenAI API 调用代理

编译打包:

./build.sh

部署测试

然后在腾讯云云函数代码管理界面上传打包好 zip 包即可完成部署:

你可以通过腾讯云云函数提供的测试工具进行测试,也可以本地通过 curl/postman 进行测试,使用的时候只需要将 api.openai.com 替换成代理域名 open.aiproxy.xyz 即可:

你可以选择自己搭建,也可以直接使用我提供的代理域名 open.aiproxy.xyz,反正是免费的。关于代理背后的原理,可以看我在极客书房发布的这篇教程:国内无法调用 OpenAI 接口的解决办法。

本地调试走VPN的话可以设置环境变量 ENV=local,然后直连 api.openai.com:

// 本地测试通过代理请求 OpenAI 接口
if os.Getenv("ENV") == "local" {
    proxyURL, _ := url.Parse("http://127.0.0.1:10809")
    client.Transport = &http.Transport{
        Proxy:           http.ProxyURL(proxyURL),
        TLSClientConfig: &tls.Config{InsecureSkipVerify: true},
    }
}

流式响应支持

这个源代码本身是支持 stream 流式响应代理的,但目前腾讯云函数并支持分块流式传输,如果你需要实现流式响应,可以把编译后的二进制文件 main 丢到任意海外云服务器运行,这样就变成支持流式响应的 OpenAI 代理了,如果你不想折腾,可以使用我这边提供的 open2.aiproxy.xyz 作为代理进行测试:

image

About

基于 Go 实现 OpenAI API 代理(适用于腾讯云云函数)

Resources

Readme
Activity
Custom properties

Stars

1 star

Watchers

0 watching

Forks

0 forks
Report repository

Releases

Packages

Contributors

Languages

You are visitor 01402775 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.