This repository has been archived by the owner on Sep 19, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 61
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* feat(deps): added openai added openAI * feat: added ask command Simple prompt engineering, one response per user per question. * fix: update prompt better initial prompt * fix: update system prompt update prompt * feat: simple memory original context indexable across repos, issues and pull requests * fix: comments comments etc * fix: streamlined context waiting for more input * chore: pulling context pulls from sources using the hashtag in issue body * chore: tokenization total token usage now displayed * chore: diff comparison feed gpt the spec and diff for it to analyze * fix: ci and spec check will only spec check once now fixed tsc issues * fix: merge mistake sort import * fix: key from config allow it to be set in org and repo config * fix: set ask to false reset default * fix(deps): langchain unused dep * fix: apikey undefined no longer undefined * fix: using token limit set to 8k in config 4k by default * chore: improve ask command improved pr-review and context for both ask and pr-review commands * fix: gpt helpers moved base ask and context call into helpers * chore: use error diff replace text error with diff * fix: remove unused requested changes * fix: remove unused missed the shared default * fix: schema new types * fix: nullable and error start with a bang and clear api key error * fix: duplicated --------- Co-authored-by: 0xcodercrane <[email protected]>
- Loading branch information
1 parent
3966177
commit c40efc5
Showing
15 changed files
with
1,627 additions
and
1,110 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
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,4 +1,4 @@ | ||
export * from "./shared"; | ||
export * from "./strings"; | ||
export * from "./abis"; | ||
export * from "./ubiquibot-config-default"; | ||
export * from "./ubiquibot-config-default"; |
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 |
---|---|---|
@@ -0,0 +1,123 @@ | ||
import { getBotContext, getLogger } from "../../../bindings"; | ||
import { Payload, StreamlinedComment, UserType } from "../../../types"; | ||
import { getAllIssueComments, getAllLinkedIssuesAndPullsInBody } from "../../../helpers"; | ||
import { CreateChatCompletionRequestMessage } from "openai/resources/chat"; | ||
import { askGPT, decideContextGPT, sysMsg } from "../../../helpers/gpt"; | ||
import { ErrorDiff } from "../../../utils/helpers"; | ||
|
||
/** | ||
* @param body The question to ask | ||
*/ | ||
export const ask = async (body: string) => { | ||
const context = getBotContext(); | ||
const logger = getLogger(); | ||
|
||
const payload = context.payload as Payload; | ||
const sender = payload.sender.login; | ||
const issue = payload.issue; | ||
|
||
if (!body) { | ||
return `Please ask a question`; | ||
} | ||
|
||
if (!issue) { | ||
return `This command can only be used on issues`; | ||
} | ||
|
||
const chatHistory: CreateChatCompletionRequestMessage[] = []; | ||
const streamlined: StreamlinedComment[] = []; | ||
let linkedPRStreamlined: StreamlinedComment[] = []; | ||
let linkedIssueStreamlined: StreamlinedComment[] = []; | ||
|
||
const regex = /^\/ask\s(.+)$/; | ||
const matches = body.match(regex); | ||
|
||
if (matches) { | ||
const [, body] = matches; | ||
|
||
// standard comments | ||
const comments = await getAllIssueComments(issue.number); | ||
// raw so we can grab the <!--- { 'UbiquityAI': 'answer' } ---> tag | ||
const commentsRaw = await getAllIssueComments(issue.number, "raw"); | ||
|
||
if (!comments) { | ||
logger.info(`Error getting issue comments`); | ||
return ErrorDiff(`Error getting issue comments`); | ||
} | ||
|
||
// add the first comment of the issue/pull request | ||
streamlined.push({ | ||
login: issue.user.login, | ||
body: issue.body, | ||
}); | ||
|
||
// add the rest | ||
comments.forEach(async (comment, i) => { | ||
if (comment.user.type == UserType.User || commentsRaw[i].body.includes("<!--- { 'UbiquityAI': 'answer' } --->")) { | ||
streamlined.push({ | ||
login: comment.user.login, | ||
body: comment.body, | ||
}); | ||
} | ||
}); | ||
|
||
// returns the conversational context from all linked issues and prs | ||
const links = await getAllLinkedIssuesAndPullsInBody(issue.number); | ||
|
||
if (typeof links === "string") { | ||
logger.info(`Error getting linked issues or prs: ${links}`); | ||
} else { | ||
linkedIssueStreamlined = links.linkedIssues; | ||
linkedPRStreamlined = links.linkedPrs; | ||
} | ||
|
||
// let chatgpt deduce what is the most relevant context | ||
const gptDecidedContext = await decideContextGPT(chatHistory, streamlined, linkedPRStreamlined, linkedIssueStreamlined); | ||
|
||
if (linkedIssueStreamlined.length == 0 && linkedPRStreamlined.length == 0) { | ||
// No external context to add | ||
chatHistory.push( | ||
{ | ||
role: "system", | ||
content: sysMsg, | ||
name: "UbiquityAI", | ||
} as CreateChatCompletionRequestMessage, | ||
{ | ||
role: "user", | ||
content: body, | ||
name: sender, | ||
} as CreateChatCompletionRequestMessage | ||
); | ||
} else { | ||
chatHistory.push( | ||
{ | ||
role: "system", | ||
content: sysMsg, // provide the answer template | ||
name: "UbiquityAI", | ||
} as CreateChatCompletionRequestMessage, | ||
{ | ||
role: "system", | ||
content: "Original Context: " + JSON.stringify(gptDecidedContext), // provide the context | ||
name: "system", | ||
} as CreateChatCompletionRequestMessage, | ||
{ | ||
role: "user", | ||
content: "Question: " + JSON.stringify(body), // provide the question | ||
name: "user", | ||
} as CreateChatCompletionRequestMessage | ||
); | ||
} | ||
|
||
const gptResponse = await askGPT(body, chatHistory); | ||
|
||
if (typeof gptResponse === "string") { | ||
return gptResponse; | ||
} else if (gptResponse.answer) { | ||
return gptResponse.answer; | ||
} else { | ||
return ErrorDiff(`Error getting response from GPT`); | ||
} | ||
} else { | ||
return "Invalid syntax for ask \n usage: '/ask What is pi?"; | ||
} | ||
}; |
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
Oops, something went wrong.