-
Notifications
You must be signed in to change notification settings - Fork 5
fix: parsing promptList text and breadcrumb #177
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
Merged
Merged
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 hidden or 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 hidden or 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,25 +1,49 @@ | ||||||
import { AlertConversation, Conversation } from "@/api/generated/types.gen"; | ||||||
import { MaliciousPkgType, TriggerType } from "@/types"; | ||||||
import { isToday, isYesterday } from "date-fns"; | ||||||
import { format, isToday, isYesterday } from "date-fns"; | ||||||
|
||||||
const ONE_DAY_MS = 24 * 60 * 60 * 1000; | ||||||
const SEVEN_DAYS_MS = 7 * ONE_DAY_MS; | ||||||
const TEEN_DAYS_MS = 14 * ONE_DAY_MS; | ||||||
const THTY_DAYS_MS = 30 * ONE_DAY_MS; | ||||||
const FILEPATH_REGEX = /(?:---FILEPATH|Path:|\/\/\s*filepath:)\s*([^\s]+)/g; | ||||||
const COMPARE_CODE_REGEX = /Compare this snippet[^:]*:/g; | ||||||
|
||||||
export function extractTitleFromMessage(message: string) { | ||||||
function parsingByKeys(text: string | undefined, timestamp: string) { | ||||||
const fallback = `Prompt ${format(new Date(timestamp ?? ""), "y/MM/dd - hh:mm:ss a")}`; | ||||||
try { | ||||||
if (!text) return fallback; | ||||||
const filePath = text.match(FILEPATH_REGEX); | ||||||
const compareCode = text.match(COMPARE_CODE_REGEX); | ||||||
// there some edge cases in copilot where the prompts are not correctly parsed. In this case is better to show the filepath | ||||||
if (compareCode || filePath) { | ||||||
if (filePath) | ||||||
return `Prompt on file${filePath[0]?.trim().toLocaleLowerCase()}`; | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. |
||||||
|
||||||
if (compareCode) | ||||||
return `Prompt from snippet ${compareCode[0]?.trim().toLocaleLowerCase()}`; | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||
} | ||||||
|
||||||
return text.trim(); | ||||||
} catch { | ||||||
return fallback; | ||||||
} | ||||||
} | ||||||
|
||||||
export function parsingPromptText(message: string, timestamp: string) { | ||||||
try { | ||||||
// checking malformed markdown code blocks | ||||||
const regex = /^(.*)```[\s\S]*?```(.*)$/s; | ||||||
const match = message.match(regex); | ||||||
|
||||||
if (match !== null && match !== undefined) { | ||||||
const beforeMarkdown = match[1]?.trim(); | ||||||
const afterMarkdown = match[2]?.trim(); | ||||||
const title = beforeMarkdown || afterMarkdown; | ||||||
return title; | ||||||
return parsingByKeys(title, timestamp); | ||||||
} | ||||||
|
||||||
return message.trim(); | ||||||
return parsingByKeys(message, timestamp); | ||||||
} catch { | ||||||
return message.trim(); | ||||||
} | ||||||
|
@@ -119,7 +143,9 @@ export function sanitizeQuestionPrompt({ | |||||
}) { | ||||||
try { | ||||||
// it shouldn't be possible to receive the prompt answer without a question | ||||||
if (!answer) return question; | ||||||
if (!answer) { | ||||||
throw new Error("Missing AI answer"); | ||||||
} | ||||||
|
||||||
// Check if 'answer' is truthy; if so, try to find and return the text after "Query:" | ||||||
const index = question.indexOf("Query:"); | ||||||
|
This file contains hidden or 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.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.