Skip to content

Commit

Permalink
openai api limit response to max tokens
Browse files Browse the repository at this point in the history
  • Loading branch information
davecthomas committed Mar 14, 2024
1 parent ac9eb88 commit 13d23ed
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 4 deletions.
2 changes: 1 addition & 1 deletion dist/index.js

Large diffs are not rendered by default.

8 changes: 5 additions & 3 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import OpenAI from "openai"
const apiKey: string | undefined = process.env.OPENAI_API_KEY
const openAiModel: string | undefined = process.env.OPENAI_MODEL
const defaultOpenAiModel: string = "gpt-4-turbo-preview"
const maxTokens: number = 200 // Max tokens for OpenAI completions. Making this huge is both expensive and unnecessary.

// Define types for the files obtained from GitHub API responses
type GitHubFile =
Expand Down Expand Up @@ -95,9 +96,10 @@ async function fetchOpenAIDescription(
messages: [
{
role: "system",
content: `Describe the following code changes in this github diff between a base and head commit, limiting your insights to logic and string content changes only. Ignore formatting and white space changes.\n${diff}`,
content: `In fewer than ${maxTokens}, describe the following code changes in this github diff between a base and head commit, limiting your insights to logic and string content changes only. Ignore formatting and white space changes.\n${diff}`,
},
],
max_tokens: maxTokens,
})
if (
completion.choices &&
Expand Down Expand Up @@ -199,8 +201,8 @@ export async function run(): Promise<void> {
const openAiClient = new OpenAI({
apiKey: process.env.OPENAI_API_KEY,
})
const models = await listModels(openAiClient)
core.setOutput("openAiModels", JSON.stringify(models))
// const models = await listModels(openAiClient)
// core.setOutput("openAiModels", JSON.stringify(models))
await processDiffsAndSetOutput(openAiClient, diffs) // For each diff, fetch a description from OpenAI and set the output

// console.log(diffsJoined)
Expand Down

0 comments on commit 13d23ed

Please sign in to comment.