Bug (commitling) Parse JSON blocks from return response (#297)
This commit is contained in:
@@ -61,6 +61,10 @@ export const configureCommitlintIntegration = async (force = false) => {
|
|||||||
|
|
||||||
// Cleanup the consistency answer. Sometimes 'gpt-3.5-turbo' sends rule's back.
|
// Cleanup the consistency answer. Sometimes 'gpt-3.5-turbo' sends rule's back.
|
||||||
prompts.forEach((prompt) => (consistency = consistency.replace(prompt, '')));
|
prompts.forEach((prompt) => (consistency = consistency.replace(prompt, '')));
|
||||||
|
|
||||||
|
// sometimes consistency is preceded by explanatory text like "Here is your JSON:"
|
||||||
|
consistency = utils.getJSONBlock(consistency);
|
||||||
|
|
||||||
// ... remaining might be extra set of "\n"
|
// ... remaining might be extra set of "\n"
|
||||||
consistency = utils.removeDoubleNewlines(consistency);
|
consistency = utils.removeDoubleNewlines(consistency);
|
||||||
|
|
||||||
|
|||||||
@@ -16,6 +16,16 @@ export const removeDoubleNewlines = (input: string): string => {
|
|||||||
return input;
|
return input;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
export const getJSONBlock = (input: string): string => {
|
||||||
|
const jsonIndex = input.search('```json');
|
||||||
|
if(jsonIndex > -1) {
|
||||||
|
input = input.slice(jsonIndex + 8);
|
||||||
|
const endJsonIndex = consistency.search('```');
|
||||||
|
input = input.slice(0, endJsonIndex);
|
||||||
|
}
|
||||||
|
return input;
|
||||||
|
};
|
||||||
|
|
||||||
export const commitlintLLMConfigExists = async (): Promise<boolean> => {
|
export const commitlintLLMConfigExists = async (): Promise<boolean> => {
|
||||||
let exists;
|
let exists;
|
||||||
try {
|
try {
|
||||||
@@ -44,4 +54,4 @@ export const getCommitlintLLMConfig =
|
|||||||
content.toString()
|
content.toString()
|
||||||
) as CommitlintLLMConfig;
|
) as CommitlintLLMConfig;
|
||||||
return commitLintLLMConfig;
|
return commitLintLLMConfig;
|
||||||
};
|
};
|
||||||
|
|||||||
Reference in New Issue
Block a user