Skip to content

Commit

Permalink
feat: add repo URL parameter to content processing functions
Browse files Browse the repository at this point in the history
  • Loading branch information
0x4007 committed Oct 18, 2024
1 parent 63817f7 commit 3f572e9
Show file tree
Hide file tree
Showing 4 changed files with 30 additions and 20 deletions.
4 changes: 2 additions & 2 deletions src/sync-configs/get-modified-content.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,10 @@ if (!ANTHROPIC_API_KEY) {
process.exit(1);
}

export async function getModifiedContent(originalContent: string, instruction: string, parserCode: string): Promise<string> {
export async function getModifiedContent(originalContent: string, instruction: string, parserCode: string, repoUrl: string): Promise<string> {
const pluginUrls = parsePluginUrls(originalContent);
const manifests = await fetchManifests(pluginUrls);
const prompt = await renderPrompt(originalContent, parserCode, JSON.stringify(manifests));
const prompt = await renderPrompt(originalContent, parserCode, JSON.stringify(manifests), repoUrl);

const anthropic = new Anthropic({
apiKey: ANTHROPIC_API_KEY,
Expand Down
2 changes: 1 addition & 1 deletion src/sync-configs/process-repository.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ export async function processRepository(repo: Repo, instruction: string, parserC
}
const fileContent = fs.readFileSync(filePath, "utf8");

const modifiedContent = await getModifiedContent(fileContent, instruction, parserCode);
const modifiedContent = await getModifiedContent(fileContent, instruction, parserCode, repo.url);

const tempFilePath = `${filePath}.modified`;
fs.writeFileSync(tempFilePath, modifiedContent, "utf8");
Expand Down
36 changes: 23 additions & 13 deletions src/sync-configs/render-prompt.ts
Original file line number Diff line number Diff line change
@@ -1,35 +1,45 @@
export async function renderPrompt(originalContent: string, parserCode: string, manifests: string): Promise<string> {
export async function renderPrompt(originalContent: string, parserCode: string, manifests: string, repoUrl: string): Promise<string> {
// eslint-disable-next-line sonarjs/prefer-immediate-return
const prompt = [
`
- You are to act as a YAML configuration editor.
- Your goal is to modify the provided YAML file according to the user's instructions while ensuring that the syntax remains valid and no necessary formatting is lost.
- Be especially careful with list indicators (like hyphens) and ensure they are preserved appropriately.
- **Important:** Do **not** remove any hyphens (\`-\`) that indicate items in a list (e.g., plugins). These hyphens are critical for YAML syntax and must be retained.
- Additionally, correct any syntax errors present in the original YAML file.
`As a YAML configuration editor, modify the following YAML file according to the user's instructions, ensuring valid syntax and preserving formatting. Pay special attention to list indicators (hyphens \`-\`); ensure they are retained and not removed, especially for list items like plugins. Correct any syntax errors in the original YAML.
- **Do not alter any URLs in the configuration file. Assume that all URLs provided are correct and must remain unchanged unless the user specifically requests a modification to URLs otherwise.**
- Here is the original YAML configuration file:`,
**Do not alter any URLs in the configuration unless explicitly instructed.**
Here is the original YAML configuration file for ${repoUrl}:`,

originalContent,

`Provide the modified YAML file without any additional explanation or extraneous characters. Do not include any headers, footers, code block markers (like triple backticks), or language identifiers (like 'yaml'). **Only output the modified YAML content.**
`Provide only the modified YAML content without any additional explanation, headers, footers, code block markers, or language identifiers.
**Example of correct plugin formatting:**
- uses:
- plugin: ubiquibot/issue-comment-embeddings@main
Ensure that the hyphens before each plugin are retained as shown above. **Remember, do not change any URLs in the configuration.** and do not remove comments intended for human readers; only remove commented-out YAML code. Finally, for additional context, here is the source code of the yml configuration parser for your reference:`,
Ensure the hyphens before each plugin are retained as shown above.
Remember:
• Do not change any URLs unless instructed.
• Keep all comments intended for human readers—including any URLs within them.
• Only remove commented-out YAML code. Do not remove or alter any other comments, notes, or URLs intended for documentation or human understanding.
**Example of a comment with a URL that should be preserved:**
# This is a comment with a URL that should be preserved: https://example.com/documentation
**Ensure all human-readable comments and their contents, especially URLs, are left unchanged unless explicit instructions are provided to modify them.**
For additional context, here is the source code of the YAML configuration parser:`,

parserCode,

`Lastly, here are the manifests for every plugin in the configuration file. Be sure to include a default value for any missing fields in the configuration file.`,
`Below are the manifests for the plugins in the configuration. Include default values for any missing fields.`,

manifests,
].join("\n\n===\n\n");

// console.trace(prompt);
console.trace(prompt);

return prompt;
}
8 changes: 4 additions & 4 deletions src/sync-configs/repositories.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
const CONFIG_FILE_PATH = ".github/.ubiquibot-config.yml";
const CONFIG_FILE_PATH = ".github/.ubiquity-os.config.yml";

export const repositories = [
{
Expand All @@ -11,7 +11,7 @@ export const repositories = [
{
type: "config",
localDir: "ubiquity",
url: "https://github.com/ubiquity/ubiquibot-config.git",
url: "https://github.com/ubiquity/ubiquity-os.config.git",
filePath: CONFIG_FILE_PATH,
},
// {
Expand All @@ -29,13 +29,13 @@ export const repositories = [
{
type: "config",
localDir: "ubiquity-os",
url: "https://github.com/ubiquity-os/ubiquibot-config.git",
url: "https://github.com/ubiquity-os/ubiquity-os.config.git",
filePath: CONFIG_FILE_PATH,
},
{
type: "config",
localDir: "ubiquity-os-marketplace",
url: "https://github.com/ubiquity-os-marketplace/ubiquibot-config.git",
url: "https://github.com/ubiquity-os-marketplace/ubiquity-os.config.git",
filePath: CONFIG_FILE_PATH,
},
];

0 comments on commit 3f572e9

Please sign in to comment.