Skip to content

Commit cd6f9d7

Browse files
STetsingAniket-Engg
authored andcommitted
resolved issues requests failling after generate
1 parent d4ca906 commit cd6f9d7

File tree

1 file changed

+39
-32
lines changed

1 file changed

+39
-32
lines changed

apps/remix-ide/src/app/plugins/remixAIPlugin.tsx

Lines changed: 39 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -194,42 +194,49 @@ export class RemixAIPlugin extends Plugin {
194194
* - If `useRag` is `true`, the function fetches additional context from a RAG API and prepends it to the user prompt.
195195
*/
196196
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)
215219
}
216-
} catch (error) {
217-
console.log('RAG context error:', error)
220+
} else {
221+
userPrompt = prompt
218222
}
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
221238
}
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)
229239

230-
if (genResult.includes('No payload')) return genResult
231-
await this.call('menuicons', 'select', 'filePanel')
232-
return genResult
233240
}
234241

235242
/**

0 commit comments

Comments
 (0)