@@ -194,42 +194,49 @@ export class RemixAIPlugin extends Plugin {
194
194
* - If `useRag` is `true`, the function fetches additional context from a RAG API and prepends it to the user prompt.
195
195
*/
196
196
async generate ( prompt : string , params : IParams = AssistantParams , newThreadID :string = "" , useRag :boolean = false , statusCallback ?: ( status : string ) => Promise < void > ) : Promise < any > {
197
- params . stream_result = false // enforce no stream result
198
- params . threadId = newThreadID
199
- params . provider = 'anthropic' // enforce all generation to be only on anthropic
200
- useRag = false
201
- _paq . push ( [ 'trackEvent' , 'ai' , 'remixAI' , 'GenerateNewAIWorkspace' ] )
202
- let userPrompt = ''
203
-
204
- if ( useRag ) {
205
- statusCallback ?.( 'Fetching RAG context...' )
206
- try {
207
- let ragContext = ""
208
- const options = { headers : { 'Content-Type' : 'application/json' , } }
209
- const response = await axios . post ( endpointUrls . rag , { query : prompt , endpoint :"query" } , options )
210
- if ( response . data ) {
211
- ragContext = response . data . response
212
- userPrompt = "Using the following context: ```\n\n" + JSON . stringify ( ragContext ) + "```\n\n" + userPrompt
213
- } else {
214
- console . log ( 'Invalid response from RAG context API:' , response . data )
197
+ try {
198
+ params . stream_result = false // enforce no stream result
199
+ params . threadId = newThreadID
200
+ params . provider = 'anthropic' // enforce all generation to be only on anthropic
201
+ useRag = false
202
+ _paq . push ( [ 'trackEvent' , 'ai' , 'remixAI' , 'GenerateNewAIWorkspace' ] )
203
+ let userPrompt = ''
204
+
205
+ if ( useRag ) {
206
+ statusCallback ?.( 'Fetching RAG context...' )
207
+ try {
208
+ let ragContext = ""
209
+ const options = { headers : { 'Content-Type' : 'application/json' , } }
210
+ const response = await axios . post ( endpointUrls . rag , { query : prompt , endpoint :"query" } , options )
211
+ if ( response . data ) {
212
+ ragContext = response . data . response
213
+ userPrompt = "Using the following context: ```\n\n" + JSON . stringify ( ragContext ) + "```\n\n" + userPrompt
214
+ } else {
215
+ console . log ( 'Invalid response from RAG context API:' , response . data )
216
+ }
217
+ } catch ( error ) {
218
+ console . log ( 'RAG context error:' , error )
215
219
}
216
- } catch ( error ) {
217
- console . log ( 'RAG context error:' , error )
220
+ } else {
221
+ userPrompt = prompt
218
222
}
219
- } else {
220
- userPrompt = prompt
223
+ // Evaluate if this function requires any context
224
+ // console.log('Generating code for prompt:', userPrompt, 'and threadID:', newThreadID)
225
+ await statusCallback ?.( 'Generating new workspace with AI...\nThis might take some minutes. Please be patient!' )
226
+ const result = await this . remoteInferencer . generate ( userPrompt , params )
227
+
228
+ await statusCallback ?.( 'Creating contracts and files...' )
229
+ const genResult = await this . contractor . writeContracts ( result , userPrompt , statusCallback )
230
+
231
+ if ( genResult . includes ( 'No payload' ) ) return genResult
232
+ await this . call ( 'menuicons' , 'select' , 'filePanel' )
233
+ return genResult
234
+ } catch {
235
+ // not handled
236
+ } finally {
237
+ params . provider = this . assistantProvider
221
238
}
222
- // Evaluate if this function requires any context
223
- // console.log('Generating code for prompt:', userPrompt, 'and threadID:', newThreadID)
224
- await statusCallback ?.( 'Generating new workspace with AI...\nThis might take some minutes. Please be patient!' )
225
- const result = await this . remoteInferencer . generate ( userPrompt , params )
226
-
227
- await statusCallback ?.( 'Creating contracts and files...' )
228
- const genResult = await this . contractor . writeContracts ( result , userPrompt , statusCallback )
229
239
230
- if ( genResult . includes ( 'No payload' ) ) return genResult
231
- await this . call ( 'menuicons' , 'select' , 'filePanel' )
232
- return genResult
233
240
}
234
241
235
242
/**
0 commit comments