From 958328673c11aac72d5c59b5d7ca8fab9d78ad35 Mon Sep 17 00:00:00 2001 From: Shivaditya Shivganesh Date: Thu, 17 Oct 2024 01:58:26 -0400 Subject: [PATCH] feat: added instruction to the embedding --- src/adapters/openai/helpers/completions.ts | 1 - src/adapters/supabase/helpers/comment.ts | 2 +- src/adapters/supabase/helpers/issues.ts | 2 +- src/adapters/voyage/helpers/embedding.ts | 5 +++-- src/handlers/ask-llm.ts | 2 -- src/helpers/issue-fetching.ts | 1 - src/helpers/issue.ts | 1 - src/plugin.ts | 1 - 8 files changed, 5 insertions(+), 10 deletions(-) diff --git a/src/adapters/openai/helpers/completions.ts b/src/adapters/openai/helpers/completions.ts index af9a565..f68f305 100644 --- a/src/adapters/openai/helpers/completions.ts +++ b/src/adapters/openai/helpers/completions.ts @@ -71,7 +71,6 @@ export class Completions extends SuperOpenAi { }, }); const answer = res.choices[0].message; - console.log(JSON.stringify(res, null, 2)); if (answer && answer.content && res.usage) { return { answer: answer.content, tokenUsage: { input: res.usage.prompt_tokens, output: res.usage.completion_tokens, total: res.usage.total_tokens } }; } diff --git a/src/adapters/supabase/helpers/comment.ts b/src/adapters/supabase/helpers/comment.ts index e6aff31..d09f24a 100644 --- a/src/adapters/supabase/helpers/comment.ts +++ b/src/adapters/supabase/helpers/comment.ts @@ -33,7 +33,7 @@ export class Comment extends SuperSupabase { } async findSimilarComments(query: string, threshold: number, currentId: string): Promise { - const embedding = await this.context.adapters.voyage.embedding.createEmbedding(query); + const embedding = await this.context.adapters.voyage.embedding.createEmbedding({ text: query, prompt: "This is a query for the stored documents:" }); const { data, error } = await this.supabase.rpc("find_similar_comments", { current_id: currentId, query_text: query, diff --git a/src/adapters/supabase/helpers/issues.ts b/src/adapters/supabase/helpers/issues.ts index 8bd083e..142ef02 100644 --- a/src/adapters/supabase/helpers/issues.ts +++ b/src/adapters/supabase/helpers/issues.ts @@ -33,7 +33,7 @@ export class Issue extends SuperSupabase { return data; } async findSimilarIssues(plaintext: string, threshold: number, currentId: string): Promise { - const embedding = await this.context.adapters.voyage.embedding.createEmbedding(plaintext); + const embedding = await this.context.adapters.voyage.embedding.createEmbedding({ text: plaintext, prompt: "This is a query for the stored documents:" }); const { data, error } = await this.supabase.rpc("find_similar_issue_ftse", { current_id: currentId, query_text: plaintext, diff --git a/src/adapters/voyage/helpers/embedding.ts b/src/adapters/voyage/helpers/embedding.ts index 575543e..68797e2 100644 --- a/src/adapters/voyage/helpers/embedding.ts +++ b/src/adapters/voyage/helpers/embedding.ts @@ -11,12 +11,13 @@ export class Embedding extends SuperVoyage { this.context = context; } - async createEmbedding(text: string | null): Promise { + async createEmbedding(input: { text?: string; prompt?: string } = {}): Promise { + const { text = null, prompt = null } = input; if (text === null) { return new Array(VECTOR_SIZE).fill(0); } else { const response = await this.client.embed({ - input: text, + input: prompt ? `${prompt} ${text}` : text, model: "voyage-large-2-instruct", }); return (response.data && response.data[0]?.embedding) || []; diff --git a/src/handlers/ask-llm.ts b/src/handlers/ask-llm.ts index b9992ac..9a01ac1 100644 --- a/src/handlers/ask-llm.ts +++ b/src/handlers/ask-llm.ts @@ -23,7 +23,6 @@ export async function askQuestion(context: Context, question: string) { repo: context.payload.repository.name, }); const formattedChat = await formatChatHistory(context, streamlinedComments, specAndBodies); - console.log("formattedChat", formattedChat); return await askGpt(context, question, formattedChat); } @@ -56,7 +55,6 @@ export async function askGpt(context: Context, question: string, formattedChat: // Remove Null Results (Private Comments) similarText = similarText.filter((text) => text !== null); formattedChat = formattedChat.filter((text) => text !== null); - context.logger.info(formattedChat.join("")); // Optimize the context formattedChat = optimizeContext(formattedChat); // ReRank the results based on the question diff --git a/src/helpers/issue-fetching.ts b/src/helpers/issue-fetching.ts index 5af306e..486d83e 100644 --- a/src/helpers/issue-fetching.ts +++ b/src/helpers/issue-fetching.ts @@ -44,7 +44,6 @@ export async function fetchLinkedIssues(params: FetchParams) { throw new Error("Issue body or URL not found"); } - console.log(params, params.owner, params.repo); if (!params.owner || !params.repo) { throw new Error("Owner, repo, or issue number not found"); } diff --git a/src/helpers/issue.ts b/src/helpers/issue.ts index 69dc4dd..2c76179 100644 --- a/src/helpers/issue.ts +++ b/src/helpers/issue.ts @@ -126,7 +126,6 @@ export async function fetchCodeLinkedFromIssue( let parsedUrl = parseGitHubUrl(url); parsedUrl = parsedUrl ? { ...parsedUrl, path: removeLineNumbers(parsedUrl.path) } : null; if (!parsedUrl || !hasValidExtension(parsedUrl.path)) return null; - console.log(`Fetching content from ${url}`); try { //Parse the commit sha from the URL const commitSha = url.match(/https?:\/\/github\.com\/[^/]+\/[^/]+\/blob\/([^/]+)\/.+/); diff --git a/src/plugin.ts b/src/plugin.ts index a886a4b..8eab234 100644 --- a/src/plugin.ts +++ b/src/plugin.ts @@ -13,7 +13,6 @@ import OpenAI from "openai"; export async function plugin(inputs: PluginInputs, env: Env) { const octokit = new Octokit({ auth: inputs.authToken }); const supabase = createClient(env.SUPABASE_URL, env.SUPABASE_KEY); - console.log("inputs", env); const voyageClient = new VoyageAIClient({ apiKey: env.VOYAGEAI_API_KEY, });