Skip to content

Commit

Permalink
fix(openai): switched to pure js tiktoken (#248)
Browse files Browse the repository at this point in the history
  • Loading branch information
nirga authored May 7, 2024
1 parent 8ee046e commit 9d8805e
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 12 deletions.
13 changes: 4 additions & 9 deletions package-lock.json

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

2 changes: 1 addition & 1 deletion packages/instrumentation-openai/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@
"@opentelemetry/instrumentation": "^0.49.0",
"@opentelemetry/semantic-conventions": "^1.22.0",
"@traceloop/ai-semantic-conventions": "^0.8.0",
"tiktoken": "^1.0.13"
"js-tiktoken": "^1.0.11"
},
"devDependencies": {
"@pollyjs/adapter-node-http": "^6.0.6",
Expand Down
4 changes: 2 additions & 2 deletions packages/instrumentation-openai/src/instrumentation.ts
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ import type {
} from "openai/resources";
import type { Stream } from "openai/streaming";
import { version } from "../package.json";
import { encoding_for_model, TiktokenModel, Tiktoken } from "tiktoken";
import { encodingForModel, TiktokenModel, Tiktoken } from "js-tiktoken";

export class OpenAIInstrumentation extends InstrumentationBase<any> {
protected declare _config: OpenAIInstrumentationConfig;
Expand Down Expand Up @@ -726,7 +726,7 @@ export class OpenAIInstrumentation extends InstrumentationBase<any> {

if (!encoding) {
try {
encoding = encoding_for_model(model as TiktokenModel);
encoding = encodingForModel(model as TiktokenModel);
this._encodingCache.set(model, encoding);
} catch (e) {
this._diag.warn(e);
Expand Down

0 comments on commit 9d8805e

Please sign in to comment.