-
Notifications
You must be signed in to change notification settings - Fork 89
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #45 from lgrammel/tools
Tool improvements
- Loading branch information
Showing
36 changed files
with
474 additions
and
160 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,3 +3,4 @@ | |
build | ||
dist | ||
node_modules | ||
examples/*/package-lock.json |
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 |
---|---|---|
@@ -0,0 +1,41 @@ | ||
import dotenv from "dotenv"; | ||
import { Tool, executeTool } from "modelfusion"; | ||
import { z } from "zod"; | ||
|
||
dotenv.config(); | ||
|
||
(async () => { | ||
const calculator = new Tool({ | ||
name: "calculator" as const, // mark 'as const' for type inference | ||
description: "Execute a calculation", | ||
|
||
inputSchema: z.object({ | ||
a: z.number().describe("The first number."), | ||
b: z.number().describe("The second number."), | ||
operator: z.enum(["+", "-", "*", "/"]).describe("The operator."), | ||
}), | ||
|
||
execute: async ({ a, b, operator }) => { | ||
switch (operator) { | ||
case "+": | ||
return a + b; | ||
case "-": | ||
return a - b; | ||
case "*": | ||
return a * b; | ||
case "/": | ||
return a / b; | ||
default: | ||
throw new Error(`Unknown operator: ${operator}`); | ||
} | ||
}, | ||
}); | ||
|
||
const result = await executeTool(calculator, { | ||
a: 14, | ||
b: 12, | ||
operator: "*" as const, | ||
}); | ||
|
||
console.log(`Result: ${result}`); | ||
})(); |
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,46 @@ | ||
import dotenv from "dotenv"; | ||
import { Tool, executeTool } from "modelfusion"; | ||
import { z } from "zod"; | ||
|
||
dotenv.config(); | ||
|
||
(async () => { | ||
const calculator = new Tool({ | ||
name: "calculator" as const, // mark 'as const' for type inference | ||
description: "Execute a calculation", | ||
|
||
inputSchema: z.object({ | ||
a: z.number().describe("The first number."), | ||
b: z.number().describe("The second number."), | ||
operator: z.enum(["+", "-", "*", "/"]).describe("The operator."), | ||
}), | ||
|
||
execute: async ({ a, b, operator }) => { | ||
switch (operator) { | ||
case "+": | ||
return a + b; | ||
case "-": | ||
return a - b; | ||
case "*": | ||
return a * b; | ||
case "/": | ||
return a / b; | ||
default: | ||
throw new Error(`Unknown operator: ${operator}`); | ||
} | ||
}, | ||
}); | ||
|
||
const { metadata, output } = await executeTool( | ||
calculator, | ||
{ | ||
a: 14, | ||
b: 12, | ||
operator: "*" as const, | ||
}, | ||
{ fullResponse: true } | ||
); | ||
|
||
console.log(`Result: ${output}`); | ||
console.log(`Duration: ${metadata.durationInMs}ms`); | ||
})(); |
File renamed without changes.
File renamed without changes.
File renamed without changes.
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 |
---|---|---|
@@ -1,6 +1,3 @@ | ||
export * from "./use-tool/NoSuchToolError.js"; | ||
export * from "./use-tool/Tool.js"; | ||
export * from "./use-tool/useTool.js"; | ||
export * from "./summarize/SummarizationFunction.js"; | ||
export * from "./summarize/summarizeRecursively.js"; | ||
export * from "./summarize/summarizeRecursivelyWithTextGenerationAndTokenSplitting.js"; |
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 was deleted.
Oops, something went wrong.
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.
399e51a
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 – ./
modelfusion-lgrammel.vercel.app
www.modelfusion.dev
ai-utils.dev
modelfusion-git-main-lgrammel.vercel.app
modelfusion.dev