Skip to content

Commit

Permalink
fix: remove hard-coded token limit (#187)
Browse files Browse the repository at this point in the history
  • Loading branch information
rocktimsaikia authored Apr 4, 2023
1 parent 2255583 commit 9b24444
Showing 1 changed file with 1 addition and 9 deletions.
10 changes: 1 addition & 9 deletions src/utils/openai.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import https from 'https';
import type { ClientRequest, IncomingMessage } from 'http';
import type { CreateChatCompletionRequest, CreateChatCompletionResponse } from 'openai';
import { type TiktokenModel, encoding_for_model as encodingForModel } from '@dqbd/tiktoken';
import { type TiktokenModel } from '@dqbd/tiktoken';
import createHttpsProxyAgent from 'https-proxy-agent';
import { KnownError } from './error.js';

Expand Down Expand Up @@ -109,14 +109,6 @@ export const generateCommitMessage = async (
) => {
const prompt = getPrompt(locale, diff);

/**
* text-davinci-003 has a token limit of 4000
* https://platform.openai.com/docs/models/overview#:~:text=to%20Sep%202021-,text%2Ddavinci%2D003,-Can%20do%20any
*/
if (encodingForModel(model).encode(prompt).length > 4000) {
throw new KnownError('The diff is too large for the OpenAI API. Try reducing the number of staged changes, or write your own commit message.');
}

try {
const completion = await createChatCompletion(
apiKey,
Expand Down

0 comments on commit 9b24444

Please sign in to comment.