UNPKG

ai-code-writer

Version:

An AI code writer application using OpenAI APIs for audio transcription and chat completion.

54 lines (53 loc) 3.12 kB
"use strict"; var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) { function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); } return new (P || (P = Promise))(function (resolve, reject) { function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } } function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } } function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); } step((generator = generator.apply(thisArg, _arguments || [])).next()); }); }; Object.defineProperty(exports, "__esModule", { value: true }); class ConversationUseCase { constructor(chatCompletionClient, conversationStorage, conversationLogger, systemPromptService, gptResponseProcessor, fileCollectorService) { this.chatCompletionClient = chatCompletionClient; this.conversationStorage = conversationStorage; this.conversationLogger = conversationLogger; this.systemPromptService = systemPromptService; this.gptResponseProcessor = gptResponseProcessor; this.fileCollectorService = fileCollectorService; this.conversationHistory = []; } initialize() { return __awaiter(this, void 0, void 0, function* () { this.conversationHistory = yield this.conversationStorage.loadConversation(); if (this.conversationHistory.length != 0) return; const systemPrompt = this.systemPromptService.getSystemPrompt(); this.conversationHistory.push({ role: 'system', content: systemPrompt }); const filesContent = yield this.fileCollectorService.collectFiles(); this.conversationHistory.push({ role: 'user', content: filesContent }); }); } handleConversation(request, response) { return __awaiter(this, void 0, void 0, function* () { this.conversationHistory.push({ role: 'user', content: request.transcription }); const responseText = yield this.chatCompletionClient.completePrompt(this.conversationHistory); this.conversationHistory.push({ role: 'assistant', content: responseText }); yield this.conversationStorage.saveConversation(this.conversationHistory); yield this.conversationLogger.logConversation(this.conversationHistory); const { comments, actions } = yield this.gptResponseProcessor.processResponse(responseText); response.comments = comments.join('\n'); response.actions = actions; }); } addToConversationHistory(request) { return __awaiter(this, void 0, void 0, function* () { this.conversationHistory.push({ role: 'user', content: request.transcription }); yield this.conversationStorage.saveConversation(this.conversationHistory); yield this.conversationLogger.logConversation(this.conversationHistory); }); } } exports.default = ConversationUseCase;