(userMessage: string)
| 46 | } |
| 47 | |
| 48 | async sendMessage(userMessage: string) { |
| 49 | try { |
| 50 | this.conversationHistory.push({ |
| 51 | role: "user", |
| 52 | content: userMessage, |
| 53 | }); |
| 54 | |
| 55 | const requestBody = { |
| 56 | model: "gemini-fast", |
| 57 | messages: [ |
| 58 | { |
| 59 | role: "system", |
| 60 | content: this.systemPrompt, |
| 61 | }, |
| 62 | ...this.conversationHistory, |
| 63 | ], |
| 64 | max_tokens: 1000, |
| 65 | }; |
| 66 | |
| 67 | const response = await axios.post(API_BASE_URL, requestBody, { |
| 68 | headers: { |
| 69 | "Content-Type": "application/json", |
| 70 | "Authorization": "Bearer pk_n6m9ghhNIlqzUvBp", |
| 71 | }, |
| 72 | }); |
| 73 | |
| 74 | const assistantMessage = response.data.choices[0].message.content; |
| 75 | |
| 76 | this.conversationHistory.push({ |
| 77 | role: "assistant", |
| 78 | content: assistantMessage, |
| 79 | }); |
| 80 | |
| 81 | return { |
| 82 | success: true, |
| 83 | message: assistantMessage, |
| 84 | timestamp: new Date().toISOString(), |
| 85 | }; |
| 86 | } catch (error: unknown) { |
| 87 | console.error("socBot API Error:", error); |
| 88 | |
| 89 | const fallbackMessage = |
| 90 | "I'm experiencing some technical difficulties right now. In the meantime, you can:\n\n• Check our FAQ page for common questions\n• Browse our project ideas\n• Join our Discord community for direct support\n• Contact mentors directly via email\n\nI'll be back online soon to help with your GSOC questions!"; |
| 91 | |
| 92 | return { |
| 93 | success: false, |
| 94 | message: fallbackMessage, |
| 95 | error: error instanceof Error ? error.message : "Unknown error", |
| 96 | timestamp: new Date().toISOString(), |
| 97 | }; |
| 98 | } |
| 99 | } |
| 100 | |
| 101 | clearHistory(): void { |
| 102 | this.conversationHistory = []; |
no test coverage detected