-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added help endpoint w/ code from equalify-llm-api repo, using OpenAI SDK
- Loading branch information
1 parent
33349ce
commit 8f13660
Showing
9 changed files
with
297 additions
and
10 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
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
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
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
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,60 @@ | ||
import { stripHtml } from 'string-strip-html'; | ||
import { openai } from '../utils/index.js'; | ||
|
||
export const help = async ({ request, reply }) => { | ||
const { reportId, messageId, dequeURL, message: accessibilityIssueToFix, codeSnippet: originalCodeSnippet, sourceUrl, status } = request.body; | ||
const accessibilityDocumentation = stripHtml(await (await fetch(dequeURL)).text()).result; | ||
const originalCode = await (await fetch(sourceUrl)).text(); | ||
|
||
const openaiRawResponse = await openai.chat.completions.create({ | ||
model: 'gpt-4-turbo-preview', | ||
tool_choice: { type: 'function', function: { name: 'suggested_fix' } }, | ||
tools: [{ | ||
type: 'function', | ||
function: { | ||
name: 'suggested_fix', | ||
description: 'Suggest an accessibility fix for the given code snippet and accessibility rule', | ||
parameters: { | ||
type: 'object', | ||
description: 'A suggested fix', | ||
properties: { | ||
suggested_replacement_code: { | ||
type: 'string', | ||
description: 'The suggested replacement code', | ||
}, | ||
how_to_implement: { | ||
type: 'string', | ||
description: 'How to implement the suggested code', | ||
}, | ||
diff_view: { | ||
type: 'string', | ||
description: 'A diff view of the old and new code with character and line positions listed on the left', | ||
}, | ||
}, | ||
required: ['suggested_code', 'how_to_implement', 'diff_view'], | ||
}, | ||
} | ||
}], | ||
messages: [ | ||
{ role: 'system', content: `You are an LLM bot running for Equalify, a platform designed to identify accessibility issues for developers to fix.` }, | ||
{ | ||
role: 'user', content: `Suggest replacement code to fix the accessibility issue identified by Equalify. You may use the accessibility documentation to assist in your resolution: | ||
\`\`\`json | ||
${JSON.stringify({ | ||
originalCode, | ||
originalCodeSnippet, | ||
accessibilityIssueToFix, | ||
accessibilityDocumentation, | ||
})} | ||
\`\`\` | ||
`}, | ||
] | ||
}); | ||
|
||
const suggestedFix = JSON.parse(openaiRawResponse.choices?.[0]?.message?.tool_calls?.[0]?.function?.arguments ?? '{}'); | ||
|
||
return { | ||
...suggestedFix, | ||
originalCode, | ||
}; | ||
} |
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 |
---|---|---|
@@ -1,3 +1,4 @@ | ||
export * from './getResults.js' | ||
export * from './graphql.js' | ||
export * from './getReports.js' | ||
export * from './getReports.js' | ||
export * from './help.js' |
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 |
---|---|---|
@@ -1,2 +1,3 @@ | ||
export * from './graphqlQuery.js' | ||
export * from './pgClient.js' | ||
export * from './pgClient.js' | ||
export * from './openai.js' |
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,2 @@ | ||
import OpenAI from 'openai'; | ||
export const openai = new OpenAI(); |
Oops, something went wrong.