Преглед на файлове

add Reverse: for v0.0.2

tags/v0.0.2
DengBiao преди 1 година
родител
ревизия
53f13dd698
променени са 5 файла, в които са добавени 69 реда и са изтрити 0 реда
  1. +8
    -0
      .idea/.gitignore
  2. +9
    -0
      .idea/go-chatgpt.iml
  3. +8
    -0
      .idea/modules.xml
  4. +6
    -0
      .idea/vcs.xml
  5. +38
    -0
      go-gpt3/chat.go

+ 8
- 0
.idea/.gitignore Целия файл

@@ -0,0 +1,8 @@
# 默认忽略的文件
/shelf/
/workspace.xml
# 基于编辑器的 HTTP 客户端请求
/httpRequests/
# Datasource local storage ignored files
/dataSources/
/dataSources.local.xml

+ 9
- 0
.idea/go-chatgpt.iml Целия файл

@@ -0,0 +1,9 @@
<?xml version="1.0" encoding="UTF-8"?>
<module type="WEB_MODULE" version="4">
<component name="Go" enabled="true" />
<component name="NewModuleRootManager">
<content url="file://$MODULE_DIR$" />
<orderEntry type="inheritedJdk" />
<orderEntry type="sourceFolder" forTests="false" />
</component>
</module>

+ 8
- 0
.idea/modules.xml Целия файл

@@ -0,0 +1,8 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="ProjectModuleManager">
<modules>
<module fileurl="file://$PROJECT_DIR$/.idea/go-chatgpt.iml" filepath="$PROJECT_DIR$/.idea/go-chatgpt.iml" />
</modules>
</component>
</project>

+ 6
- 0
.idea/vcs.xml Целия файл

@@ -0,0 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="VcsDirectoryMappings">
<mapping directory="$PROJECT_DIR$" vcs="Git" />
</component>
</project>

+ 38
- 0
go-gpt3/chat.go Целия файл

@@ -1,10 +1,12 @@
package gogpt

import (
"bufio"
"bytes"
"context"
"encoding/json"
"errors"
"fmt"
"net/http"
)

@@ -75,3 +77,39 @@ func (c *Client) CreateChatCompletion(
err = c.sendRequest(req, &response)
return
}

// CreateChatCompletionStream — API call to create a completion w/ streaming
func (c *Client) CreateChatCompletionStream(
ctx context.Context,
request CompletionRequest,
) (stream *CompletionStream, err error) {
request.Stream = true
reqBytes, err := json.Marshal(request)
if err != nil {
return
}

urlSuffix := "/chat/completions"
req, err := http.NewRequestWithContext(ctx, http.MethodPost, c.fullURL(urlSuffix), bytes.NewBuffer(reqBytes))
req.Header.Set("Content-Type", "application/json")
req.Header.Set("Accept", "text/event-stream")
req.Header.Set("Cache-Control", "no-cache")
req.Header.Set("Connection", "keep-alive")
req.Header.Set("Authorization", fmt.Sprintf("Bearer %s", c.config.authToken))
if err != nil {
return
}

resp, err := c.config.HTTPClient.Do(req) //nolint:bodyclose // body is closed in stream.Close()
if err != nil {
return
}

stream = &CompletionStream{
emptyMessagesLimit: c.config.EmptyMessagesLimit,

reader: bufio.NewReader(resp.Body),
response: resp,
}
return
}

Зареждане…
Отказ
Запис