V2EX = way to explore
V2EX 是一个关于分享和探索的地方
Sign Up Now
For Existing Member  Sign In
nonfu
V2EX  ›  OpenAI

ChatGPT 翻车记

  •  
  •   nonfu · Mar 3, 2023 · 2449 views
    This topic created in 1151 days ago, the information mentioned may be changed or developed.

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

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

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

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