@@ -194,23 +194,32 @@ struct WindowBaseCommandHandler: SuggestionCommandHandler {
194194 let fileURL = try await Environment . fetchCurrentFileURL ( )
195195 let endpoint = UserDefaults . shared. value ( for: \. chatGPTEndpoint)
196196 let model = UserDefaults . shared. value ( for: \. chatGPTModel)
197+ let language = UserDefaults . shared. value ( for: \. chatGPTLanguage)
197198 guard let selection = editor. selections. last else { return }
199+
198200 let service = ChatGPTService (
199201 systemPrompt: """
200- You are a code explanation engine, you can only explain the code, do not interpret or translate it. Reply in Chinese
202+ You are a code explanation engine, you can only explain the code, do not interpret or translate it. Reply in \( language . isEmpty ? language : " English " )
201203 """ ,
202204 apiKey: UserDefaults . shared. value ( for: \. openAIAPIKey) ,
203205 endpoint: endpoint. isEmpty ? nil : endpoint,
204206 model: model. isEmpty ? nil : model,
205- temperature: 1 ,
206- maxToken: 2048
207+ temperature: 0.6 ,
208+ maxToken: UserDefaults . shared . value ( for : \ . chatGPTMaxToken )
207209 )
208-
210+
209211 let code = editor. selectedCode ( in: selection)
210212 Task {
211- try ? await service. send ( content: code, summary: " Explain selected code. " )
213+ try ? await service. send (
214+ content: removeContinousSpaces ( from: code) ,
215+ summary: " Explain selected code from \( selection. start. line) : \( selection. start. character) to \( selection. end. line) : \( selection. end. character) . "
216+ )
212217 }
213-
218+
214219 presenter. presentChatGPTConversation ( service, fileURL: fileURL)
215220 }
216221}
222+
223+ func removeContinousSpaces( from string: String ) -> String {
224+ return string. replacingOccurrences ( of: " + " , with: " " , options: . regularExpression)
225+ }
0 commit comments