Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Some samples in v 0.3 #292

Merged
merged 6 commits into from
May 9, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 14 additions & 14 deletions samples/sample_benchmark.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { graphDataTestRunner } from "~/utils/runner";
import { groqAgent, fetchAgent, shiftAgent, nestedAgent } from "@/experimental_agents";

const graph_data = {
version: 0.2,
version: 0.3,
nodes: {
GSM8: {
// This node specifies the URL and query paramters to fetch GSM8K dataset.
Expand All @@ -21,66 +21,66 @@ const graph_data = {
fetch: {
// This node fetches the dataset over HTTP.
agent: "fetchAgent",
inputs: ["GSM8.url", "GSM8.query"],
inputs: [":GSM8.url", ":GSM8.query"],
},
rows: {
// This node extract the "row" property from each item in the dataset.
agent: (items: Array<Record<string, any>>) => items.map((item) => item.row),
inputs: ["fetch.rows"],
inputs: [":fetch.rows"],
},
debugOutputRow: {
agent: (row: Record<string, string>) => console.log(row),
inputs: ["rows.$0"],
inputs: [":rows.$0"],
},
loop: {
// This node interate all the items in the dataset using the nested graph
agent: "nestedAgent",
inputs: ["rows"],
inputs: [":rows"],
isResult: true,
graph: {
// This graph continues until the array on node "$0" becomes empty
version: 0.2,
version: 0.3,
loop: {
while: "$0",
while: ":$0",
},
nodes: {
// This node receives the inputs[0] (data from "rows" node on outer graph) initially
// then, updated with the data from "retriever" node after each iteration.
$0: {
value: undefined,
update: "retriever.array",
update: ":retriever.array",
},
// This node accumurate asnwers for each question in the dataset.
answers: {
value: [],
update: "reducer",
update: ":reducer",
isResult: true,
},
// This node takes the first item from the array from node "$0".
retriever: {
agent: "shiftAgent",
inputs: ["$0"],
inputs: [":$0"],
},
debugOutputQA: {
agent: (item: Record<string, string>) => console.log(`Q: ${item.question}\nA0: ${item.answer}`),
inputs: ["retriever.item"],
inputs: [":retriever.item"],
},
groq: {
// This node sends the question on the current item to Llama3 on groq and get the answer.
agent: "groqAgent",
params: {
model: "Llama3-8b-8192",
},
inputs: ["retriever.item.question"],
inputs: [":retriever.item.question"],
},
reducer: {
// This node pushs the answer from Llama3 into the answer array.
agent: "pushAgent",
inputs: ["answers", "groq.choices.$0.message.content"],
inputs: [":answers", ":groq.choices.$0.message.content"],
},
debugOutputA: {
agent: (answer: string) => console.log(`A: ${answer}\n`),
inputs: ["groq.choices.$0.message.content"],
inputs: [":groq.choices.$0.message.content"],
},
},
},
Expand Down
14 changes: 7 additions & 7 deletions samples/sample_benchmark2.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { graphDataTestRunner } from "~/utils/runner";
import { groqAgent, fetchAgent, mapAgent } from "@/experimental_agents";

const graph_data = {
version: 0.2,
version: 0.3,
nodes: {
GSM8: {
// This node specifies the URL and query paramters to fetch GSM8K dataset.
Expand All @@ -21,32 +21,32 @@ const graph_data = {
fetch: {
// This node fetches the dataset over HTTP.
agent: "fetchAgent",
inputs: ["GSM8.url", "GSM8.query"],
inputs: [":GSM8.url", ":GSM8.query"],
},
rows: {
// This node extract the "row" property from each item in the dataset.
agent: (items: Array<Record<string, any>>) => items.map((item) => item.row),
inputs: ["fetch.rows"],
inputs: [":fetch.rows"],
},
map: {
// This node executes the nested graph concurrently
agent: "mapAgent",
inputs: ["rows"],
inputs: [":rows"],
isResult: true,
graph: {
version: 0.2,
version: 0.3,
nodes: {
groq: {
// This node sends the question on the current item to Llama3 on groq and get the answer.
agent: "groqAgent",
params: {
model: "Llama3-8b-8192",
},
inputs: ["$0.question"],
inputs: [":$0.question"],
},
answer: {
agent: (item: string) => item,
inputs: ["groq.choices.$0.message.content"],
inputs: [":groq.choices.$0.message.content"],
isResult: true,
},
},
Expand Down
20 changes: 10 additions & 10 deletions samples/sample_chat.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,19 +4,19 @@ import { groqAgent, shiftAgent, nestedAgent } from "@/experimental_agents";
import input from "@inquirer/input";

const graph_data = {
version: 0.2,
version: 0.3,
loop: {
while: "continue",
while: ":continue",
},
nodes: {
continue: {
value: true,
update: "checkInput",
update: ":checkInput",
},
messages: {
// This node holds the conversation, array of messages.
value: [],
update: "reducer",
update: ":reducer",
isResult: true,
},
userInput: {
Expand All @@ -25,31 +25,31 @@ const graph_data = {
},
checkInput: {
agent: (query: string) => query !== "/bye",
inputs: ["userInput"],
inputs: [":userInput"],
},
appendedMessages: {
// This node appends the user's input to the array of messages.
agent: (content: string, messages: Array<any>) => [...messages, { role: "user", content }],
inputs: ["userInput", "messages"],
if: "checkInput",
inputs: [":userInput", ":messages"],
if: ":checkInput",
},
groq: {
// This node sends those messages to Llama3 on groq to get the answer.
agent: "groqAgent",
params: {
model: "Llama3-8b-8192",
},
inputs: [undefined, "appendedMessages"],
inputs: [undefined, ":appendedMessages"],
},
output: {
// This node displays the responce to the user.
agent: (answer: string) => console.log(`Llama3: ${answer}\n`),
inputs: ["groq.choices.$0.message.content"],
inputs: [":groq.choices.$0.message.content"],
},
reducer: {
// This node append the responce to the messages.
agent: "pushAgent",
inputs: ["appendedMessages", "groq.choices.$0.message"],
inputs: [":appendedMessages", ":groq.choices.$0.message"],
},
},
};
Expand Down
12 changes: 6 additions & 6 deletions samples/sample_tool.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,22 +24,22 @@ const tools = [
];

const graph_data = {
version: 0.2,
version: 0.3,
concurrency: 1,
nodes: {
foods: {
value: ["apple", "eggplant", "pork"],
},
categorizer: {
agent: "mapAgent",
inputs: ["foods"],
inputs: [":foods"],
isResult: true,
graph: {
version: 0.2,
version: 0.3,
nodes: {
debug: {
agent: (food: string) => console.log(food),
inputs: ["$0"],
inputs: [":$0"],
isResult: true,
},
groq: {
Expand All @@ -52,14 +52,14 @@ const graph_data = {
tool_choice: { type: "function", function: { name: "categorize" } },
},
retry: 1,
inputs: ["$0"],
inputs: [":$0"],
},
parser: {
agent: (food: string, args: string) => {
const json = JSON.parse(args);
return { [food]: json.category };
},
inputs: ["$0", "groq.choices.$0.message.tool_calls.$0.function.arguments"],
inputs: [":$0", ":groq.choices.$0.message.tool_calls.$0.function.arguments"],
isResult: true,
},
},
Expand Down
Loading