Skip to content

Commit

Permalink
bundled
Browse files Browse the repository at this point in the history
  • Loading branch information
bemijonathan committed Apr 27, 2024
1 parent 5517d0e commit 9f39ec5
Showing 1 changed file with 40 additions and 40 deletions.
80 changes: 40 additions & 40 deletions src/ai.ts
Original file line number Diff line number Diff line change
@@ -1,49 +1,49 @@
import {
prompt,
jiraPrompt,
acSummariesPrompt,
compareOldSummaryTemplate
prompt,
jiraPrompt,
acSummariesPrompt,
compareOldSummaryTemplate
} from './constants.js'
import core from '@actions/core'
import * as core from '@actions/core'
import OpenAI from 'openai'
import { Logger } from './utils.js'

export class Ai {
constructor() {
const openAiKey = core.getInput('openAIKey') || process.env.OPENAI_API_KEY
if (!openAiKey) {
throw new Error('OpenAI key is required')
}
this.model = new OpenAI({
apiKey: openAiKey
})
constructor() {
const openAiKey = core.getInput('openAIKey') || process.env.OPENAI_API_KEY
if (!openAiKey) {
throw new Error('OpenAI key is required')
}
configuration = {
model: 'gpt-3.5-turbo'
}
model: OpenAI
basePromptTemplate = prompt
jiraPromptTemplate = jiraPrompt
acSummariesPromptTemplate = acSummariesPrompt
compareOldSummaryTemplate(oldSummary: string, newSummary: string): string {
return compareOldSummaryTemplate(oldSummary, newSummary)
}
execute = async (prompt: string) => {
try {
const response = await this.model.chat.completions.create({
messages: [
{
role: 'user',
content: prompt
}
],
...this.configuration
})
Logger.log('ai response', { response })
return response.choices[0].message.content
} catch (e) {
Logger.error('error summarizing changes', e)
return null
}
this.model = new OpenAI({
apiKey: openAiKey
})
}
configuration = {
model: 'gpt-3.5-turbo'
}
model: OpenAI
basePromptTemplate = prompt
jiraPromptTemplate = jiraPrompt
acSummariesPromptTemplate = acSummariesPrompt
compareOldSummaryTemplate(oldSummary: string, newSummary: string): string {
return compareOldSummaryTemplate(oldSummary, newSummary)
}
execute = async (prompt: string) => {
try {
const response = await this.model.chat.completions.create({
messages: [
{
role: 'user',
content: prompt
}
],
...this.configuration
})
Logger.log('ai response', { response })
return response.choices[0].message.content
} catch (e) {
Logger.error('error summarizing changes', e)
return null
}
}
}

0 comments on commit 9f39ec5

Please sign in to comment.