-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
3 changed files
with
64 additions
and
1 deletion.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
import type { Config } from '@jest/types'; | ||
// Sync object | ||
const config: Config.InitialOptions = { | ||
verbose: true, | ||
preset: 'ts-jest/presets/default-esm', // or other ESM presets | ||
moduleNameMapper: { | ||
'^(\\.{1,2}/.*)\\.js$': '$1', | ||
}, | ||
transform: { | ||
// '^.+\\.[tj]sx?$' to process js/ts with `ts-jest` | ||
// '^.+\\.m?[tj]sx?$' to process js/ts/mjs/mts with `ts-jest` | ||
'^.+\\.tsx?$': [ | ||
'ts-jest', | ||
{ | ||
useESM: true, | ||
}, | ||
], | ||
}, | ||
}; | ||
export default config; |
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 |
---|---|---|
@@ -0,0 +1,42 @@ | ||
import { templates, PromptTemplate } from "../src/main"; | ||
|
||
describe('templates', () => { | ||
it('base', async () => { | ||
const tpl = new PromptTemplate(templates.alpaca); | ||
expect(tpl.name).toBe("Alpaca"); | ||
expect(tpl.user).toBe("### Instruction:\n{prompt}"); | ||
expect(tpl.assistant).toBe("### Response:"); | ||
}); | ||
it('system', async () => { | ||
const tpl = new PromptTemplate(templates.alpaca); | ||
expect(tpl.system?.schema).toBe("{system}") | ||
const sysMsg = "Below is an instruction that describes a task. Write a response that appropriately completes the request." | ||
expect(tpl.system?.message).toBe(sysMsg); | ||
tpl.afterSystem("AFTER"); | ||
expect(tpl.render()).toContain(sysMsg + "AFTER"); | ||
tpl.replaceSystem("NEW SYS"); | ||
const txt = tpl.render() | ||
expect(txt).not.toContain(sysMsg); | ||
expect(txt.startsWith("NEW SYS")).toBeTruthy() | ||
}); | ||
it('shots', async () => { | ||
const tpl = new PromptTemplate(templates.human_response); | ||
tpl.addShot("2+2", "4"); | ||
const txt = `### HUMAN: | ||
2+2 | ||
### RESPONSE: | ||
4 | ||
### HUMAN: | ||
{prompt} | ||
### RESPONSE: | ||
` | ||
expect(tpl.render()).toBe(txt); | ||
const ntpl = tpl.cloneTo("mistral"); | ||
const newtxt = `<s>[INST] 2+2 [/INST]4 | ||
[INST] {prompt} [/INST]`; | ||
expect(ntpl.render()).toBe(newtxt) | ||
}); | ||
}); |
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 |
---|---|---|
|
@@ -18,7 +18,8 @@ | |
"dom" | ||
], | ||
"types": [ | ||
"node" | ||
"node", | ||
"jest" | ||
], | ||
"baseUrl": ".", | ||
"paths": { | ||
|