-
Notifications
You must be signed in to change notification settings - Fork 2.2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
langchain[patch]: Miscellaneous test fixes (#3497)
* Fix bug * Small fixes
- Loading branch information
1 parent
cd7e640
commit 791e314
Showing
4 changed files
with
7 additions
and
50 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,44 +1 @@ | ||
import { | ||
Tiktoken, | ||
TiktokenBPE, | ||
TiktokenEncoding, | ||
TiktokenModel, | ||
getEncodingNameForModel, | ||
} from "js-tiktoken/lite"; | ||
import { AsyncCaller } from "./async_caller.js"; | ||
|
||
const cache: Record<string, Promise<TiktokenBPE>> = {}; | ||
|
||
const caller = /* #__PURE__ */ new AsyncCaller({}); | ||
|
||
export async function getEncoding( | ||
encoding: TiktokenEncoding, | ||
options?: { | ||
signal?: AbortSignal; | ||
extendedSpecialTokens?: Record<string, number>; | ||
} | ||
) { | ||
if (!(encoding in cache)) { | ||
cache[encoding] = caller | ||
.fetch(`https://tiktoken.pages.dev/js/${encoding}.json`, { | ||
signal: options?.signal, | ||
}) | ||
.then((res) => res.json()) | ||
.catch((e) => { | ||
delete cache[encoding]; | ||
throw e; | ||
}); | ||
} | ||
|
||
return new Tiktoken(await cache[encoding], options?.extendedSpecialTokens); | ||
} | ||
|
||
export async function encodingForModel( | ||
model: TiktokenModel, | ||
options?: { | ||
signal?: AbortSignal; | ||
extendedSpecialTokens?: Record<string, number>; | ||
} | ||
) { | ||
return getEncoding(getEncodingNameForModel(model), options); | ||
} | ||
export * from "@langchain/core/utils/tiktoken"; |
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
791e314
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Successfully deployed to the following URLs:
langchainjs-api-refs β ./docs/api_refs
langchainjs-api-refs-git-main-langchain.vercel.app
langchainjs-api-refs-langchain.vercel.app
api.js.langchain.com
langchainjs-api-docs.vercel.app
791e314
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Successfully deployed to the following URLs:
langchainjs-docs β ./docs/core_docs/
langchainjs-docs-langchain.vercel.app
langchainjs-docs-ruddy.vercel.app
langchainjs-docs-git-main-langchain.vercel.app
js.langchain.com