V2EX = way to explore
V2EX 是一个关于分享和探索的地方
现在注册
已注册用户请  登录
nonfu
V2EX  ›  OpenAI

ChatGPT 翻车记

  •  
  •   nonfu · 2023-03-03 19:46:10 +08:00 · 1841 次点击
    这是一个创建于 421 天前的主题,其中的信息可能已经有所发展或是发生改变。

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

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

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

    11 条回复    2023-03-05 21:19:59 +08:00
    dreasky
        1
    dreasky  
       2023-03-03 21:00:42 +08:00
    人家都说了是 2021 年前的数据 怎么会知道现在的新接口怎么调用
    SMGdcAt4kPPQ
        2
    SMGdcAt4kPPQ  
       2023-03-03 21:09:44 +08:00 via Android
    试过 Bing 当天就可以正常生成 Python 代码
    SMGdcAt4kPPQ
        3
    SMGdcAt4kPPQ  
       2023-03-03 21:12:20 +08:00 via Android   ❤️ 1
    恢复旧版 Sydney 的办法也有了
    https://www.make-safe-ai.com/is-bing-chat-safe/
    westoy
        4
    westoy  
       2023-03-03 21:15:15 +08:00
    试下来, 这东西各领域的翻车率都很高
    mingl0280
        5
    mingl0280  
       2023-03-04 06:11:44 +08:00 via Android
    你这是不知道新版 API ,我今天试图用这玩意儿搞个解析 cmake 的脚本,这玩意儿搞事,整了一套根本不存在的 python pip 库和 import 以及对应的 API 出来……
    nonfu
        6
    nonfu  
    OP
       2023-03-05 00:10:48 +08:00
    @mingl0280 写代码目前确实翻车率比较高 好在是一些细节问题 整体结构上还是 ok 的
    nonfu
        7
    nonfu  
    OP
       2023-03-05 00:12:56 +08:00
    @dreasky 话是这么说 但是今天貌似就可以了 一个读者按照我的教程自己写反馈给我的
    nonfu
        8
    nonfu  
    OP
       2023-03-05 00:13:44 +08:00
    @ComputerIdiot 可能官方就是 python 示例 已经训练过 我这个是 go 版本的
    SMGdcAt4kPPQ
        9
    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
        10
    nonfu  
    OP
       2023-03-05 20:54:16 +08:00
    @ComputerIdiot 那个 url 是不是错了
    SMGdcAt4kPPQ
        11
    SMGdcAt4kPPQ  
       2023-03-05 21:19:59 +08:00
    是的,拉了呀,要它不借助第三方库生成代码不行
    关于   ·   帮助文档   ·   博客   ·   API   ·   FAQ   ·   我们的愿景   ·   实用小工具   ·   1472 人在线   最高记录 6543   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 26ms · UTC 16:59 · PVG 00:59 · LAX 09:59 · JFK 12:59
    Developed with CodeLauncher
    ♥ Do have faith in what you're doing.