-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
12 changed files
with
55,891 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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." |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
{ | ||
"java.configuration.updateBuildConfiguration": "interactive", | ||
"java.compile.nullAnalysis.mode": "automatic" | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
}); |
Oops, something went wrong.