Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: Structured Comment Exploration #35

Open
wants to merge 4 commits into
base: development
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
"knip-ci": "knip --no-exit-code --reporter json --config .github/knip.ts",
"prepare": "husky install",
"test": "jest --setupFiles dotenv/config --coverage",
"worker": "wrangler dev --env dev --port 4000"
"worker": "wrangler dev --env dev --port 5000"
},
"keywords": [
"typescript",
Expand Down
10 changes: 10 additions & 0 deletions src/adapters/openai/helpers/completions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,11 @@ export class Completions extends SuperOpenAi {
},
});

if (!res.choices || !res.choices[0].message) {
logger.error(`Failed to generate completion: ${JSON.stringify(res)}`);
return { answer: "", tokenUsage: { input: 0, output: 0, total: 0 }, groundTruths };
}

const answer = res.choices[0].message;
if (answer && answer.content && res.usage) {
return {
Expand Down Expand Up @@ -161,6 +166,11 @@ export class Completions extends SuperOpenAi {
model: model,
});

if (!res.choices || !res.choices[0].message || !res.choices[0].message.content) {
this.context.logger.error(`Failed to generate ground truth completion: ${JSON.stringify(res)}`);
return null;
}

return res.choices[0].message.content;
}

Expand Down
10 changes: 8 additions & 2 deletions src/handlers/ask-llm.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,13 +15,15 @@ export async function askQuestion(context: Context, question: string) {
// using any links in comments or issue/pr bodies to fetch more context
const { specAndBodies, streamlinedComments } = await recursivelyFetchLinkedIssues({
context,
maxDepth: 2,
owner: context.payload.repository.owner.login,
repo: context.payload.repository.name,
issueNum: context.payload.issue.number,
});
// build a nicely structure system message containing a streamlined chat history
// includes the current issue, any linked issues, and any linked PRs
const formattedChat = await formatChatHistory(context, streamlinedComments, specAndBodies);
logger.info(`${formattedChat.join("")}`);
const formattedChat = await formatChatHistory(context, streamlinedComments, specAndBodies, 2);
logger.info("Formatted chat history " + formattedChat.join("\n"));
return await askLlm(context, question, formattedChat);
}

Expand All @@ -36,6 +38,7 @@ export async function askLlm(context: Context, question: string, formattedChat:
},
} = context;

context.logger.info("Asking LLM question: " + question);
try {
// using db functions to find similar comments and issues
const [similarComments, similarIssues] = await Promise.all([
Expand All @@ -49,6 +52,8 @@ export async function askLlm(context: Context, question: string, formattedChat:
...(similarIssues?.map((issue: IssueSimilaritySearchResult) => issue.issue_plaintext) || []),
];

context.logger.info("Similar text: " + similarText.join("\n"));

// filter out any empty strings
formattedChat = formattedChat.filter((text) => text);

Expand All @@ -57,6 +62,7 @@ export async function askLlm(context: Context, question: string, formattedChat:
// gather structural data about the payload repository
const [languages, { dependencies, devDependencies }] = await Promise.all([fetchRepoLanguageStats(context), fetchRepoDependencies(context)]);

context.logger.info("Languages: " + languages.join(", "));
let groundTruths: string[] = [];

if (!languages.length) {
Expand Down
Loading