Skip to content

Commit

Permalink
chore: type, tests, cspell
Browse files Browse the repository at this point in the history
  • Loading branch information
Keyrxng committed Oct 31, 2024
1 parent 97868df commit 398e993
Show file tree
Hide file tree
Showing 6 changed files with 53 additions and 6 deletions.
6 changes: 5 additions & 1 deletion .cspell.json
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,11 @@
"Typeguard",
"typeguards",
"OPENROUTER_API_KEY",
"Openrouter"
"Openrouter",
"flac",
"dylib",
"mobileprovision",
"icns"
],
"dictionaries": ["typescript", "node", "software-terms"],
"import": ["@cspell/dict-typescript/cspell-ext.json", "@cspell/dict-node/cspell-ext.json", "@cspell/dict-software-terms"],
Expand Down
2 changes: 1 addition & 1 deletion src/adapters/openai/helpers/completions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ export class Completions extends SuperOpenAi {
additionalContext.join("\n"),
].join("\n");

logger.info(`System message: ${sysMsg}`);
// logger.info(`System message: ${sysMsg}`);
logger.info(`Query: ${query}`);

const res: OpenAI.Chat.Completions.ChatCompletion = await this.client.chat.completions.create({
Expand Down
2 changes: 1 addition & 1 deletion src/handlers/ask-llm.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ export async function askQuestion(context: Context, question: string) {
repo: context.payload.repository.name,
});
const formattedChat = await formatChatHistory(context, streamlinedComments, specAndBodies);
logger.info(`${formattedChat.join("")}`);
// logger.info(`${formattedChat.join("")}`);
return await askLlm(context, question, formattedChat);
}

Expand Down
7 changes: 7 additions & 0 deletions src/types/llm.ts
Original file line number Diff line number Diff line change
Expand Up @@ -51,3 +51,10 @@ export type StreamlinedComments = {
org: string;
comments: StreamlinedComment[];
};

export type TokenLimits = {
modelMaxTokenLimit: number;
maxCompletionTokens: number;
runningTokenCount: number;
tokensRemaining: number;
};
19 changes: 16 additions & 3 deletions tests/__mocks__/handlers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -85,9 +85,7 @@ export const handlers = [
db.pull.findFirst({ where: { owner: { equals: owner as string }, repo: { equals: repo as string }, number: { equals: Number(pullNumber) } } })
)
),
http.get("https://api.github.com/repos/:owner/:repo/languages", ({ params: { owner, repo } }) =>
HttpResponse.json(db.repo.findFirst({ where: { owner: { login: { equals: owner as string } }, name: { equals: repo as string } } }))
),
http.get("https://api.github.com/repos/:owner/:repo/languages", () => HttpResponse.json(["JavaScript", "TypeScript", "Python"])),
http.get("https://api.github.com/repos/:owner/:repo/contents/:path", () =>
HttpResponse.json({
type: "file",
Expand All @@ -97,4 +95,19 @@ export const handlers = [
content: Buffer.from(JSON.stringify({ content: "This is a mock README file" })).toString("base64"),
})
),
// [MSW] Warning: intercepted a request without a matching request handler:

// • GET https://api.github.com/repos/ubiquity/test-repo/pulls/3/files?per_page=100?per_page=100
http.get("https://api.github.com/repos/:owner/:repo/pulls/:pull_number/files", () =>
HttpResponse.json([
{
sha: "abc123",
filename: "file1.txt",
status: "modified",
additions: 10,
deletions: 5,
changes: 15,
},
])
),
];
23 changes: 23 additions & 0 deletions tests/main.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,23 @@ type Comment = {
const octokit = jest.requireActual("@octokit/rest");
jest.requireActual("openai");

// extractDependencies

jest.mock("../src/handlers/ground-truths/chat-bot", () => {
return {
fetchRepoDependencies: jest.fn().mockReturnValue({
dependencies: {},
devDependencies: {},
}),
extractDependencies: jest.fn(),
// [string, number][]
fetchRepoLanguageStats: jest.fn().mockReturnValue([
["JavaScript", 100],
["TypeScript", 200],
]),
};
});

beforeAll(() => {
server.listen();
});
Expand Down Expand Up @@ -388,6 +405,12 @@ function createContext(body = TEST_SLASH_COMMAND) {
},
openai: {
completions: {
getModelMaxTokenLimit: () => {
return 50000;
},
getModelMaxOutputLimit: () => {
return 50000;
},
createCompletion: async (): Promise<CompletionsType> => {
return {
answer: MOCK_ANSWER,
Expand Down

0 comments on commit 398e993

Please sign in to comment.