@@ -180,20 +180,20 @@ func (s *ChatServer) appendConversationMessage(
180180
181181// 如果 conversationId 是 "", 就创建新对话,否则就追加消息到对话
182182// conversationType 可以在一次 conversation 中多次切换
183- func (s * ChatServer ) prepare (ctx context.Context , projectId string , conversationId string , userMessage string , userSelectedText string , languageModel models.LanguageModel , conversationType chatv1.ConversationType ) (context.Context , * models.Conversation , error ) {
183+ func (s * ChatServer ) prepare (ctx context.Context , projectId string , conversationId string , userMessage string , userSelectedText string , languageModel models.LanguageModel , conversationType chatv1.ConversationType ) (context.Context , * models.Conversation , * models. Settings , error ) {
184184 actor , err := contextutil .GetActor (ctx )
185185 if err != nil {
186- return ctx , nil , err
186+ return ctx , nil , nil , err
187187 }
188188
189189 project , err := s .projectService .GetProject (ctx , actor .ID , projectId )
190190 if err != nil && err != mongo .ErrNoDocuments {
191- return ctx , nil , err
191+ return ctx , nil , nil , err
192192 }
193193
194194 userInstructions , err := s .userService .GetUserInstructions (ctx , actor .ID )
195195 if err != nil {
196- return ctx , nil , err
196+ return ctx , nil , nil , err
197197 }
198198
199199 var latexFullSource string
@@ -202,12 +202,12 @@ func (s *ChatServer) prepare(ctx context.Context, projectId string, conversation
202202 latexFullSource = "latex_full_source is not available in debug mode"
203203 default :
204204 if project == nil || project .IsOutOfDate () {
205- return ctx , nil , shared .ErrProjectOutOfDate ("project is out of date" )
205+ return ctx , nil , nil , shared .ErrProjectOutOfDate ("project is out of date" )
206206 }
207207
208208 latexFullSource , err = project .GetFullContent ()
209209 if err != nil {
210- return ctx , nil , err
210+ return ctx , nil , nil , err
211211 }
212212 }
213213
@@ -238,34 +238,44 @@ func (s *ChatServer) prepare(ctx context.Context, projectId string, conversation
238238 }
239239
240240 if err != nil {
241- return ctx , nil , err
241+ return ctx , nil , nil , err
242242 }
243243
244244 ctx = contextutil .SetProjectID (ctx , conversation .ProjectID )
245245 ctx = contextutil .SetConversationID (ctx , conversation .ID .Hex ())
246246
247- return ctx , conversation , nil
247+ settings , err := s .userService .GetUserSettings (ctx , actor .ID )
248+ if err != nil {
249+ return ctx , conversation , nil , err
250+ }
251+
252+ return ctx , conversation , settings , nil
248253}
249254
250255// Deprecated: Use CreateConversationMessageStream instead.
251256func (s * ChatServer ) CreateConversationMessage (
252257 ctx context.Context ,
253258 req * chatv1.CreateConversationMessageRequest ,
254259) (* chatv1.CreateConversationMessageResponse , error ) {
255- ctx , conversation , err := s .prepare (
260+ languageModel := models .LanguageModel (req .GetLanguageModel ())
261+ ctx , conversation , settings , err := s .prepare (
256262 ctx ,
257263 req .GetProjectId (),
258264 req .GetConversationId (),
259265 req .GetUserMessage (),
260266 req .GetUserSelectedText (),
261- models . LanguageModel ( req . GetLanguageModel ()) ,
267+ languageModel ,
262268 req .GetConversationType (),
263269 )
264270 if err != nil {
265271 return nil , err
266272 }
267273
268- openaiChatHistory , inappChatHistory , err := s .aiClient .ChatCompletion (ctx , conversation .LanguageModel , conversation .OpenaiChatHistory )
274+ llmProvider := & models.LLMProviderConfig {
275+ Endpoint : s .cfg .OpenAIBaseURL ,
276+ APIKey : settings .OpenAIAPIKey ,
277+ }
278+ openaiChatHistory , inappChatHistory , err := s .aiClient .ChatCompletion (ctx , languageModel , conversation .OpenaiChatHistory , llmProvider )
269279 if err != nil {
270280 return nil , err
271281 }
@@ -290,7 +300,7 @@ func (s *ChatServer) CreateConversationMessage(
290300 for i , bsonMsg := range conversation .InappChatHistory {
291301 protoMessages [i ] = mapper .BSONToChatMessage (bsonMsg )
292302 }
293- title , err := s .aiClient .GetConversationTitle (ctx , protoMessages )
303+ title , err := s .aiClient .GetConversationTitle (ctx , protoMessages , llmProvider )
294304 if err != nil {
295305 s .logger .Error ("Failed to get conversation title" , "error" , err , "conversationID" , conversation .ID .Hex ())
296306 return
0 commit comments