Skip to content

Commit

Permalink
fix: type rename and add tsx
Browse files Browse the repository at this point in the history
  • Loading branch information
sshivaditya committed Oct 17, 2024
1 parent a55fb00 commit 0f00dd4
Show file tree
Hide file tree
Showing 14 changed files with 182 additions and 70 deletions.
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@
"npm-run-all": "4.1.5",
"prettier": "3.3.2",
"ts-jest": "29.1.5",
"tsx": "4.15.6",
"typescript": "5.4.5",
"typescript-eslint": "7.13.1",
"wrangler": "3.60.3"
Expand Down
39 changes: 0 additions & 39 deletions src/adapters/openai/helpers/completions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -77,43 +77,4 @@ export class Completions extends SuperOpenAi {
}
return { answer: "", tokenUsage: { input: 0, output: 0, total: 0 } };
}

async contextCompressionCalls(context: string[]): Promise<CompletionsType> {
const res: OpenAI.Chat.Completions.ChatCompletion = await this.client.chat.completions.create({
model: "mistralai/mistral-nemo",
messages: [
{
role: "system",
content: [
{
type: "text",
text: "You are a LLM responsible for compression the context for better processing, do not leave anything out",
},
],
},
{
role: "user",
content: [
{
type: "text",
text: context.join("\n"),
},
],
},
],
temperature: 0.2,
max_tokens: 300,
top_p: 1,
frequency_penalty: 0,
presence_penalty: 0,
response_format: {
type: "text",
},
});
const answer = res.choices[0].message;
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 } };
}
return { answer: "", tokenUsage: { input: 0, output: 0, total: 0 } };
}
}
File renamed without changes.
4 changes: 2 additions & 2 deletions src/handlers/comments.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { splitKey } from "../helpers/issue";
import { LinkedIssues, SimplifiedComment } from "../types/github";
import { StreamlinedComment } from "../types/gpt";
import { LinkedIssues, SimplifiedComment } from "../types/github-types";
import { StreamlinedComment } from "../types/llm";

/**
* Get all streamlined comments from linked issues
Expand Down
2 changes: 1 addition & 1 deletion src/helpers/format-chat-history.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { Context } from "../types";
import { StreamlinedComment, StreamlinedComments } from "../types/gpt";
import { StreamlinedComment, StreamlinedComments } from "../types/llm";
import { createKey, streamlineComments } from "../handlers/comments";
import { fetchPullRequestDiff, fetchIssue, fetchIssueComments } from "./issue-fetching";
import { splitKey } from "./issue";
Expand Down
6 changes: 3 additions & 3 deletions src/helpers/issue-fetching.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import { createKey, getAllStreamlinedComments } from "../handlers/comments";
import { Context } from "../types";
import { IssueWithUser, SimplifiedComment, User } from "../types/github";
import { FetchParams, Issue, Comments, LinkedIssues } from "../types/github";
import { StreamlinedComment } from "../types/gpt";
import { IssueWithUser, SimplifiedComment, User } from "../types/github-types";
import { FetchParams, Issue, Comments, LinkedIssues } from "../types/github-types";
import { StreamlinedComment } from "../types/llm";
import {
dedupeStreamlinedComments,
fetchCodeLinkedFromIssue,
Expand Down
4 changes: 2 additions & 2 deletions src/helpers/issue-handling.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { createKey } from "../handlers/comments";
import { FetchParams } from "../types/github";
import { StreamlinedComment } from "../types/gpt";
import { FetchParams } from "../types/github-types";
import { StreamlinedComment } from "../types/llm";
import { idIssueFromComment, mergeStreamlinedComments, splitKey } from "./issue";
import { fetchLinkedIssues, fetchIssue, fetchAndHandleIssue, mergeCommentsAndFetchSpec } from "./issue-fetching";

Expand Down
22 changes: 3 additions & 19 deletions src/helpers/issue.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { createKey } from "../handlers/comments";
import { FetchedCodes, FetchParams, LinkedIssues } from "../types/github";
import { StreamlinedComment } from "../types/gpt";
import { FetchedCodes, FetchParams, LinkedIssues } from "../types/github-types";
import { StreamlinedComment } from "../types/llm";
import { Context } from "../types/context"; // Import Context type

/**
Expand Down Expand Up @@ -66,22 +66,6 @@ export function idIssueFromComment(comment?: string | null): LinkedIssues[] | nu
response.push(createLinkedIssueOrPr(url));
});
}
// This section handles issue references using markdown format (e.g., #123)
// const hashMatch = comment?.match(/#(\d+)/g);
// if (hashMatch) {
// const owner = params?.context.payload.repository?.owner?.login || "";
// const repo = params?.context.payload.repository?.name || "";

// hashMatch.forEach((hash) => {
// const issueNumber = hash.replace("#", "");
// response.push({
// owner,
// repo,
// issueNumber: parseInt(issueNumber, 10),
// url: `https://github.com/${owner}/${repo}/issues/${issueNumber}`
// });
// });
// }

return response.length > 0 ? response : null;
}
Expand Down Expand Up @@ -246,7 +230,7 @@ export function optimizeContext(strings: string[]): string[] {
* @returns The content of the README file as a string.
*/
export async function pullReadmeFromRepoForIssue(params: FetchParams): Promise<string | undefined> {
let readme = undefined;
let readme;
try {
const response = await params.context.octokit.repos.getContent({
owner: params.context.payload.repository.owner?.login || params.context.payload.organization?.login || "",
Expand Down
2 changes: 1 addition & 1 deletion src/plugin.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { Octokit } from "@octokit/rest";
import { PluginInputs } from "./types";
import { Context } from "./types";
import { askQuestion } from "./handlers/ask-gpt";
import { askQuestion } from "./handlers/ask-llm";
import { addCommentToIssue } from "./handlers/add-comment";
import { LogLevel, LogReturn, Logs } from "@ubiquity-dao/ubiquibot-logger";
import { Env } from "./types/env";
Expand Down
2 changes: 1 addition & 1 deletion src/types/env.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ dotenv.config();
*/
export const envSchema = T.Object({
OPENAI_API_KEY: T.String(),
UBIQUITY_OS_APP_NAME: T.String(),
UBIQUITY_OS_APP_NAME: T.String({ default: "UbiquityOS" }),
VOYAGEAI_API_KEY: T.String(),
SUPABASE_URL: T.String(),
SUPABASE_KEY: T.String(),
Expand Down
File renamed without changes.
File renamed without changes.
2 changes: 1 addition & 1 deletion tests/main.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import { Context, SupportedEventsU } from "../src/types";
import { drop } from "@mswjs/data";
import issueTemplate from "./__mocks__/issue-template";
import repoTemplate from "./__mocks__/repo-template";
import { askQuestion } from "../src/handlers/ask-gpt";
import { askQuestion } from "../src/handlers/ask-llm";
import { runPlugin } from "../src/plugin";
import { TransformDecodeCheckError, Value } from "@sinclair/typebox/value";
import { envSchema } from "../src/types/env";
Expand Down
Loading

0 comments on commit 0f00dd4

Please sign in to comment.