Skip to content

Commit

Permalink
API alignment with AutoGen (#19)
Browse files Browse the repository at this point in the history
* Align API endpoints; add instructions field
* Fix API responses for GET agents, tools, and agencies lists.
* Refactoring of the FastAPI dependencies
* Refactor -> move objects to services
* Refactor AgencyConfigStorage to remove agency_id from the constructor.
  • Loading branch information
bonk1t authored Jan 20, 2024
1 parent 05fdbd9 commit 675adeb
Show file tree
Hide file tree
Showing 50 changed files with 334 additions and 227 deletions.
1 change: 1 addition & 0 deletions frontend/.env.development
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
GATSBY_API_URL=http://127.0.0.1:8000/v1/api
1 change: 1 addition & 0 deletions frontend/.env.production
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
GATSBY_API_URL=/v1/api
4 changes: 1 addition & 3 deletions frontend/.gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,5 @@ node_modules/
.cache/
public/

.env.development
.env.production

package-lock.json
yarn.lock
24 changes: 22 additions & 2 deletions frontend/src/components/atoms.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -1032,6 +1032,26 @@ export const AgentFlowSpecView = ({
/>
)} */}

{llm_config && (
<ControlRowView
title="Instructions"
className="mt-4"
description="Instructions to define agent behavior"
value={flowSpec.config.instructions}
control={
<TextArea
className="mt-2 w-full"
value={flowSpec.config.instructions}
rows={3}
onChange={(e) => {
// onDebouncedControlChange(e.target.value, "instructions");
onControlChange(e.target.value, "instructions");
}}
/>
}
/>
)}

{
<ControlRowView
title="Skills"
Expand Down Expand Up @@ -1197,7 +1217,7 @@ export const SkillLoader = ({
});
const serverUrl = getServerUrl();
const { user } = React.useContext(appContext);
const listSkillsUrl = `${serverUrl}/skills?user_id=${user?.email}`;
const listSkillsUrl = `${serverUrl}/tool?user_id=${user?.id}`;

const fetchSkills = () => {
setError(null);
Expand Down Expand Up @@ -1372,7 +1392,7 @@ const AgentModal = ({

const serverUrl = getServerUrl();
const { user } = React.useContext(appContext);
const listAgentsUrl = `${serverUrl}/agents?user_id=${user?.email}`;
const listAgentsUrl = `${serverUrl}/agent?user_id=${user?.id}`;

const [flowSpecs, setFlowSpecs] = useState<IAgentFlowSpec[]>([]);
useEffect(() => {
Expand Down
1 change: 1 addition & 0 deletions frontend/src/components/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ export interface IAgentConfig {
human_input_mode: string;
max_consecutive_auto_reply: number;
system_message: string | "";
instructions: string | "";
is_termination_msg?: boolean | string;
code_execution_config?: boolean | string | { [key: string]: any } | null;
}
Expand Down
5 changes: 4 additions & 1 deletion frontend/src/components/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import {
} from "./types";

export const getServerUrl = () => {
return process.env.GATSBY_API_URL || "/api";
return process.env.GATSBY_API_URL || "/v1/api";
};

export function setCookie(name: string, value: any, days: number) {
Expand Down Expand Up @@ -241,6 +241,7 @@ export const sampleWorkflowConfig = () => {
human_input_mode: "NEVER",
max_consecutive_auto_reply: 5,
system_message: "",
instructions: "",
llm_config: false,
code_execution_config: {
work_dir: null,
Expand All @@ -259,6 +260,8 @@ export const sampleWorkflowConfig = () => {
max_consecutive_auto_reply: 8,
system_message:
"You are a helpful assistant that can use available functions when needed to solve problems. At each point, do your best to determine if the user's request has been addressed. IF THE REQUEST HAS NOT BEEN ADDRESSED, RESPOND WITH CODE TO ADDRESS IT. IF A FAILURE OCCURRED (e.g., due to a missing library) AND SOME ADDITIONAL CODE WAS WRITTEN (e.g. code to install the library), ENSURE THAT THE ORIGINAL CODE TO ADDRESS THE TASK STILL GETS EXECUTED. If the request HAS been addressed, respond with a summary of the result. The summary must be written as a coherent helpful response to the user request e.g. 'Sure, here is result to your request ' or 'The tallest mountain in Africa is ..' etc. The summary MUST end with the word TERMINATE. If the user request is pleasantry or greeting, you should respond with a pleasantry or greeting and TERMINATE.",
instructions:
"You are a helpful assistant that can use available functions when needed to solve problems. At each point, do your best to determine if the user's request has been addressed. IF THE REQUEST HAS NOT BEEN ADDRESSED, ADDRESS IT. IF A FAILURE OCCURRED AND SOME ADDITIONAL CODE WAS WRITTEN (e.g. code to install the library), ENSURE THAT THE ORIGINAL CODE TO ADDRESS THE TASK STILL GETS EXECUTED. If the request HAS been addressed, respond with a summary of the result. The summary must be written as a coherent helpful response to the user request e.g. 'Sure, here is result to your request ' or 'The tallest mountain in Africa is ..' etc.",
};

const assistantFlowSpec: IAgentFlowSpec = {
Expand Down
15 changes: 8 additions & 7 deletions frontend/src/components/views/builder/agents.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,9 @@ const AgentsView = ({}: any) => {

const { user } = React.useContext(appContext);
const serverUrl = getServerUrl();
const listAgentsUrl = `${serverUrl}/agents?user_id=${user?.email}`;
const saveAgentsUrl = `${serverUrl}/agents`;
const deleteAgentUrl = `${serverUrl}/agents/delete`;
const listAgentsUrl = `${serverUrl}/agent?user_id=${user?.id}`;
const saveAgentsUrl = `${serverUrl}/agent/config`;
const deleteAgentUrl = `${serverUrl}/agent/delete`;

const [agents, setAgents] = React.useState<IAgentFlowSpec[] | null>([]);
const [selectedAgent, setSelectedAgent] =
Expand All @@ -39,7 +39,7 @@ const AgentsView = ({}: any) => {
const sampleAgent: IAgentFlowSpec = {
type: "assistant",
description: "Sample assistant",
user_id: user?.email,
user_id: user?.id,
config: {
name: "sample_assistant",
llm_config: {
Expand All @@ -55,6 +55,7 @@ const AgentsView = ({}: any) => {
human_input_mode: "NEVER",
max_consecutive_auto_reply: 8,
system_message: " ..",
instructions: "",
},
};
const [newAgent, setNewAgent] = React.useState<IAgentFlowSpec | null>(
Expand All @@ -71,7 +72,7 @@ const AgentsView = ({}: any) => {
"Content-Type": "application/json",
},
body: JSON.stringify({
user_id: user?.email,
user_id: user?.id,
agent: agent,
}),
};
Expand Down Expand Up @@ -129,13 +130,13 @@ const AgentsView = ({}: any) => {
// const fetch;

const payLoad = {
method: "POST",
method: "PUT",
headers: {
Accept: "application/json",
"Content-Type": "application/json",
},
body: JSON.stringify({
user_id: user?.email,
user_id: user?.id,
agent: agent,
}),
};
Expand Down
12 changes: 6 additions & 6 deletions frontend/src/components/views/builder/skills.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,9 @@ const SkillsView = ({}: any) => {

const { user } = React.useContext(appContext);
const serverUrl = getServerUrl();
const listSkillsUrl = `${serverUrl}/skills?user_id=${user?.email}`;
const saveSkillsUrl = `${serverUrl}/skills`;
const deleteSkillsUrl = `${serverUrl}/skills/delete`;
const listSkillsUrl = `${serverUrl}/tool?user_id=${user?.id}`;
const saveSkillsUrl = `${serverUrl}/tool/config`;
const deleteSkillsUrl = `${serverUrl}/tool/delete`;

const [skills, setSkills] = React.useState<ISkill[] | null>([]);
const [selectedSkill, setSelectedSkill] = React.useState<any>(null);
Expand All @@ -52,7 +52,7 @@ const SkillsView = ({}: any) => {
"Content-Type": "application/json",
},
body: JSON.stringify({
user_id: user?.email,
user_id: user?.id,
skill: skill,
}),
};
Expand Down Expand Up @@ -115,7 +115,7 @@ const SkillsView = ({}: any) => {
title: newSkillTitle,
file_name: "skill.py",
content: skillCode,
user_id: user?.email,
user_id: user?.id,
};

setError(null);
Expand All @@ -128,7 +128,7 @@ const SkillsView = ({}: any) => {
"Content-Type": "application/json",
},
body: JSON.stringify({
user_id: user?.email,
user_id: user?.id,
skill: skill,
}),
};
Expand Down
12 changes: 6 additions & 6 deletions frontend/src/components/views/builder/workflow.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -29,9 +29,9 @@ const WorkflowView = ({}: any) => {
});
const { user } = React.useContext(appContext);
const serverUrl = getServerUrl();
const listWorkflowsUrl = `${serverUrl}/workflows?user_id=${user?.email}`;
const saveWorkflowsUrl = `${serverUrl}/workflows`;
const deleteWorkflowsUrl = `${serverUrl}/workflows/delete`;
const listWorkflowsUrl = `${serverUrl}/agency?user_id=${user?.id}`;
const saveWorkflowsUrl = `${serverUrl}/agency/config`;
const deleteWorkflowsUrl = `${serverUrl}/agency/delete`;

const [workflows, setWorkflows] = React.useState<IFlowConfig[] | null>([]);
const [selectedWorkflow, setSelectedWorkflow] =
Expand Down Expand Up @@ -84,7 +84,7 @@ const WorkflowView = ({}: any) => {
"Content-Type": "application/json",
},
body: JSON.stringify({
user_id: user?.email,
user_id: user?.id,
workflow: workflow,
}),
};
Expand All @@ -111,13 +111,13 @@ const WorkflowView = ({}: any) => {
setLoading(true);
// const fetch;
const payLoad = {
method: "POST",
method: "PUT",
headers: {
Accept: "application/json",
"Content-Type": "application/json",
},
body: JSON.stringify({
user_id: user?.email,
user_id: user?.id,
workflow: workflow,
}),
};
Expand Down
2 changes: 1 addition & 1 deletion frontend/src/components/views/gallery/gallery.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ const GalleryView = ({ location }: any) => {
const [gallery, setGallery] = React.useState<null | IGalleryItem[]>(null);
const [currentGallery, setCurrentGallery] =
React.useState<null | IGalleryItem>(null);
const listGalleryUrl = `${serverUrl}/gallery?user_id=${user?.email}`;
const listGalleryUrl = `${serverUrl}/gallery?user_id=${user?.id}`;
const [error, setError] = React.useState<IStatus | null>({
status: true,
message: "All good",
Expand Down
6 changes: 3 additions & 3 deletions frontend/src/components/views/playground/chatbox.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ const ChatBox = ({
"Content-Type": "application/json",
},
body: JSON.stringify({
user_id: user?.email,
user_id: user?.id,
msg_id: messageId,
session_id: session?.id,
}),
Expand Down Expand Up @@ -320,12 +320,12 @@ const ChatBox = ({
role: "user",
content: query,
msg_id: userMessage.msg_id,
user_id: user?.email || "",
user_id: user?.id || "",
root_msg_id: "0",
session_id: session?.id || "",
};

const textUrl = `${serverUrl}/messages`;
const textUrl = `${serverUrl}/agency/message`;
const postData = {
method: "POST",
headers: {
Expand Down
2 changes: 1 addition & 1 deletion frontend/src/components/views/playground/ra.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ const RAView = () => {

const { user } = React.useContext(appContext);
const serverUrl = getServerUrl();
const fetchMessagesUrl = `${serverUrl}/messages?user_id=${user?.email}&session_id=${session?.id}`;
const fetchMessagesUrl = `${serverUrl}/messages?user_id=${user?.id}&session_id=${session?.id}`;
const workflowConfig = useConfigStore((state) => state.workflowConfig);

const fetchMessages = () => {
Expand Down
10 changes: 5 additions & 5 deletions frontend/src/components/views/playground/sessions.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ const SessionsView = ({}: any) => {

const { user } = React.useContext(appContext);
const serverUrl = getServerUrl();
const listSessionUrl = `${serverUrl}/sessions?user_id=${user?.email}`;
const listSessionUrl = `${serverUrl}/sessions?user_id=${user?.id}`;
const createSessionUrl = `${serverUrl}/sessions`;
const publishSessionUrl = `${serverUrl}/sessions/publish`;
const deleteSessionUrl = `${serverUrl}/sessions/delete`;
Expand All @@ -45,7 +45,7 @@ const SessionsView = ({}: any) => {
"Content-Type": "application/json",
},
body: JSON.stringify({
user_id: user?.email,
user_id: user?.id,
session: session,
}),
};
Expand Down Expand Up @@ -111,7 +111,7 @@ const SessionsView = ({}: any) => {
setLoading(true);

const body = {
user_id: user?.email,
user_id: user?.id,
session: session,
tags: ["published"],
};
Expand Down Expand Up @@ -156,9 +156,9 @@ const SessionsView = ({}: any) => {
setLoading(true);

const body = {
user_id: user?.email,
user_id: user?.id,
session: {
user_id: user?.email,
user_id: user?.id,
flow_config: workflowConfig,
session_id: null,
},
Expand Down
2 changes: 1 addition & 1 deletion frontend/src/components/views/playground/workflows.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ const AgentsWorkflowView = () => {

const { user } = React.useContext(appContext);
const serverUrl = getServerUrl();
const listWorkflowsUrl = `${serverUrl}/workflows?user_id=${user?.email}`;
const listWorkflowsUrl = `${serverUrl}/agency?user_id=${user?.id}`;

const [workflowConfigs, setWorkflowConfigs] = React.useState<IFlowConfig[]>(
[]
Expand Down
1 change: 1 addition & 0 deletions frontend/src/hooks/provider.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ const Provider = ({ children }: any) => {

// Modify logic here to add your own authentication
const initUser = {
id: "test_user_id",
name: "Guest User",
email: "[email protected]",
username: "guestuser",
Expand Down
35 changes: 35 additions & 0 deletions nalgonda/dependencies/dependencies.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
from fastapi import Depends
from redis import asyncio as aioredis

from nalgonda.persistence.agent_config_firestore_storage import AgentConfigFirestoreStorage
from nalgonda.services.agency_manager import AgencyManager
from nalgonda.services.agent_manager import AgentManager
from nalgonda.services.caching.redis_cache_manager import RedisCacheManager
from nalgonda.services.thread_manager import ThreadManager
from nalgonda.settings import settings


def get_redis() -> aioredis.Redis:
redis_url = str(settings.redis_tls_url or settings.redis_url)
redis = aioredis.from_url(redis_url, decode_responses=False, ssl_cert_reqs="none")
return redis


def get_redis_cache_manager(redis: aioredis.Redis = Depends(get_redis)) -> RedisCacheManager:
return RedisCacheManager(redis)


def get_agent_manager(storage: AgentConfigFirestoreStorage = Depends(AgentConfigFirestoreStorage)) -> AgentManager:
return AgentManager(storage)


def get_agency_manager(
cache_manager: RedisCacheManager = Depends(get_redis_cache_manager),
agent_manager: AgentManager = Depends(get_agent_manager),
) -> AgencyManager:
return AgencyManager(cache_manager, agent_manager)


def get_thread_manager() -> ThreadManager:
"""Returns a ThreadManager object"""
return ThreadManager()
9 changes: 0 additions & 9 deletions nalgonda/dependencies/redis.py

This file was deleted.

Loading

0 comments on commit 675adeb

Please sign in to comment.