mirror of
https://github.com/run-llama/ts-agents.git
synced 2026-07-01 21:14:01 -04:00
Mixtral ReAct agent
This commit is contained in:
@@ -0,0 +1,65 @@
|
||||
import {
|
||||
Ollama,
|
||||
FunctionTool,
|
||||
ReActAgent,
|
||||
Settings
|
||||
} from "llamaindex"
|
||||
import 'dotenv/config'
|
||||
|
||||
Settings.llm = new Ollama({
|
||||
model: "mixtral:8x7b",
|
||||
temperature: 0.1
|
||||
});
|
||||
|
||||
/*
|
||||
Set up logging so we can see the work in progress.
|
||||
Available events:
|
||||
llm-start
|
||||
llm-end
|
||||
agent-start
|
||||
agent-end
|
||||
llm-tool-call
|
||||
llm-tool-result
|
||||
*/
|
||||
Settings.callbackManager.on("llm-tool-call", (event) => {
|
||||
console.log(event.detail.payload)
|
||||
})
|
||||
Settings.callbackManager.on("llm-tool-result", (event) => {
|
||||
console.log(event.detail.payload)
|
||||
})
|
||||
|
||||
const sumNumbers = ({a, b}) => {
|
||||
return `${a + b}`;
|
||||
}
|
||||
|
||||
const tools = [
|
||||
FunctionTool.from(
|
||||
sumNumbers,
|
||||
{
|
||||
name: "sumNumbers",
|
||||
description: "Use this function to sum two numbers",
|
||||
parameters: {
|
||||
type: "object",
|
||||
properties: {
|
||||
a: {
|
||||
type: "number",
|
||||
description: "First number to sum"
|
||||
},
|
||||
b: {
|
||||
type: "number",
|
||||
description: "Second number to sum"
|
||||
},
|
||||
},
|
||||
required: ["a", "b"]
|
||||
}
|
||||
}
|
||||
)
|
||||
]
|
||||
|
||||
const agent = new ReActAgent({tools})
|
||||
|
||||
let response = await agent.chat({
|
||||
message: "Add 101 and 303",
|
||||
})
|
||||
|
||||
console.log(response)
|
||||
Generated
+3292
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,6 @@
|
||||
{
|
||||
"dependencies": {
|
||||
"dotenv": "^16.4.5",
|
||||
"llamaindex": "^0.3.1"
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user