-
Notifications
You must be signed in to change notification settings - Fork 83
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add automatic JSON enforcement to jsonToolCallPrompt.
- Loading branch information
Showing
9 changed files
with
163 additions
and
55 deletions.
There are no files selected for viewing
28 changes: 28 additions & 0 deletions
28
examples/basic/src/model-provider/llamacpp/llamacpp-run-tool-mistral-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,28 @@ | ||
import { jsonToolCallPrompt, llamacpp, runTool } from "modelfusion"; | ||
import { calculator } from "../../tool/tools/calculator-tool"; | ||
|
||
async function main() { | ||
const { tool, toolCall, args, ok, result } = await runTool({ | ||
model: llamacpp | ||
.CompletionTextGenerator({ | ||
// run https://huggingface.co/TheBloke/Mistral-7B-Instruct-v0.2-GGUF with llama.cpp | ||
promptTemplate: llamacpp.prompt.ChatML, | ||
temperature: 0, | ||
}) | ||
.withInstructionPrompt() | ||
.asToolCallGenerationModel(jsonToolCallPrompt.text()), | ||
|
||
tool: calculator, | ||
prompt: "What's fourteen times twelve?", | ||
|
||
logging: "detailed-object", | ||
}); | ||
|
||
console.log(`Tool call:`, toolCall); | ||
console.log(`Tool:`, tool); | ||
console.log(`Arguments:`, args); | ||
console.log(`Ok:`, ok); | ||
console.log(`Result or Error:`, result); | ||
} | ||
|
||
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
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
27 changes: 27 additions & 0 deletions
27
packages/modelfusion/src/tool/generate-tool-call/ToolCallPromptTemplate.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,27 @@ | ||
import { JsonSchemaProducer } from "../../core/schema/JsonSchemaProducer"; | ||
import { Schema } from "../../core/schema/Schema"; | ||
import { ToolDefinition } from "../ToolDefinition"; | ||
|
||
export interface ToolCallPromptTemplate<SOURCE_PROMPT, TARGET_PROMPT> { | ||
createPrompt( | ||
prompt: SOURCE_PROMPT, | ||
tool: ToolDefinition<string, unknown> | ||
): TARGET_PROMPT; | ||
|
||
extractToolCall( | ||
response: string, | ||
tool: ToolDefinition<string, unknown> | ||
): { id: string; args: unknown } | null; | ||
|
||
withJsonOutput?({ | ||
model, | ||
schema, | ||
}: { | ||
model: { | ||
withJsonOutput( | ||
schema: Schema<unknown> & JsonSchemaProducer | ||
): typeof model; | ||
}; | ||
schema: Schema<unknown> & JsonSchemaProducer; | ||
}): typeof model; | ||
} |
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