Skip to content

Commit

Permalink
stuff
Browse files Browse the repository at this point in the history
  • Loading branch information
yigaldviri committed Dec 23, 2024
1 parent 8895516 commit f915ff9
Show file tree
Hide file tree
Showing 1,851 changed files with 305,970 additions and 19 deletions.
31 changes: 15 additions & 16 deletions ai-agent.js
Original file line number Diff line number Diff line change
@@ -1,16 +1,13 @@
import {
Configuration,
OpenAIApi,
} from 'openai';
const OpenAI = require('openai');

async function createFailureRhyme(apiKey, failureDescription, user) {
try {
const openai = new OpenAIApi(new Configuration({
apiKey,
}));
const openai = new OpenAI({
apiKey
});

const response = await openai.createChatCompletion(getChatCompletionRequest(failureDescription, user));
const rhyme = response.data.choices?.[0]?.message?.content
const response = await openai.chat.completions.create(getChatCompletionRequest(failureDescription, user));
const rhyme = response.choices?.[0]?.message?.content

return rhyme;
} catch (error) {
Expand All @@ -20,15 +17,17 @@ async function createFailureRhyme(apiKey, failureDescription, user) {
}

const getChatCompletionRequest = (failureDescription, user) => {

const prompt = `
You are a witted engineer and you need to create a rhyme about a failure that happened when running a GitHub Action on the current commit.
It has to be short and witted - no more then 4 lines. Dont insolt the engineer that caused it. Be funny.
The failtre is - ${failureDescription} and the user who casued it is - ${user}.`;

return {
model : "gpt-4o",
messages,
messages: [{
role: "system",
content: "You are a witty engineer who creates short, funny rhymes about GitHub Action failures."
}, {
role: "user",
content: `Create a witty rhyme (max 4 lines) about this GitHub Action failure. Be funny but don't insult the engineer.
Failure: ${failureDescription}
User: ${user}`
}],
max_tokens: 100,
n: 1,
stream: false,
Expand Down
10 changes: 8 additions & 2 deletions index.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
const core = require('@actions/core');
const github = require('@actions/github');
const aiAgent = require('./aiAgent');
const aiAgent = require('./ai-agent');

const failFailed = (err = `It's sad, so sad. It's a sad, sad situation 🎶`) => {
core.setFailed(err);
Expand All @@ -14,6 +14,12 @@ try {
const user = core.getInput('user');

const ghToken = core.getInput('ghToken');

if (!openAIToken) {
return `
Without a token, you're out of luck,
The gates to OpenAI are firmly stuck!`;
}
const rhyme = await aiAgent.createFailureRhyme(openAIToken, failureDescription, user);
await postRhymeToGitHub(rhyme, ghToken);

Expand All @@ -22,7 +28,7 @@ try {
}
})()
.then(() => {
console.log(`Finished runnning Loadmill Test Plan`);
console.log(`Finished runnning Failure Rhyme Action`);
});

async function postRhymeToGitHub(rhyme, token) {
Expand Down
1 change: 1 addition & 0 deletions node_modules/.bin/openai

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

Loading

0 comments on commit f915ff9

Please sign in to comment.