diff --git a/.cspell.json b/.cspell.json index 65d0f95..06b57b6 100644 --- a/.cspell.json +++ b/.cspell.json @@ -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"], diff --git a/src/adapters/openai/helpers/completions.ts b/src/adapters/openai/helpers/completions.ts index 52299e8..dfd2bcb 100644 --- a/src/adapters/openai/helpers/completions.ts +++ b/src/adapters/openai/helpers/completions.ts @@ -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({ diff --git a/src/handlers/ask-llm.ts b/src/handlers/ask-llm.ts index c487420..0a48f46 100644 --- a/src/handlers/ask-llm.ts +++ b/src/handlers/ask-llm.ts @@ -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); } diff --git a/src/types/llm.ts b/src/types/llm.ts index f05e985..7d5bedf 100644 --- a/src/types/llm.ts +++ b/src/types/llm.ts @@ -51,3 +51,10 @@ export type StreamlinedComments = { org: string; comments: StreamlinedComment[]; }; + +export type TokenLimits = { + modelMaxTokenLimit: number; + maxCompletionTokens: number; + runningTokenCount: number; + tokensRemaining: number; +}; diff --git a/tests/__mocks__/handlers.ts b/tests/__mocks__/handlers.ts index be7ba62..2c2141b 100644 --- a/tests/__mocks__/handlers.ts +++ b/tests/__mocks__/handlers.ts @@ -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", @@ -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, + }, + ]) + ), ]; diff --git a/tests/main.test.ts b/tests/main.test.ts index 5f67bd9..64c1063 100644 --- a/tests/main.test.ts +++ b/tests/main.test.ts @@ -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(); }); @@ -388,6 +405,12 @@ function createContext(body = TEST_SLASH_COMMAND) { }, openai: { completions: { + getModelMaxTokenLimit: () => { + return 50000; + }, + getModelMaxOutputLimit: () => { + return 50000; + }, createCompletion: async (): Promise => { return { answer: MOCK_ANSWER,