generated from ubiquity-os/plugin-template
-
Notifications
You must be signed in to change notification settings - Fork 11
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #9 from sshivaditya2019/development
- Loading branch information
Showing
42 changed files
with
810 additions
and
288 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,3 @@ | ||
SUPABASE_URL="" | ||
SUPABASE_KEY="" | ||
OPENAI_API_KEY="" | ||
VOYAGEAI_API_KEY="" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,3 @@ | ||
SUPABASE_URL= | ||
SUPABASE_KEY= | ||
OPENAI_API_KEY= | ||
VOYAGEAI_API_KEY= |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,5 @@ | ||
{ | ||
"name": "@ubiquity-os/comment-vector-embeddings", | ||
"description": "Issue comment plugin for Ubiquibot. It enables the storage, updating, and deletion of issue comment embeddings.", | ||
"ubiquity:listeners": ["issue_comment.created", "issue_comment.edited", "issue_comment.deleted"] | ||
"ubiquity:listeners": ["issue_comment.created", "issue_comment.edited", "issue_comment.deleted", "issues.opened", "issues.edited", "issues.deleted"] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,88 @@ | ||
import { SupabaseClient } from "@supabase/supabase-js"; | ||
import { SuperSupabase } from "./supabase"; | ||
import { Context } from "../../../types/context"; | ||
import { markdownToPlainText } from "../../utils/markdown-to-plaintext"; | ||
|
||
export interface IssueType { | ||
id: string; | ||
markdown?: string; | ||
author_id: number; | ||
created_at: string; | ||
modified_at: string; | ||
payloadObject: Record<string, unknown> | null; | ||
embedding: number[]; | ||
} | ||
|
||
export class Issues extends SuperSupabase { | ||
constructor(supabase: SupabaseClient, context: Context) { | ||
super(supabase, context); | ||
} | ||
|
||
async createIssue(issueNodeId: string, payload: Record<string, unknown> | null, isPrivate: boolean, markdown: string | null, authorId: number) { | ||
//First Check if the issue already exists | ||
const { data, error } = await this.supabase.from("issues").select("*").eq("id", issueNodeId); | ||
if (error) { | ||
this.context.logger.error("Error creating issue", error); | ||
return; | ||
} | ||
if (data && data.length > 0) { | ||
this.context.logger.info("Issue already exists"); | ||
return; | ||
} else { | ||
const embedding = await this.context.adapters.voyage.embedding.createEmbedding(markdown); | ||
let plaintext: string | null = markdownToPlainText(markdown || ""); | ||
if (isPrivate) { | ||
payload = null; | ||
markdown = null; | ||
plaintext = null; | ||
} | ||
const { error } = await this.supabase.from("issues").insert([{ id: issueNodeId, payload, markdown, plaintext, author_id: authorId, embedding }]); | ||
if (error) { | ||
this.context.logger.error("Error creating issue", error); | ||
return; | ||
} | ||
} | ||
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 | ||
const embedding = Array.from(await this.context.adapters.voyage.embedding.createEmbedding(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("issues") | ||
.update({ markdown, plaintext, embedding: embedding, payload, modified_at: new Date() }) | ||
.eq("id", issueNodeId); | ||
if (error) { | ||
this.context.logger.error("Error updating comment", error); | ||
} | ||
} | ||
|
||
async deleteIssue(issueNodeId: string) { | ||
const { error } = await this.supabase.from("issues").delete().eq("id", issueNodeId); | ||
if (error) { | ||
this.context.logger.error("Error deleting comment", error); | ||
} | ||
} | ||
|
||
async findSimilarIssues(markdown: string, threshold: number): Promise<IssueType[] | null> { | ||
const embedding = await this.context.adapters.voyage.embedding.createEmbedding(markdown); | ||
const { data, error } = await this.supabase | ||
.from("issues") | ||
.select("*") | ||
.eq("type", "issue") | ||
.textSearch("embedding", embedding.join(",")) | ||
.order("embedding", { foreignTable: "issues", ascending: false }) | ||
.lte("embedding", threshold); | ||
if (error) { | ||
this.context.logger.error("Error finding similar issues", error); | ||
return []; | ||
} | ||
return data; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
import markdownit from "markdown-it"; | ||
import plainTextPlugin from "markdown-it-plain-text"; | ||
|
||
/** | ||
* Converts a Markdown string to plain text. | ||
* @param markdown | ||
* @returns | ||
*/ | ||
export function markdownToPlainText(markdown: string | null): string | null { | ||
if (!markdown) { | ||
return markdown; | ||
} | ||
const md = markdownit(); | ||
md.use(plainTextPlugin); | ||
md.render(markdown); | ||
//Package markdown-it-plain-text does not have types | ||
return (md as any).plainText; | ||
} |
Oops, something went wrong.