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

format #313

Merged
merged 1 commit into from
May 11, 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
8 changes: 3 additions & 5 deletions samples/sample_runner.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import { main as test_loop } from "./test/loop";
import { main as slashgpt } from "./llm/slashgpt";
import { main as groq } from "./llm/groq";

import { main as net_paper_ai } from "./net/paper_ai"
import { main as net_paper_ai } from "./net/paper_ai";
import { main as net_rss } from "./net/rss";

import { main as interaction_text } from "./interaction/text";
Expand All @@ -20,7 +20,6 @@ import { main as interaction_select } from "./interaction/select";
import { main as sample_co2 } from "./tools/sample_co2";
import { main as tools_home } from "./tools/home";


const main = async () => {
// streaming
await streaming_groq();
Expand All @@ -31,7 +30,7 @@ const main = async () => {
// test
await test_fibonacci();
await test_loop();

// llm
await slashgpt();
await groq();
Expand All @@ -44,11 +43,10 @@ const main = async () => {
// net
await net_paper_ai();
await net_rss();

// tools
await sample_co2();
await tools_home();

};

main();
8 changes: 4 additions & 4 deletions src/experimental_agents/llm_agents/groq_stream_agent.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { AgentFunction } from "@/graphai";
import { Groq } from "groq-sdk";
import { ChatCompletionCreateParamsStreaming } from "groq-sdk/resources/chat/completions"
import { ChatCompletionCreateParamsStreaming } from "groq-sdk/resources/chat/completions";
import { assert } from "@/utils/utils";

const groq = process.env.GROQ_API_KEY ? new Groq({ apiKey: process.env.GROQ_API_KEY }) : undefined;
Expand Down Expand Up @@ -67,7 +67,7 @@ export const groqStreamAgent: AgentFunction<
}
if (tools) {
options.tools = tools;
options.tool_choice = tool_choice ?? "auto" as Groq.Chat.CompletionCreateParams.ToolChoice;
options.tool_choice = tool_choice ?? ("auto" as Groq.Chat.CompletionCreateParams.ToolChoice);
}
const stream = await groq.chat.completions.create(options);
let lastMessage = null;
Expand All @@ -81,9 +81,9 @@ export const groqStreamAgent: AgentFunction<
contents.push(token);
}
lastMessage = message as any;
};
}
if (lastMessage) {
lastMessage.choices[0]["message"] = [{"role": "assistant", "content": contents.join("")}];
lastMessage.choices[0]["message"] = [{ role: "assistant", content: contents.join("") }];
}
return lastMessage;
};
Expand Down
13 changes: 8 additions & 5 deletions src/experimental_agents/llm_agents/slashgpt_agent.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,11 +22,14 @@ export const slashGPTAgent: AgentFunction<
const contents = query.concat(inputs);

session.append_user_question(contents.join("\n"));
await session.call_loop(() => {}, (token: string) => {
if (filterParams && filterParams.streamTokenCallback && token) {
filterParams.streamTokenCallback(token);
}
});
await session.call_loop(
() => {},
(token: string) => {
if (filterParams && filterParams.streamTokenCallback && token) {
filterParams.streamTokenCallback(token);
}
},
);
return session.history.messages();
};

Expand Down
10 changes: 5 additions & 5 deletions src/node.ts
Original file line number Diff line number Diff line change
Expand Up @@ -220,18 +220,18 @@ export class ComputedNode extends Node {
private agentFilterHandler(context: AgentFunctionContext, agent: AgentFunction): Promise<ResultData> {
let index = 0;

const next = (context: AgentFunctionContext): Promise<ResultData> => {
const next = (innerContext: AgentFunctionContext): Promise<ResultData> => {
const agentFilter = this.graph.agentFilters[index++];
if (agentFilter) {
if (this.shouldApplyAgentFilter(agentFilter)) {
if (agentFilter.filterParams) {
context.filterParams = { ...agentFilter.filterParams, ...context.filterParams };
innerContext.filterParams = { ...agentFilter.filterParams, ...innerContext.filterParams };
}
return agentFilter.agent(context, next);
return agentFilter.agent(innerContext, next);
}
return next(context);
return next(innerContext);
}
return agent(context);
return agent(innerContext);
};

return next(context);
Expand Down
1 change: 0 additions & 1 deletion tests/agentFilters/test_filter_params.ts
Original file line number Diff line number Diff line change
Expand Up @@ -180,7 +180,6 @@ test("test filterParams on each agent", async () => {
});
});


test("test filterParams on agent filter", async () => {
const graph_data = {
version: 0.3,
Expand Down