Spaces:
Running
Running
| export async function resolveThreeJSError( | |
| errorMessage: string, | |
| apiKey: string | |
| ): Promise<string> { | |
| if (!apiKey) { | |
| return 'Please set your OpenRouter API key in the AI Assistant panel.'; | |
| } | |
| const systemPrompt = `You are an expert Three.js and React Three Fiber debugging assistant. | |
| When given an error, provide: | |
| 1. A clear explanation of the error | |
| 2. The root cause | |
| 3. A step-by-step fix | |
| 4. A corrected code snippet if applicable | |
| Keep responses concise and actionable.`; | |
| const response = await fetch('https://openrouter.ai/api/v1/chat/completions', { | |
| method: 'POST', | |
| headers: { | |
| 'Content-Type': 'application/json', | |
| 'Authorization': `Bearer ${apiKey}`, | |
| 'HTTP-Referer': 'https://huggingface.co', | |
| 'X-Title': '3D Studio AI Assistant', | |
| }, | |
| body: JSON.stringify({ | |
| model: 'stepfun/step-3.5-flash:free', | |
| messages: [ | |
| { role: 'system', content: systemPrompt }, | |
| { | |
| role: 'user', | |
| content: `I encountered this Three.js/React Three Fiber error:\n\n${errorMessage}\n\nPlease help me debug and fix it.`, | |
| }, | |
| ], | |
| reasoning: { enabled: true }, | |
| }), | |
| }); | |
| if (!response.ok) { | |
| throw new Error(`API request failed: ${response.statusText}`); | |
| } | |
| const data = await response.json(); | |
| return data.choices?.[0]?.message?.content || 'No response from AI.'; | |
| } | |