Skip to content

Commit

Permalink
scripting for preparing context
Browse files Browse the repository at this point in the history
  • Loading branch information
wtrocki committed Feb 21, 2025
1 parent c3707e7 commit 9a56822
Show file tree
Hide file tree
Showing 11 changed files with 55,839 additions and 0 deletions.
67 changes: 67 additions & 0 deletions .github/workflows/update-sdk-example.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
name: Update SDK Example

on:
push:
branches:
- copilot
paths:
- 'context/changelog.json'
- '.github/workflows/update-sdk-example.yml'
workflow_dispatch: # Allows manual triggering

jobs:
update-example:
runs-on: ubuntu-latest
permissions:
contents: write
pull-requests: write

steps:
- uses: actions/checkout@v3

- name: Setup Node.js
uses: actions/setup-node@v3
with:
node-version: '18'

- name: update-example Update SDK example
run: |
// call chat.js to update the SDK example
node chat.js
env:
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}

- name: Format code
run: |
go install golang.org/x/tools/cmd/goimports@latest
goimports -w golang/sdk-example.go
- name: Create Pull Request
run: |
git config --global user.name 'GitHub Action'
git config --global user.email '[email protected]'
BRANCH_NAME="automated-sdk-example-update-$(date +%s)"
git checkout -b $BRANCH_NAME
if ! git diff --quiet; then
git add golang/sdk-example.go
git commit -m "chore: Update SDK example based on changelog changes
Automated update by GitHub Copilot based on changelog.json changes"
git push origin $BRANCH_NAME
gh pr create \
--title "chore: Update SDK example based on changelog changes" \
--body "This PR was automatically created using GitHub Copilot to update the SDK example based on changelog.json changes." \
--base main \
--head $BRANCH_NAME
else
echo "No changes to commit"
fi
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

- name: Handle Failure
if: failure()
run: |
echo "::error::Failed to update SDK example. Please check the logs for details."
4 changes: 4 additions & 0 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
{
"java.configuration.updateBuildConfiguration": "interactive",
"java.compile.nullAnalysis.mode": "automatic"
}
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);
});
Loading

0 comments on commit 9a56822

Please sign in to comment.