Giter Site home page Giter Site logo

Comments (5)

linweiyuan avatar linweiyuan commented on July 19, 2024

其实里面有注释,用了 //

其他感觉顾名思义的,就没写,因为有些所谓注释就是把英文翻译成中文,好像没必要(没别的意思)

流程就是根据 AJAX 请求的不同状态,然后再根据 HTTP 状态码来判断正常处理还是报错,应该挺清晰的

你可以本地跑打个断点,或者输出下 ChatGPT 返回的数据,就一目了然了

或者看重说说哪里不清楚的

from go-chatgpt-api.

time-river avatar time-river commented on July 19, 2024

其实里面有注释,用了 //

其他感觉顾名思义的,就没写,因为有些所谓注释就是把英文翻译成中文,好像没必要(没别的意思)

流程就是根据 AJAX 请求的不同状态,然后再根据 HTTP 状态码来判断正常处理还是报错,应该挺清晰的

你可以本地跑打个断点,或者输出下 ChatGPT 返回的数据,就一目了然了

或者看重说说哪里不清楚的

我想重构下代码的,因为里面出现了很多魔鬼数字,以及api经过了转换并不一定与openai的相兼容,但POST request部分,那些处理非200的response分支我没有遇到过,着实下不去手。

from go-chatgpt-api.

linweiyuan avatar linweiyuan commented on July 19, 2024

我不明白,那些魔鬼数字指的是 422、429 那些?

from go-chatgpt-api.

time-river avatar time-river commented on July 19, 2024

是的。还有dataArray.pop().substring(6)的6,这

conversationResponseDataString[0:1] == strconv.Itoa(4) || conversationResponseDataString[0:1] == strconv.Itoa(5) {
				statusCode, _ := strconv.Atoi(conversationResponseDataString[0:3])

等多处。

from go-chatgpt-api.

linweiyuan avatar linweiyuan commented on July 19, 2024

4xx 5xx 其实是 HTTP 状态码,有报错就额外处理

substring(6) 就是把 "data: {ChatGPT 实际数据的}" 的"data: " 去掉,因为 API 返回 SSE 有额外的处理返回 "data: "

然后你引用那段就是取出 HTTP 状态码如果有错误(不是 200 就是错)就返回异常

这些是基础设施的代码,如果你重构这里提 PR 我是不合并的

from go-chatgpt-api.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.