ChatGPT 翻车记

2023-03-03 19:46:10 +08:00
 nonfu

OpenAI 这两天发布了 ChatGPT API ,今天试水用这个最新 API 实现了一个命令行版 ChatGPT (基于 Go 语言),果不其然面向 ChatGPT 编程的时候翻车了,它压根不知道最新版的 API 接口怎么调用:

https://geekr.dev/posts/chatgpt-console-client

所以我比较好奇前端程序员是不是稳了,毕竟新框架新特性如过江之鲫,ChatGPT 都学不过来。

1846 次点击
所在节点    OpenAI
11 条回复
dreasky
2023-03-03 21:00:42 +08:00
人家都说了是 2021 年前的数据 怎么会知道现在的新接口怎么调用
SMGdcAt4kPPQ
2023-03-03 21:09:44 +08:00
试过 Bing 当天就可以正常生成 Python 代码
SMGdcAt4kPPQ
2023-03-03 21:12:20 +08:00
恢复旧版 Sydney 的办法也有了
https://www.make-safe-ai.com/is-bing-chat-safe/
westoy
2023-03-03 21:15:15 +08:00
试下来, 这东西各领域的翻车率都很高
mingl0280
2023-03-04 06:11:44 +08:00
你这是不知道新版 API ,我今天试图用这玩意儿搞个解析 cmake 的脚本,这玩意儿搞事,整了一套根本不存在的 python pip 库和 import 以及对应的 API 出来……
nonfu
2023-03-05 00:10:48 +08:00
@mingl0280 写代码目前确实翻车率比较高 好在是一些细节问题 整体结构上还是 ok 的
nonfu
2023-03-05 00:12:56 +08:00
@dreasky 话是这么说 但是今天貌似就可以了 一个读者按照我的教程自己写反馈给我的
nonfu
2023-03-05 00:13:44 +08:00
@ComputerIdiot 可能官方就是 python 示例 已经训练过 我这个是 go 版本的
SMGdcAt4kPPQ
2023-03-05 15:50:22 +08:00
@nonfu 这是 Bing 生成的 Go 调用 ChatGPT 的代码
···go
package main

import (
"bytes"
"encoding/json"
"fmt"
"io/ioutil"
"net/http"
)

type Request struct {
Messages []string `json:"messages"`
}

type Response struct {
Text string `json:"text"`
}

func main() {
url := "https://api.openai.com/v1/engines/chatgpt/completions"

reqBody := Request{
Messages: []string{
"system: Hello, this is Bing.",
"user: Hi. Can you help me with something?",
"system: Sure. What can I do for you?",
"user: How can I call ChatGPT API with Go?",
// add more messages here
},
}

reqBytes, err := json.Marshal(reqBody)
if err != nil {
panic(err)
}

req, err := http.NewRequest("POST", url, bytes.NewBuffer(reqBytes))
if err != nil {
panic(err)
}

req.Header.Set("Authorization", "sk-your token") // replace your token with your API key
req.Header.Set("Content-Type", "application/json")

client := &http.Client{}
resp, err := client.Do(req)
if err != nil {
panic(err)
}
defer resp.Body.Close()

respBody, err := ioutil.ReadAll(resp.Body)
if err != nil {
panic(err)
}

var respData Response
err = json.Unmarshal(respBody, &respData)
if err != nil {
panic(err)
}

fmt.Println(respData.Text) // print the generated text
}
···
nonfu
2023-03-05 20:54:16 +08:00
@ComputerIdiot 那个 url 是不是错了
SMGdcAt4kPPQ
2023-03-05 21:19:59 +08:00
是的,拉了呀,要它不借助第三方库生成代码不行

这是一个专为移动设备优化的页面(即为了让你能够在 Google 搜索结果里秒开这个页面),如果你希望参与 V2EX 社区的讨论,你可以继续到 V2EX 上打开本讨论主题的完整版本。

https://www.v2ex.com/t/920926

V2EX 是创意工作者们的社区,是一个分享自己正在做的有趣事物、交流想法,可以遇见新朋友甚至新机会的地方。

V2EX is a community of developers, designers and creative people.

© 2021 V2EX