Skip to content

Commit

Permalink
fix: prompt
Browse files Browse the repository at this point in the history
  • Loading branch information
wtrocki committed Feb 20, 2025
1 parent 9e1ce11 commit 7ff5cfb
Show file tree
Hide file tree
Showing 3 changed files with 66 additions and 19 deletions.
22 changes: 3 additions & 19 deletions .github/workflows/update-sdk-example.yml
Original file line number Diff line number Diff line change
Expand Up @@ -24,26 +24,10 @@ jobs:
with:
node-version: '18'

- name: Install Copilot CLI
- name: update-example Update SDK example
run: |
gh extension install github/gh-copilot
env:
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}

- name: Create Copilot prompt
run: |
cat << EOF > prompt.txt
Context: openapi.yaml file represents MongoDB Atlas OpenAPI. sdk-example.go is the file I want to edit. changelog.json contains new changes to the attached OpenAPI.yaml
SDK uses OpenAPI tag and operationId fields to build SDK methods.
Action: Act as software agent that for provided SDK example extending it by providing sdk method calls from changelog.json path
EOF
- name: Use GitHub Copilot to update SDK example
run: |
gh copilot suggest --prompt-file prompt.txt --file golang/sdk-example.go > golang/sdk-example.go.new
mv golang/sdk-example.go.new golang/sdk-example.go
// call chat.js to update the SDK example
node chat.js
env:
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}

Expand Down
62 changes: 62 additions & 0 deletions chat.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
import OpenAI from "openai";
import { promises as fs } from 'fs';
import path from 'path';

const token = process.env["GITHUB_TOKEN"];
const endpoint = "https://models.inference.ai.azure.com";
const modelName = "o3-mini";

async function readFiles() {
const files = ['context/openapi.yaml', 'golang/sdk-example.go', 'context/changelog.json'];
const fileContents = {};

for (const file of files) {
try {
const content = await fs.readFile(path.join(process.cwd(), file), 'utf8');
fileContents[file] = content;
} catch (error) {
console.error(`Error reading ${file}:`, error);
fileContents[file] = `Error: Could not read ${file}`;
}
}
return fileContents;
}

export async function main() {
const fileContents = await readFiles();

const enhancedPrompt = `Context: openapi.yaml file represents MongoDB Atlas OpenAPI.
sdk-example.go is the file I want to edit.
changelog.json contains new changes to the attached OpenAPI.yaml
SDK uses OpenAPI tag and operationId fields to build SDK methods.
File contents:
openapi.yaml:
${fileContents['openapi.yaml']}
sdk-example.go:
${fileContents['sdk-example.go']}
changelog.json:
${fileContents['changelog.json']}
Action: Act as software agent that for provided SDK example extending it by providing sdk method calls from changelog.json path`;

const client = new OpenAI({ baseURL: endpoint, apiKey: token });

const response = await client.chat.completions.create({
messages: [
{ role: "developer", content: "You are a helpful assistant." },
{ role: "user", content: enhancedPrompt }
],
model: modelName
});

console.log(response.choices[0].message.content);
}

main().catch((err) => {
console.error("The sample encountered an error:", err);
});
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
"description": "This repository demonstrates how to call the [MongoDB Atlas Administration API](https://www.mongodb.com/docs/atlas/api/) using Service Account authentication. You can read the accompanying article ['Calling the MongoDB Atlas Admin API - How to do it from Node, Python, and Golang'](https://www.mongodb.com/developer/how-to/nodejs-python-ruby-atlas-api/) for more information.",
"main": "index.js",
"scripts": {
"openai": "latest",
"ai-context": "repomix",
"ai-openapi": "wget https://raw.githubusercontent.com/mongodb/openapi/refs/heads/main/openapi/v2/openapi-2025-02-19.yaml",
"ai-changelog": "wget https://github.com/mongodb/openapi/blob/main/changelog/version-diff/2024-11-13_2025-02-19.json"
Expand Down

0 comments on commit 7ff5cfb

Please sign in to comment.