Skip to content

Commit

Permalink
chore: start to tidy up the CLI
Browse files Browse the repository at this point in the history
  • Loading branch information
ydennisy committed Nov 26, 2023
1 parent e1fd920 commit 26076ef
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 5 deletions.
5 changes: 4 additions & 1 deletion backend/src/llm.ts
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,9 @@ const summariseOrAnswerFromDocuments = async (
rows: SearchResultRow[],
query: string,
) => {
const titles = rows.map((row) => `- ${row.title}`).join('\n');
const titles = rows
.map((row) => `- ${row.title}: ${row.data?.content ?? ''}`)
.join('\n');
const input = `
Given the following list of documents, and query, you must
answer the question, or summarise the docs depending on the tone.
Expand All @@ -60,6 +62,7 @@ const summariseOrAnswerFromDocuments = async (
QUERY:
${query}
`;
console.log(input);
const stream = await openai.chat.completions.create({
model: 'gpt-3.5-turbo',
messages: [{ role: 'user', content: input }],
Expand Down
4 changes: 2 additions & 2 deletions backend/src/repo.ts
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ export class PrismaRepo implements Repo {
SELECT
id,
'web_page' as type,
jsonb_build_object('title', title, 'url', url) as data,
jsonb_build_object('title', title, 'url', url, 'content', content) as data,
1 - (embedding <=> ${queryEmbeddingSql}::vector) AS similarity
FROM web_pages
WHERE embedding IS NOT NULL
Expand All @@ -80,7 +80,7 @@ export class PrismaRepo implements Repo {
SELECT
id,
'paper' as type,
jsonb_build_object('title', title, 'content', content) as data,
jsonb_build_object('title', title, 'url', url, 'author', author, 'content', content) as data,
1 - (embedding <=> ${queryEmbeddingSql}::vector) AS similarity
FROM papers
WHERE embedding IS NOT NULL
Expand Down
10 changes: 8 additions & 2 deletions cli/src/search.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,9 @@ import chalk from 'chalk';
interface SearchResultRow {
id: string;
title: string;
similarity: number;
type: 'NOTE' | 'WEB_PAGE' | 'PAPER';
data: {};
}

const BASE_URL =
Expand All @@ -17,8 +19,12 @@ const search = async (q: string): Promise<void> => {
q,
},
});
const nodes = data.reduce((acc, { id, ...x }) => {
acc[id] = x;
const nodes = data.reduce((acc, { id, data, ...rest }) => {
// const {content} = data;
acc[id] = {
...rest,
//...data,
};
return acc;
}, {} as Record<string, object>);

Expand Down

0 comments on commit 26076ef

Please sign in to comment.