Skip to content

Commit

Permalink
feat: added instruction to the embedding
Browse files Browse the repository at this point in the history
  • Loading branch information
sshivaditya committed Oct 17, 2024
1 parent 6c7f136 commit 9583286
Show file tree
Hide file tree
Showing 8 changed files with 5 additions and 10 deletions.
1 change: 0 additions & 1 deletion src/adapters/openai/helpers/completions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 } };
}
Expand Down
2 changes: 1 addition & 1 deletion src/adapters/supabase/helpers/comment.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ export class Comment extends SuperSupabase {
}

async findSimilarComments(query: string, threshold: number, currentId: string): Promise<CommentSimilaritySearchResult[] | null> {
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,
Expand Down
2 changes: 1 addition & 1 deletion src/adapters/supabase/helpers/issues.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ export class Issue extends SuperSupabase {
return data;
}
async findSimilarIssues(plaintext: string, threshold: number, currentId: string): Promise<IssueSimilaritySearchResult[] | null> {
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,
Expand Down
5 changes: 3 additions & 2 deletions src/adapters/voyage/helpers/embedding.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,13 @@ export class Embedding extends SuperVoyage {
this.context = context;
}

async createEmbedding(text: string | null): Promise<number[]> {
async createEmbedding(input: { text?: string; prompt?: string } = {}): Promise<number[]> {
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) || [];
Expand Down
2 changes: 0 additions & 2 deletions src/handlers/ask-llm.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}

Expand Down Expand Up @@ -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
Expand Down
1 change: 0 additions & 1 deletion src/helpers/issue-fetching.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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");
}
Expand Down
1 change: 0 additions & 1 deletion src/helpers/issue.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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\/([^/]+)\/.+/);
Expand Down
1 change: 0 additions & 1 deletion src/plugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
});
Expand Down

0 comments on commit 9583286

Please sign in to comment.