File size: 1,381 Bytes
43024e4
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
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.';
}