File tree Expand file tree Collapse file tree 1 file changed +12
-4
lines changed Expand file tree Collapse file tree 1 file changed +12
-4
lines changed Original file line number Diff line number Diff line change @@ -10,7 +10,6 @@ import (
1010 "github.com/pkg/errors"
1111 "github.com/sashabaranov/go-openai"
1212 "io"
13- "log"
1413 "net/http"
1514 "net/url"
1615 "os"
@@ -39,7 +38,17 @@ func MakeChatCompletionRequest(c *gin.Context) {
3938 c .Writer .Header ().Set ("Cache-Control" , "no-cache" )
4039 c .Writer .Header ().Set ("Connection" , "keep-alive" )
4140 c .Writer .Header ().Set ("Access-Control-Allow-Origin" , "*" )
42- log .Println (settings .OpenAISettings .Token )
41+
42+ if settings .OpenAISettings .Token == "" {
43+ c .Stream (func (w io.Writer ) bool {
44+ c .SSEvent ("message" , gin.H {
45+ "type" : "error" ,
46+ "content" : "[Error] OpenAI token is empty" ,
47+ })
48+ return false
49+ })
50+ return
51+ }
4352
4453 config := openai .DefaultConfig (settings .OpenAISettings .Token )
4554
@@ -104,9 +113,8 @@ func MakeChatCompletionRequest(c *gin.Context) {
104113 return
105114 }
106115
107- // Send SSE to client
108116 message := fmt .Sprintf ("%s" , response .Choices [0 ].Delta .Content )
109- fmt .Printf ("%s" , response . Choices [ 0 ]. Delta . Content )
117+ fmt .Printf ("%s" , message )
110118 _ = os .Stdout .Sync ()
111119
112120 msgChan <- message
You can’t perform that action at this time.
0 commit comments