|
| 1 | +import { type LanguageModel, streamText, type CoreMessage, generateObject } from "ai"; |
| 2 | +import { type ZodType, type ZodTypeDef } from "zod"; |
| 3 | +import { mosLookup } from "./tools/mos-lookup"; |
| 4 | + |
| 5 | +const baseContext = ` |
| 6 | + You are a specialized AI assistant for Vets Who Code members, designed to provide clear, practical technical guidance to veterans transitioning into software development careers.\n\n |
| 7 | + CORE TECH STACK:\n |
| 8 | + - Frontend: JavaScript, TypeScript, React, Next.js\n |
| 9 | + - Styling: CSS, Tailwind CSS\n |
| 10 | + - Backend: Python, FastAPI\n |
| 11 | + - Data & Visualization: Streamlit\n |
| 12 | + - Advanced: AI/ML fundamentals\n |
| 13 | + - Development Tools: Git, GitHub, VS Code\n |
| 14 | + - Testing: Jest, Pytest\n\n |
| 15 | +
|
| 16 | + CAREER TRANSITION GUIDANCE:\n |
| 17 | + 1. Resume Development:\n |
| 18 | + - Technical Skills: Programming Languages, Frameworks, Tools, Cloud, Testing\n |
| 19 | + - Military Experience Translation: Leadership, Problem-solving, Team Collaboration\n\n |
| 20 | +
|
| 21 | + 2. Portfolio Development:\n |
| 22 | + - Clean code and documentation\n |
| 23 | + - Version control and API integration\n |
| 24 | + - Responsive design and performance\n |
| 25 | + - Testing and TypeScript implementation\n |
| 26 | + - Security and accessibility standards\n\n |
| 27 | +
|
| 28 | + LEARNING PATHS:\n |
| 29 | + 1. Fundamentals: HTML, CSS, JavaScript, Git\n |
| 30 | + 2. Intermediate: TypeScript, React, Python\n |
| 31 | + 3. Advanced: Next.js, FastAPI, Streamlit, AI/ML\n\n |
| 32 | +
|
| 33 | + PROJECT FOCUS:\n |
| 34 | + 1. Portfolio Projects: Personal website, APIs, Data visualization\n |
| 35 | + 2. Technical Skills: Code quality, Testing, Security, Performance\n |
| 36 | + 3. Career Materials: GitHub profile, Technical blog, Documentation\n\n |
| 37 | +
|
| 38 | + Remember: Provide practical guidance for building technical skills and transitioning to software development careers. |
| 39 | + Focus on concrete examples and best practices. |
| 40 | +`; |
| 41 | + |
| 42 | +export class ChatBot { |
| 43 | + model: LanguageModel; |
| 44 | + |
| 45 | + constructor(model: LanguageModel) { |
| 46 | + this.model = model; |
| 47 | + } |
| 48 | + |
| 49 | + chat(messages: CoreMessage[], systemContext: string | null = baseContext) { |
| 50 | + const includedMessages: CoreMessage[] = []; |
| 51 | + if (systemContext) { |
| 52 | + includedMessages.push({ |
| 53 | + role: "system", |
| 54 | + content: systemContext, |
| 55 | + }); |
| 56 | + } |
| 57 | + includedMessages.push(...messages); |
| 58 | + |
| 59 | + console.log("Sending messages to AI model:", includedMessages); |
| 60 | + const response = streamText({ |
| 61 | + model: this.model, |
| 62 | + messages: includedMessages, |
| 63 | + tools: { mosLookup }, |
| 64 | + onFinish: (message) => { |
| 65 | + // TODO - store response in database |
| 66 | + if (message.text) { |
| 67 | + console.error("Response received:", message.text); |
| 68 | + } |
| 69 | + |
| 70 | + if (message.toolCalls && message.toolCalls.length > 0) { |
| 71 | + console.log("Tool calls received:", JSON.stringify(message.toolCalls)); |
| 72 | + console.log("Tool call results:", JSON.stringify(message.toolResults)); |
| 73 | + } |
| 74 | + }, |
| 75 | + onError: (error) => { |
| 76 | + console.error("Error during chat response stream:", error); |
| 77 | + }, |
| 78 | + maxSteps: 5, |
| 79 | + }); |
| 80 | + console.log("Chat response stream initialized"); |
| 81 | + |
| 82 | + return response; |
| 83 | + } |
| 84 | +} |
0 commit comments