Skip to content

Commit

Permalink
chore: update to latest APIs (#26)
Browse files Browse the repository at this point in the history
  • Loading branch information
joyceerhl authored May 15, 2024
1 parent 82f4883 commit 8e1dc64
Show file tree
Hide file tree
Showing 6 changed files with 328 additions and 247 deletions.
4 changes: 2 additions & 2 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 package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@vscode/prompt-tsx",
"version": "0.1.6-alpha",
"version": "0.1.7-alpha",
"description": "Declare LLM prompts with TSX",
"main": "./dist/base/index.js",
"types": "./dist/base/index.d.ts",
Expand Down
6 changes: 2 additions & 4 deletions src/base/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -95,12 +95,10 @@ export function toVsCodeChatMessages(messages: ChatMessage[]) {
const vscode = require('vscode');
return messages.map((m) => {
switch (m.role) {
case ChatRole.System:
return new vscode.LanguageModelChatSystemMessage(m.content);
case ChatRole.Assistant:
return new vscode.LanguageModelChatAssistantMessage(m.content, m.name);
return vscode.LanguageModelChatMessage.Assistant(m.content, m.name);
case ChatRole.User:
return new vscode.LanguageModelChatUserMessage(m.content, m.name);
return vscode.LanguageModelChatMessage.User(m.content, m.name);
}
});
}
25 changes: 0 additions & 25 deletions src/base/tokenizer/tokenizer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,18 +25,6 @@ export interface ITokenizer {
*/
tokenLength(text: string): number;

/**
* Returns the tokens created from tokenizing `text`.
* @param text The text to tokenize
*/
tokenize(text: string): number[];

/**
* This function returns the substring such that the return string has maxTokenCount tokens when encoded.
* If the input text has more than maxTokenCount tokens, the return string will be the first maxTokenCount tokens.
*/
encodeTrimSuffix(text: string, maxTokenCount: number): string;

countMessageTokens(message: ChatMessage): number;
}

Expand Down Expand Up @@ -69,19 +57,6 @@ export class Cl100KBaseTokenizer implements ITokenizer {
return this._cl100kTokenizer.encode(text);
}

/**
* Encodes the given text and trims the suffix to the specified maximum token count.
* @param text The text to encode and trim.
* @param maxTokenCount The maximum number of tokens to include in the trimmed text.
* @returns The encoded and trimmed text.
*/
encodeTrimSuffix(text: string, maxTokenCount: number): string {
if (!this._cl100kTokenizer) {
this._cl100kTokenizer = this.initTokenizer();
}
return this._cl100kTokenizer.encodeTrimSuffix(text, maxTokenCount, []).text;
}

/**
* Calculates the token length of the given text.
* @param text The text to calculate the token length for.
Expand Down
Loading

0 comments on commit 8e1dc64

Please sign in to comment.