-
Notifications
You must be signed in to change notification settings - Fork 87
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add Mistral instruct prompt template.
- Loading branch information
Showing
16 changed files
with
322 additions
and
24 deletions.
There are no files selected for viewing
20 changes: 20 additions & 0 deletions
20
...c/model-provider/llamacpp/llamacpp-stream-text-with-mistral-instruction-prompt-example.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 |
---|---|---|
@@ -0,0 +1,20 @@ | ||
import { MistralInstructPrompt, llamacpp, streamText } from "modelfusion"; | ||
|
||
// example assumes you are running a mistral instruct model with llama.cpp | ||
async function main() { | ||
const textStream = await streamText( | ||
llamacpp | ||
.TextGenerator({ maxGenerationTokens: 512 }) | ||
.withTextPromptTemplate(MistralInstructPrompt.instruction()), | ||
{ | ||
system: "You are a celebrated poet.", | ||
instruction: "Write a short story about a robot learning to love.", | ||
} | ||
); | ||
|
||
for await (const textPart of textStream) { | ||
process.stdout.write(textPart); | ||
} | ||
} | ||
|
||
main().catch(console.error); |
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
9 changes: 5 additions & 4 deletions
9
examples/basic/src/model-provider/ollama/ollama-completion-generate-text-example.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
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
7 changes: 4 additions & 3 deletions
7
examples/basic/src/model-provider/ollama/ollama-completion-stream-text-example.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
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
4 changes: 2 additions & 2 deletions
4
examples/basic/src/model-provider/ollama/ollama-completion-stream-text-raw-example.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
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
72 changes: 72 additions & 0 deletions
72
...on/src/model-function/generate-text/prompt-template/MistralInstructPromptTemplate.test.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 |
---|---|---|
@@ -0,0 +1,72 @@ | ||
import { chat, instruction, text } from "./MistralInstructPromptTemplate.js"; | ||
|
||
describe("text prompt", () => { | ||
it("should format prompt", () => { | ||
const prompt = text().format("prompt"); | ||
|
||
expect(prompt).toMatchSnapshot(); | ||
}); | ||
}); | ||
|
||
describe("instruction prompt", () => { | ||
it("should format prompt with instruction", () => { | ||
const prompt = instruction().format({ | ||
instruction: "instruction", | ||
}); | ||
|
||
expect(prompt).toMatchSnapshot(); | ||
}); | ||
|
||
it("should format prompt with system and instruction", () => { | ||
const prompt = instruction().format({ | ||
system: "system", | ||
instruction: "instruction", | ||
}); | ||
|
||
expect(prompt).toMatchSnapshot(); | ||
}); | ||
|
||
it("should format prompt with instruction and response prefix", () => { | ||
const prompt = instruction().format({ | ||
instruction: "instruction", | ||
responsePrefix: "response prefix", | ||
}); | ||
|
||
expect(prompt).toMatchSnapshot(); | ||
}); | ||
}); | ||
|
||
describe("chat prompt", () => { | ||
it("should format prompt with user message", () => { | ||
const prompt = chat().format({ | ||
messages: [{ role: "user", content: "user message" }], | ||
}); | ||
|
||
expect(prompt).toMatchSnapshot(); | ||
}); | ||
|
||
it("should format prompt with user-assistant-user messages", () => { | ||
const prompt = chat().format({ | ||
messages: [ | ||
{ role: "user", content: "1st user message" }, | ||
{ role: "assistant", content: "assistant message" }, | ||
{ role: "user", content: "2nd user message" }, | ||
], | ||
}); | ||
|
||
expect(prompt).toMatchSnapshot(); | ||
}); | ||
|
||
it("should format prompt with system message and user-assistant-user messages", () => { | ||
const prompt = chat().format({ | ||
system: "you are a chatbot", | ||
messages: [ | ||
{ role: "user", content: "1st user message" }, | ||
{ role: "assistant", content: "assistant message" }, | ||
{ role: "user", content: "2nd user message" }, | ||
], | ||
}); | ||
|
||
expect(prompt).toMatchSnapshot(); | ||
}); | ||
}); |
Oops, something went wrong.
d2c2cc9
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:
modelfusion – ./
www.modelfusion.dev
modelfusion-lgrammel.vercel.app
modelfusion-git-main-lgrammel.vercel.app
modelfusion.dev