Skip to content

Commit 6c8bfd2

Browse files
committed
fix: ChatGPT messages history for stream
1 parent 2649b71 commit 6c8bfd2

File tree

3 files changed

+24
-19
lines changed

3 files changed

+24
-19
lines changed

api/streams/streams.go

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -99,6 +99,18 @@ func GetStream(c *gin.Context) {
9999
enabled = false
100100
}
101101

102+
g := query.ChatGPTLog
103+
chatgpt, err := g.Where(g.Name.Eq(path)).FirstOrCreate()
104+
105+
if err != nil {
106+
api.ErrHandler(c, err)
107+
return
108+
}
109+
110+
if chatgpt.Content == nil {
111+
chatgpt.Content = make([]openai.ChatCompletionMessage, 0)
112+
}
113+
102114
s := query.Stream
103115
stream, err := s.Where(s.Path.Eq(path)).FirstOrInit()
104116

@@ -120,7 +132,7 @@ func GetStream(c *gin.Context) {
120132
Enabled: enabled,
121133
Name: name,
122134
Config: string(origContent),
123-
ChatGPTMessages: stream.ChatGPTMessages,
135+
ChatGPTMessages: chatgpt.Content,
124136
})
125137
return
126138
}
@@ -133,16 +145,14 @@ func GetStream(c *gin.Context) {
133145
return
134146
}
135147

136-
c.Set("maybe_error", "nginx_config_syntax_error")
137-
138148
c.JSON(http.StatusOK, Stream{
139149
ModifiedAt: file.ModTime(),
140150
Advanced: stream.Advanced,
141151
Enabled: enabled,
142152
Name: name,
143153
Config: nginxConfig.FmtCode(),
144154
Tokenized: nginxConfig,
145-
ChatGPTMessages: stream.ChatGPTMessages,
155+
ChatGPTMessages: chatgpt.Content,
146156
})
147157
}
148158

model/stream.go

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@ package model
22

33
type Stream struct {
44
Model
5-
Path string `json:"path"`
6-
Advanced bool `json:"advanced"`
7-
ChatGPTMessages ChatGPTCompletionMessages `json:"chatgpt_messages" gorm:"serializer:json"`
5+
Path string `json:"path"`
6+
Advanced bool `json:"advanced"`
87
}

query/streams.gen.go

Lines changed: 8 additions & 12 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)