Skip to content

Commit

Permalink
fix(#77) format to md
Browse files Browse the repository at this point in the history
  • Loading branch information
h1alexbel committed Apr 19, 2024
1 parent 432de92 commit 750bbad
Show file tree
Hide file tree
Showing 8 changed files with 175 additions and 67 deletions.
8 changes: 4 additions & 4 deletions src/formatted-summary.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,18 +33,18 @@ export class FormattedSummary implements Scalar<string> {
* @param suggestions Suggestions
*/
constructor(
private readonly problems: Scalar<string>,
private readonly suggestions: Scalar<string>
private readonly problems: any,
private readonly suggestions: any
) {
}

value(): string {
return `
Problems:
${this.problems.value()}
${this.problems}
Suggestions:
${this.suggestions.value()}
${this.suggestions}
`;
}
}
36 changes: 13 additions & 23 deletions src/goals/top-goal.ts
Original file line number Diff line number Diff line change
Expand Up @@ -50,29 +50,19 @@ export class TopGoal implements Goal {
console.log(
`Running top goal`
);
const amount = JSON.parse(new MdUnbox(this.problems).value()).size;
let candidate;
if (amount > 3) {
console.log(
"Amount of problems is more than 3, capping problems..."
);
const top = await this.model.analyze(
new Default(),
new Top(this.problems, this.report)
);
console.log(
`Top problems:
const top = await this.model.analyze(
new Default(),
new Top(this.problems, this.report)
);
console.log(
`Top problems:
${top}`
);
candidate = await new NamedGoal(
"polish",
this.model,
new Default(),
new Polish(top)
).exec();
} else {
candidate = this.problems;
}
return candidate;
);
return await new NamedGoal(
"polish",
this.model,
new Default(),
new Polish(top)
).exec();
}
}
10 changes: 6 additions & 4 deletions src/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,11 +35,11 @@ import {QualityExpert} from "./prompts/quality-expert";
import {Analyze} from "./prompts/analyze";
import {Validate} from "./prompts/validate";
import {Default} from "./prompts/default";
import {JsonProblems} from "./prompts/json-problems";
import {MdProblems} from "./prompts/md-problems";
import {Top} from "./prompts/top";
import {Polish} from "./prompts/polish";
import {Suggestions} from "./prompts/suggestions";
import {SuggestionsJson} from "./prompts/suggestions-json";
import {MdSuggestions} from "./prompts/md-suggestions";
import {FormattedSummary} from "./formatted-summary";
import {MdObjects} from "./md-objects";
import {MdUnbox} from "./md-unbox";
Expand Down Expand Up @@ -190,8 +190,10 @@ async function run() {
).compose(report);
await new Feedback(
new FormattedSummary(
new MdObjects(JSON.parse(new MdUnbox(composed.problems).value()).problems),
new MdObjects(JSON.parse(new MdUnbox(composed.suggestions).value()).suggestions)
composed.problems,
composed.suggestions
// new MdObjects(JSON.parse(new MdUnbox(composed.problems).value()).problems),
// new MdObjects(JSON.parse(new MdUnbox(composed.suggestions).value()).suggestions)
),
octokit,
issue,
Expand Down
71 changes: 42 additions & 29 deletions src/models.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,12 +24,14 @@
import {TopGoal} from "./goals/top-goal";
import {NamedGoal} from "./goals/named-goal";
import {Default} from "./prompts/default";
import {JsonProblems} from "./prompts/json-problems";
import {MdProblems} from "./prompts/md-problems";
import {Validate} from "./prompts/validate";
import {QualityExpert} from "./prompts/quality-expert";
import {Analyze} from "./prompts/analyze";
import {SuggestionsJson} from "./prompts/suggestions-json";
import {MdSuggestions} from "./prompts/md-suggestions";
import {Suggestions} from "./prompts/suggestions";
import {Polish} from "./prompts/polish";
import {Top} from "./prompts/top";

/**
* Models.
Expand All @@ -48,49 +50,60 @@ export class Models {
}

async compose(report: string) {
const candidate = await new TopGoal(
const problems = await new NamedGoal(
"polish",
this.def,
report,
await new NamedGoal(
"json-validate",
this.def,
new Default(),
new JsonProblems(
await new NamedGoal(
"validate",
this.validator,
new Default(),
new Validate(
report,
await new NamedGoal(
"analyze",
this.def,
new QualityExpert(),
new Analyze(report)
).exec()
)
).exec()
new Default(),
new Polish(
await new NamedGoal(
"top",
this.def,
new Default(),
new Top(
await new NamedGoal(
"validated.md",
this.def,
new Default(),
new MdProblems(
await new NamedGoal(
"validate",
this.validator,
new Default(),
new Validate(
report,
await new NamedGoal(
"analyze",
this.def,
new QualityExpert(),
new Analyze(report)
).exec()
)
).exec()
)
),
report
)
)
).exec(),
).exec();
)
);
const suggestions = await new NamedGoal(
"json-suggestions",
"suggestions.md",
this.def,
new Default(),
new SuggestionsJson(
new MdSuggestions(
await new NamedGoal(
"suggestions",
this.def,
new Default(),
new Suggestions(
report,
candidate
problems
)
).exec()
)
).exec();
return {
problems: candidate,
problems: problems,
suggestions: suggestions
}
}
Expand Down
51 changes: 51 additions & 0 deletions src/prompts/md-problems.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
/*
* The MIT License (MIT)
*
* Copyright (c) 2023-2024 Tracehub.git
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included
* in all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*/

/**
* Format to JSON prompt.
*/
export class MdProblems implements Scalar<string> {

/**
* Ctor.
* @param problems Problems
*/
constructor(private readonly problems: any) {
}

value(): string {
return `
Please format these response to Markdown array format.
Each problem statement must be represented as a star(*) array member.
Please strictly adhere the provided example template.
Example:
* ...
* ...
* ...
Problems:
${this.problems}
`;
}
}
52 changes: 52 additions & 0 deletions src/prompts/md-suggestions.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
/*
* The MIT License (MIT)
*
* Copyright (c) 2023-2024 Tracehub.git
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included
* in all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*/

/**
* Prompt to format suggestions to JSON.
*/
export class MdSuggestions implements Scalar<string> {

/**
* Ctor.
* @param suggestions Suggestions
*/
constructor(private readonly suggestions: any) {
}

value(): string {
return `
Please combine provided suggestions text into logical array of suggestions and format these response to Markdown array format.
Each suggestion must be represented as an array member.
It's very important to split text into array members in a smart way using logic.
Please strictly adhere the provided example template.
Don't rephrase suggestions or generate any other info.
Example:
* ...
* ...
* ...
Suggestions:
${this.suggestions}
`;
}
}
10 changes: 5 additions & 5 deletions src/prompts/polish.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,22 +23,22 @@
*/

/**
* Prompt to polish JSON.
* Prompt to polish Markdown.
*/
export class Polish implements Scalar<string> {

/**
* Ctor.
* @param origin JSON to polish
* @param origin Response to polish
*/
constructor(private readonly origin: any) {
}

value(): string {
return `
Please polish this JSON and return polished JSON.
Polished JSON problems node must have only text without any numbering or other formatting.
Response must contain only JSON without any extra text or info.
Please polish this text and return polished one.
Polished problems must be represented as markdown star(*) array.
Response must contain only markdown star(*) array without any extra text or info.
Don't rephrase problems or generate any other info.
Problems:
Expand Down
4 changes: 2 additions & 2 deletions src/prompts/top.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,9 @@ export class Top implements Scalar<string> {
value(): string {
return `
Take a look at these quality problems that were identified during analysis of the outlined bug report.
Now, please copy the most important problems into new array.
Now, please copy the most important problems into new response.
Max amount of problems must be 3.
Don't rephrase problems or generate any other info.
Don't rephrase problems or generate any other info.
Problems:
${this.problems}
Expand Down

0 comments on commit 750bbad

Please sign in to comment.