Skip to content

Commit

Permalink
app service extends embeddingService
Browse files Browse the repository at this point in the history
  • Loading branch information
Olasunkanmi Oyinlola authored and Olasunkanmi Oyinlola committed Feb 11, 2024
1 parent 1705bb6 commit 7406cb1
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 8 deletions.
3 changes: 2 additions & 1 deletion api/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import { DataBase } from "./database";
import express, { Express } from "express";
import "dotenv/config";
import { getValue } from "./utils";
import { CONSTANTS } from "./core/constants";
const app: Express = express();

export const database: DataBase = new DataBase();
Expand Down Expand Up @@ -31,7 +32,7 @@ const filePath: string = getValue("PDF_ABSOLUTE_PATH");
const apiKey: string = getValue("API_KEY");

const createEmbedding = async () => {
const appService = new AppService(apiKey, filePath);
const appService = new AppService(apiKey, filePath, CONSTANTS.generativeAIModel);
return await appService.createEmbeddings();
};

Expand Down
13 changes: 7 additions & 6 deletions api/services/app.service.ts
Original file line number Diff line number Diff line change
@@ -1,26 +1,27 @@
import { CONSTANTS } from "../core/constants";
import { IDocumentService } from "../interfaces/document-service.interface";
import { IEmbeddingService } from "../interfaces/embedding-service.interface";
import { DocumentService } from "./document-service";
import { EmbeddingService } from "./embed-service";
import { database } from "..";

export class AppService {
constructor(private readonly APIkey: string, private readonly documentPath: string) {}
export class AppService extends EmbeddingService {
constructor(apikey: string, private readonly documentPath: string, AIModel: string) {
super(apikey, AIModel);
}
async createEmbeddings(): Promise<void> {
const documentService: IDocumentService = new DocumentService();
const embeddingService: IEmbeddingService = new EmbeddingService(this.APIkey, CONSTANTS.generativeAIModel);
let text: string;
if (this.documentPath.length) {
text = await documentService.convertPDFToText(this.documentPath);
}
if (text) {
console.log("...generating embeddings");
const embeddings = await embeddingService.generateEmbeddings(text);
const embeddings = await this.generateEmbeddings(text);
if (embeddings) {
console.log("...embeddings generated");
return await database.createDocument(text, embeddings);
}
}
}

async similaritySearch() {}
}
2 changes: 1 addition & 1 deletion api/services/embed-service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { IEmbeddingService } from "../interfaces/embedding-service.interface";

export class EmbeddingService implements IEmbeddingService {
genAI: GoogleGenerativeAI;
constructor(private readonly apiKey: string, private readonly AIModel: string) {
constructor(protected readonly apiKey: string, protected readonly AIModel: string) {
this.genAI = new GoogleGenerativeAI(this.apiKey);
}
/**
Expand Down

0 comments on commit 7406cb1

Please sign in to comment.