Skip to content

Commit

Permalink
Add embeddings
Browse files Browse the repository at this point in the history
Signed-off-by: Andreia Ocănoaia <[email protected]>
  • Loading branch information
andreia-oca committed Jun 9, 2024
1 parent e6b9421 commit d44558e
Show file tree
Hide file tree
Showing 6 changed files with 12 additions and 12 deletions.
24 changes: 12 additions & 12 deletions server/backend.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,33 +15,30 @@ export type UserDescription = {
description: string;
}

export type Talks = {
title: string;
description: string;
export type Recommendation = {
speaker: string;
bio: string;
reason: string;
}

const CONTEXT_DOCS_NUMBER = 15
const DATABASE_PATH = "./vectorStore";

@GenezioDeploy()
export class BackendService {
constructor() {}

// I am a fullstack software engineer interested in: open source, generative ai, backend technologies, cloud, cloud native, deployment, dev tools.
// I am a product engineer interested in leadership, defining clear scopes, user experience, getting feedback
async ask(user: UserDescription): Promise<string> {
async ask(user: UserDescription): Promise<Recommendation[]> {
const OPENAI_API_KEY = process.env.OPENAI_API_KEY;
if (!OPENAI_API_KEY) {
throw new Error(
"You need to provide an OpenAI API key. Go to https://platform.openai.com/account/api-keys and save it in a `.env` file.",
);
}

// Set the database path
const database = "./lancedb";
// Connect to the database
const db = await connect(database);
const db = await connect(DATABASE_PATH);
// Open the table
const table = await db.openTable("vectors");

Expand Down Expand Up @@ -88,7 +85,7 @@ export class BackendService {
Based on the provided user description select the top 3 speakers you would recommend to the user.
You must also mention why you selected these speakers.
You must respond as a json object with the following structure: a list of speakers with the following fields: speaker, why.
You must respond as a json object with the following structure: a list of speakers with the following fields: speaker, reason.
Do not add any additional information to the response.
Expand Down Expand Up @@ -116,12 +113,15 @@ Context: {context}`,
const chain = setupAndRetrieval.pipe(prompt).pipe(model).pipe(outputParser);

// Invoke the model to answer the question
const response = await chain.invoke(
const rawResponse = await chain.invoke(
user.description,
);

console.log("Answer:", response);
const response = rawResponse.replace('```json', '').replace('```', '');
const recommendationList = JSON.parse(response) as Recommendation[];

console.log("Recommendation list: ", recommendationList);

return response;
return recommendationList;
}
}
Binary file added server/vectorStore/vectors.lance/_latest.manifest
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.

0 comments on commit d44558e

Please sign in to comment.