Skip to content

Commit

Permalink
fix: tokenize with gpt-3.5-turbo model (Nutlope#173)
Browse files Browse the repository at this point in the history
  • Loading branch information
privatenumber authored Mar 27, 2023
1 parent 52b62d5 commit 7068024
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 8 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@
"*.ts": "eslint --cache"
},
"dependencies": {
"@dqbd/tiktoken": "^0.4.0"
"@dqbd/tiktoken": "^1.0.2"
},
"devDependencies": {
"@clack/prompts": "^0.6.1",
Expand Down
8 changes: 4 additions & 4 deletions pnpm-lock.yaml

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

4 changes: 1 addition & 3 deletions src/utils/openai.ts
Original file line number Diff line number Diff line change
Expand Up @@ -91,8 +91,6 @@ const deduplicateMessages = (array: string[]) => Array.from(new Set(array));
const getPrompt = (locale: string, diff: string) => `Write an insightful but concise Git commit message in a complete sentence in present tense for the following diff without prefacing it with anything, the response must be in the language ${locale}:\n${diff}`;

const model = 'gpt-3.5-turbo';
// TODO: update for the new gpt-3.5 model
const encoder = encodingForModel('text-davinci-003');

export const generateCommitMessage = async (
apiKey: string,
Expand All @@ -106,7 +104,7 @@ export const generateCommitMessage = async (
* 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 (encoder.encode(prompt).length > 4000) {
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.');
}

Expand Down

0 comments on commit 7068024

Please sign in to comment.