mirror of
https://github.com/0xJacky/nginx-ui.git
synced 2025-05-11 02:15:48 +02:00
enhance: check whether openai.token is empty
This commit is contained in:
parent
94408cd21f
commit
e11bc16842
1 changed files with 12 additions and 4 deletions
|
@ -10,7 +10,6 @@ import (
|
|||
"github.com/pkg/errors"
|
||||
"github.com/sashabaranov/go-openai"
|
||||
"io"
|
||||
"log"
|
||||
"net/http"
|
||||
"net/url"
|
||||
"os"
|
||||
|
@ -39,7 +38,17 @@ func MakeChatCompletionRequest(c *gin.Context) {
|
|||
c.Writer.Header().Set("Cache-Control", "no-cache")
|
||||
c.Writer.Header().Set("Connection", "keep-alive")
|
||||
c.Writer.Header().Set("Access-Control-Allow-Origin", "*")
|
||||
log.Println(settings.OpenAISettings.Token)
|
||||
|
||||
if settings.OpenAISettings.Token == "" {
|
||||
c.Stream(func(w io.Writer) bool {
|
||||
c.SSEvent("message", gin.H{
|
||||
"type": "error",
|
||||
"content": "[Error] OpenAI token is empty",
|
||||
})
|
||||
return false
|
||||
})
|
||||
return
|
||||
}
|
||||
|
||||
config := openai.DefaultConfig(settings.OpenAISettings.Token)
|
||||
|
||||
|
@ -104,9 +113,8 @@ func MakeChatCompletionRequest(c *gin.Context) {
|
|||
return
|
||||
}
|
||||
|
||||
// Send SSE to client
|
||||
message := fmt.Sprintf("%s", response.Choices[0].Delta.Content)
|
||||
fmt.Printf("%s", response.Choices[0].Delta.Content)
|
||||
fmt.Printf("%s", message)
|
||||
_ = os.Stdout.Sync()
|
||||
|
||||
msgChan <- message
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue