-
Notifications
You must be signed in to change notification settings - Fork 25
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Add nemo support * Fix old tokenization guidance * Fix nemo preset
- Loading branch information
Showing
16 changed files
with
353 additions
and
243 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
42 changes: 17 additions & 25 deletions
42
apps/interactor/src/libs/prompts/strategies/AbstractPromptStrategy.ts
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,38 +1,30 @@ | ||
import llamaTokenizer, { Tokenizer } from '../_llama-tokenizer' | ||
import mistralTokenizer from '../_mistral-tokenizer' | ||
import { Tokenizer } from '../_llama-tokenizer'; | ||
import mistralTokenizer from '../_mistral-tokenizer'; | ||
|
||
export abstract class AbstractPromptStrategy<Input, Output> { | ||
private tokenizer: Tokenizer | ||
constructor(tokenizerSkug?: string) { | ||
if (tokenizerSkug === 'mistral') { | ||
this.tokenizer = mistralTokenizer | ||
} else { | ||
this.tokenizer = llamaTokenizer | ||
} | ||
private tokenizer: Tokenizer; | ||
constructor(_tokenizerSkug?: string) { | ||
this.tokenizer = mistralTokenizer; | ||
} | ||
public abstract buildGuidancePrompt( | ||
maxNewTokens: number, | ||
memorySize: number, | ||
input: Input | ||
input: Input, | ||
): { | ||
template: string | ||
variables: Record<string, string | string[]> | ||
totalTokens: number | ||
} | ||
template: string; | ||
variables: Record<string, string | string[]>; | ||
totalTokens: number; | ||
}; | ||
|
||
public abstract completeResponse( | ||
input: Input, | ||
response: Output, | ||
variables: Map<string, string> | ||
): Output | ||
public abstract completeResponse(input: Input, response: Output, variables: Map<string, string>): Output; | ||
|
||
protected countTokens(template: string): number { | ||
let maxTokens: number = 0 | ||
let maxTokens: number = 0; | ||
template.replace(/max_tokens=(\d+)/g, (_, _maxTokens) => { | ||
maxTokens += parseInt(_maxTokens) || 0 | ||
return '' | ||
}) | ||
const _template = template.replace(/{{.*?}}/g, '') | ||
return this.tokenizer.encode(_template).length + maxTokens | ||
maxTokens += parseInt(_maxTokens) || 0; | ||
return ''; | ||
}); | ||
const _template = template.replace(/{{.*?}}/g, ''); | ||
return this.tokenizer.encode(_template).length + maxTokens; | ||
} | ||
} |
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 |
---|---|---|
|
@@ -39,4 +39,4 @@ | |
"devDependencies": { | ||
"nodemon": "^2.0.20" | ||
} | ||
} | ||
} |
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
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
Oops, something went wrong.