Skip to content

Commit

Permalink
Merge pull request #31 from sshivaditya2019/issuesim
Browse files Browse the repository at this point in the history
  • Loading branch information
0x4007 authored Oct 11, 2024
2 parents 0fc8d04 + 3477aea commit ab3df04
Show file tree
Hide file tree
Showing 14 changed files with 349 additions and 123 deletions.
31 changes: 22 additions & 9 deletions src/adapters/supabase/helpers/comment.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ export class Comment extends SuperSupabase {
} else {
//Create the embedding for this comment
const embedding = await this.context.adapters.voyage.embedding.createEmbedding(markdown);
let plaintext: string | null = markdownToPlainText(markdown || "");
let plaintext: string | null = markdownToPlainText(markdown);
if (isPrivate) {
markdown = null as string | null;
payload = null as Record<string, unknown> | null;
Expand All @@ -54,21 +54,34 @@ export class Comment extends SuperSupabase {
this.context.logger.info("Comment created successfully");
}

async updateComment(markdown: string | null, commentNodeId: string, payload: Record<string, unknown> | null, isPrivate: boolean) {
async updateComment(
markdown: string | null,
commentNodeId: string,
authorId: number,
payload: Record<string, unknown> | null,
isPrivate: boolean,
issueId: string
) {
//Create the embedding for this comment
const embedding = Array.from(await this.context.adapters.voyage.embedding.createEmbedding(markdown));
let plaintext: string | null = markdownToPlainText(markdown || "");
let plaintext: string | null = markdownToPlainText(markdown);
if (isPrivate) {
markdown = null as string | null;
payload = null as Record<string, unknown> | null;
plaintext = null as string | null;
}
const { error } = await this.supabase
.from("issue_comments")
.update({ markdown, plaintext, embedding: embedding, payload, modified_at: new Date() })
.eq("id", commentNodeId);
if (error) {
this.context.logger.error("Error updating comment", error);
const comments = await this.getComment(commentNodeId);
if (comments && comments.length == 0) {
this.context.logger.info("Comment does not exist, creating a new one");
await this.createComment(markdown, commentNodeId, authorId, payload, isPrivate, issueId);
} else {
const { error } = await this.supabase
.from("issue_comments")
.update({ markdown, plaintext, embedding: embedding, payload, modified_at: new Date() })
.eq("id", commentNodeId);
if (error) {
this.context.logger.error("Error updating comment", error);
}
}
}

Expand Down
30 changes: 17 additions & 13 deletions src/adapters/supabase/helpers/issues.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ export class Issues extends SuperSupabase {
return;
} else {
const embedding = await this.context.adapters.voyage.embedding.createEmbedding(markdown);
let plaintext: string | null = markdownToPlainText(markdown || "");
let plaintext: string | null = markdownToPlainText(markdown);
if (isPrivate) {
payload = null;
markdown = null;
Expand All @@ -52,21 +52,24 @@ export class Issues extends SuperSupabase {
this.context.logger.info("Issue created successfully");
}

async updateIssue(markdown: string | null, issueNodeId: string, payload: Record<string, unknown> | null, isPrivate: boolean) {
//Create the embedding for this comment
async updateIssue(markdown: string | null, issueNodeId: string, payload: Record<string, unknown> | null, isPrivate: boolean, authorId: number) {
const embedding = Array.from(await this.context.adapters.voyage.embedding.createEmbedding(markdown));
let plaintext: string | null = markdownToPlainText(markdown || "");
let plaintext: string | null = markdownToPlainText(markdown);
if (isPrivate) {
markdown = null as string | null;
payload = null as Record<string, unknown> | null;
plaintext = null as string | null;
markdown = null;
payload = null;
plaintext = null;
}
const { error } = await this.supabase
.from("issues")
.update({ markdown, plaintext, embedding: embedding, payload, modified_at: new Date() })
.eq("id", issueNodeId);
if (error) {
this.context.logger.error("Error updating comment", error);
const issues = await this.getIssue(issueNodeId);
if (issues && issues.length == 0) {
this.context.logger.info("Issue does not exist, creating a new one");
await this.createIssue(issueNodeId, payload, isPrivate, markdown, authorId);
} else {
const { error } = await this.supabase.from("issues").update({ markdown, plaintext, embedding, payload, modified_at: new Date() }).eq("id", issueNodeId);

if (error) {
this.context.logger.error("Error updating comment", error);
}
}
}

Expand Down Expand Up @@ -96,6 +99,7 @@ export class Issues extends SuperSupabase {
current_id: currentId,
query_embedding: embedding,
threshold: threshold,
top_k: 5,
});
if (error) {
this.context.logger.error("Error finding similar issues", error);
Expand Down
4 changes: 3 additions & 1 deletion src/handlers/add-issue.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { Context } from "../types";
import { IssuePayload } from "../types/payload";
import { removeFootnotes } from "./issue-deduplication";

export async function addIssue(context: Context) {
const {
Expand All @@ -16,7 +17,8 @@ export async function addIssue(context: Context) {
if (!markdown) {
throw new Error("Issue body is empty");
}
await supabase.issue.createIssue(nodeId, payload, isPrivate, markdown, authorId);
const cleanedIssue = removeFootnotes(markdown);
await supabase.issue.createIssue(nodeId, payload, isPrivate, cleanedIssue, authorId);
} catch (error) {
if (error instanceof Error) {
logger.error(`Error creating issue:`, { error: error, stack: error.stack });
Expand Down
Loading

0 comments on commit ab3df04

Please sign in to comment.