Ecosyste.ms: Awesome

An open API service indexing awesome lists of open source software.

Awesome Lists | Featured Topics | Projects

https://github.com/hktalent/ChatGPT-API

OpenAI ChatGPT, GPT-3, ChatGPT-API for go,ChatGPT in bash shell command line
https://github.com/hktalent/ChatGPT-API

bash chatgpt go golang

Last synced: 29 days ago
JSON representation

OpenAI ChatGPT, GPT-3, ChatGPT-API for go,ChatGPT in bash shell command line

Awesome Lists containing this project

README

        

# ChatGPT-API

# How use

```
curl -XPOST -v -H "user-agent: Mozilla/5.0 (Windows NT 6.1; rv:45.0) Gecko/20100101 Firefox/45.0" 'https://51pwn.com/chatGPT?q=介绍支持matrix协议、开源客户端聊天软件'
```

#### download from release
https://github.com/hktalent/ChatGPT-API/releases

```
wget -c https://github.com/hktalent/ChatGPT-API/releases/download/0.0.3/ChatGPT_0.0.3_macOS_amd64.zip
unzip -x ChatGPT_0.0.3_macOS_amd64.zip
./ChatGPT -i -k [your key]

```
Screenshot 2022-12-18 at 18 10 56

# Example
```go
package main

import (
"bufio"
"flag"
"fmt"
gtp "github.com/hktalent/ChatGPT-API"
"os"
"strings"
)

func doOne(q, k string) {
if got, err := gtp.Completions(q, k); nil == err {
fmt.Println(got)
} else if nil != err {
fmt.Println("gtp.Completions is err:", err)
}
}

func main() {
key := flag.String("k", "", "your ChatGPT-API token key")
interact := flag.Bool("i", false, "interact")
q := flag.String("q", "", "your question")
flag.Parse()
if *key != "" {
if *interact {
buf := bufio.NewScanner(os.Stdin)
for buf.Scan() {
s := buf.Text()
x1 := strings.TrimSpace(strings.ToLower(s))
if x1 == "exit" || x1 == "quit" || x1 == "q" || x1 == "x" {
break
}
if "" != s {
doOne(s, *key)
}
if nil != buf.Err() {
break
}
}
} else if "" != *q {
doOne(*q, *key)
}
}
}

```