Skip to content

Commit

Permalink
First Release AI action draft
Browse files Browse the repository at this point in the history
  • Loading branch information
Vishalk91-4 committed Dec 24, 2023
1 parent 1965ebe commit ec55e0d
Show file tree
Hide file tree
Showing 7 changed files with 324 additions and 1 deletion.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
# dependencies
/node_modules
11 changes: 10 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1 +1,10 @@
# Festive-Greeting
# Festive-Greeting

## Example usage

```yaml
uses: Vishalk91-4/Festive-Greeting
with:
prompt: 'Vishal is a dear friend of mine, Diwali'
api-key: ${{ secrets.AI_API_KEY }}
endpoint: ${{ secrets.AI_ENDPOINT }}
Binary file added README.pdf
Binary file not shown.
21 changes: 21 additions & 0 deletions action.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
name: 'Festive Greetings'
description: 'Generate Festival greetings with OpenAI'
inputs:
prompt: # id of input
description: 'Let the AI know who the message is for and provide context about the person.'
required: true
default: 'Vishal is a friend of mine'
api-key:
description: 'The API key for the OpenAI API'
required: true
default: '0123456789'
endpoint:
description: 'Your endpoint for the Azure OpenAI API'
required: true
default: ''
outputs:
seasons-greeting: # id of output
description: 'The AI generated Festival greeting'
runs:
using: 'node20'
main: 'index.js'
46 changes: 46 additions & 0 deletions index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
const core = require('@actions/core');
const github = require('@actions/github');
const httpm = require('@actions/http-client');

async function makePostRequest() {
const prompt = core.getInput('prompt');
const apikey = core.getInput('api-key');
const endpoint = core.getInput('endpoint');

let http = new httpm.HttpClient('http-client');
let data = {
messages: [
{ role: 'system', content: 'You generate short Festival greeting. The message should be 160 characters or less to fit into an SMS. The user will tell you who the message is for and will provide more context if needed. You will only answer with the text for the sms, nothing else.' },
{ role: 'user', content: 'Mother, haven\'t seen her for a long time, Birthday' },
{ role: 'assistant', content: 'Merry Birthday Mum! I miss you! 🎂 ' },
{ role: 'user', content: 'Laura, is a colleague of mine, Christmas' },
{ role: 'assistant', content: 'Have a great Holiday Season Laura! Thanks for the great partnership this year. 🎁✨' },
{ role: 'user', content: prompt }
],
max_tokens: 800,
temperature: 0.7,
frequency_penalty: 0,
presence_penalty: 0,
top_p: 0.95,
stop: null
};
let headers = {
'Content-Type': 'application/json',
'api-key': apikey
};

let res = await http.postJson(endpoint, data, headers);
return res.result;
}

try {
makePostRequest().then(response => {
let message = response.choices[0].message.content;
console.log(message);
core.setOutput("seasons-greeting", message);
}).catch(error => {
core.setFailed(error.message);
});
} catch (error) {
core.setFailed(error.message);
}
228 changes: 228 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

17 changes: 17 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
{
"name": "festive-greeting",
"version": "1.0.0",
"description": "",
"main": "index.js",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
},
"keywords": [],
"author": "",
"license": "ISC",
"dependencies": {
"@actions/core": "^1.10.1",
"@actions/github": "^6.0.0",
"@actions/http-client": "^2.2.0"
}
}

0 comments on commit ec55e0d

Please sign in to comment.