Skip to content

Commit

Permalink
wip (#180)
Browse files Browse the repository at this point in the history
Co-authored-by: Kumaran Rajendhiran <[email protected]>
  • Loading branch information
davorrunje and kumaranvpl authored Sep 11, 2024
1 parent 299806b commit 98f57c2
Show file tree
Hide file tree
Showing 50 changed files with 135 additions and 115 deletions.
36 changes: 19 additions & 17 deletions docs/docs/SUMMARY.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,24 @@ search:
- Reference
- fastagency
- [FastAgency](api/fastagency/FastAgency.md)
- api
- openapi
- [OpenAPI](api/fastagency/api/openapi/OpenAPI.md)
- client
- [OpenAPI](api/fastagency/api/openapi/client/OpenAPI.md)
- [add_to_globals](api/fastagency/api/openapi/client/add_to_globals.md)
- fastapi_code_generator_helpers
- [ArgumentWithDescription](api/fastagency/api/openapi/fastapi_code_generator_helpers/ArgumentWithDescription.md)
- [patch_get_parameter_type](api/fastagency/api/openapi/fastapi_code_generator_helpers/patch_get_parameter_type.md)
- security
- [APIKeyCookie](api/fastagency/api/openapi/security/APIKeyCookie.md)
- [APIKeyHeader](api/fastagency/api/openapi/security/APIKeyHeader.md)
- [APIKeyQuery](api/fastagency/api/openapi/security/APIKeyQuery.md)
- [BaseSecurity](api/fastagency/api/openapi/security/BaseSecurity.md)
- [BaseSecurityParameters](api/fastagency/api/openapi/security/BaseSecurityParameters.md)
- [HTTPBearer](api/fastagency/api/openapi/security/HTTPBearer.md)
- security_schema_visitor
- [custom_visitor](api/fastagency/api/openapi/security_schema_visitor/custom_visitor.md)
- cli
- cli
- [callback](api/fastagency/cli/cli/callback.md)
Expand Down Expand Up @@ -103,22 +121,6 @@ search:
- [IOStreamAdapter](api/fastagency/core/runtimes/autogen/base/IOStreamAdapter.md)
- logging
- [get_logger](api/fastagency/logging/get_logger.md)
- openapi
- client
- [Client](api/fastagency/openapi/client/Client.md)
- [add_to_globals](api/fastagency/openapi/client/add_to_globals.md)
- fastapi_code_generator_helpers
- [ArgumentWithDescription](api/fastagency/openapi/fastapi_code_generator_helpers/ArgumentWithDescription.md)
- [patch_get_parameter_type](api/fastagency/openapi/fastapi_code_generator_helpers/patch_get_parameter_type.md)
- security
- [APIKeyCookie](api/fastagency/openapi/security/APIKeyCookie.md)
- [APIKeyHeader](api/fastagency/openapi/security/APIKeyHeader.md)
- [APIKeyQuery](api/fastagency/openapi/security/APIKeyQuery.md)
- [BaseSecurity](api/fastagency/openapi/security/BaseSecurity.md)
- [BaseSecurityParameters](api/fastagency/openapi/security/BaseSecurityParameters.md)
- [HTTPBearer](api/fastagency/openapi/security/HTTPBearer.md)
- security_schema_visitor
- [custom_visitor](api/fastagency/openapi/security_schema_visitor/custom_visitor.md)
- studio
- app
- [ChatRequest](api/fastagency/studio/app/ChatRequest.md)
Expand Down Expand Up @@ -253,7 +255,7 @@ search:
- [TwoAgentTeam](api/fastagency/studio/models/teams/two_agent_teams/TwoAgentTeam.md)
- toolboxes
- toolbox
- [Client](api/fastagency/studio/models/toolboxes/toolbox/Client.md)
- [OpenAPI](api/fastagency/studio/models/toolboxes/toolbox/OpenAPI.md)
- [OpenAPIAuth](api/fastagency/studio/models/toolboxes/toolbox/OpenAPIAuth.md)
- [OpenAPIAuthToken](api/fastagency/studio/models/toolboxes/toolbox/OpenAPIAuthToken.md)
- [Toolbox](api/fastagency/studio/models/toolboxes/toolbox/Toolbox.md)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,4 @@ search:
boost: 0.5
---

::: fastagency.openapi.client.Client
::: fastagency.api.openapi.OpenAPI
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,4 @@ search:
boost: 0.5
---

::: fastagency.openapi.client.Client
::: fastagency.api.openapi.client.OpenAPI
11 changes: 11 additions & 0 deletions docs/docs/en/api/fastagency/api/openapi/client/add_to_globals.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
---
# 0.5 - API
# 2 - Release
# 3 - Contributing
# 5 - Template Page
# 10 - Default
search:
boost: 0.5
---

::: fastagency.api.openapi.client.add_to_globals
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,4 @@ search:
boost: 0.5
---

::: fastagency.openapi.fastapi_code_generator_helpers.ArgumentWithDescription
::: fastagency.api.openapi.fastapi_code_generator_helpers.ArgumentWithDescription
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,4 @@ search:
boost: 0.5
---

::: fastagency.openapi.fastapi_code_generator_helpers.patch_get_parameter_type
::: fastagency.api.openapi.fastapi_code_generator_helpers.patch_get_parameter_type
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,4 @@ search:
boost: 0.5
---

::: fastagency.openapi.security.APIKeyCookie
::: fastagency.api.openapi.security.APIKeyCookie
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,4 @@ search:
boost: 0.5
---

::: fastagency.openapi.security.APIKeyHeader
::: fastagency.api.openapi.security.APIKeyHeader
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,4 @@ search:
boost: 0.5
---

::: fastagency.openapi.security.APIKeyQuery
::: fastagency.api.openapi.security.APIKeyQuery
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,4 @@ search:
boost: 0.5
---

::: fastagency.openapi.security.BaseSecurity
::: fastagency.api.openapi.security.BaseSecurity
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,4 @@ search:
boost: 0.5
---

::: fastagency.openapi.security.BaseSecurityParameters
::: fastagency.api.openapi.security.BaseSecurityParameters
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,4 @@ search:
boost: 0.5
---

::: fastagency.openapi.client.add_to_globals
::: fastagency.api.openapi.security.HTTPBearer
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,4 @@ search:
boost: 0.5
---

::: fastagency.openapi.security_schema_visitor.custom_visitor
::: fastagency.api.openapi.security_schema_visitor.custom_visitor
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,4 @@ search:
boost: 0.5
---

::: fastagency.openapi.security.HTTPBearer
::: fastagency.api.openapi.client.OpenAPI
10 changes: 6 additions & 4 deletions docs/docs_src/tutorial/external_rest_apis/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,9 @@
from fastagency.core import Chatable
from fastagency.core.io.console import ConsoleIO
from fastagency.core.runtimes.autogen.base import AutoGenWorkflows
from fastagency.openapi.client import Client

from fastagency.api.openapi import OpenAPI


llm_config = {
"config_list": [
Expand All @@ -27,7 +29,7 @@
@wf.register(name="simple_weather", description="Weather chat")
def weather_workflow(io: Chatable, initial_message: str, session_id: str) -> str:

weather_client = Client.create(openapi_url=WEATHER_OPENAPI_URL)
weather_api = OpenAPI.create(openapi_url=WEATHER_OPENAPI_URL)

user_agent = UserProxyAgent(
name="User_Agent",
Expand All @@ -42,8 +44,8 @@ def weather_workflow(io: Chatable, initial_message: str, session_id: str) -> str
human_input_mode="NEVER",
)

weather_client.register_for_llm(weather_agent)
weather_client.register_for_execution(user_agent)
weather_api.register_for_llm(weather_agent)
weather_api.register_for_execution(user_agent)

chat_result = user_agent.initiate_chat(
weather_agent,
Expand Down
6 changes: 3 additions & 3 deletions docs/docs_src/tutorial/external_rest_apis/security.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@
from fastagency.core import Chatable
from fastagency.core.io.console import ConsoleIO
from fastagency.core.runtimes.autogen.base import AutoGenWorkflows
from fastagency.openapi.client import Client
from fastagency.openapi.security import APIKeyHeader
from fastagency.api.openapi.client import OpenAPI
from fastagency.api.openapi.security import APIKeyHeader

llm_config = {
"config_list": [
Expand All @@ -28,7 +28,7 @@
@wf.register(name="simple_weather_with_security", description="Weather chat with security")
def weather_workflow_with_security(io: Chatable, initial_message: str, session_id: str) -> str:

weather_client = Client.create(openapi_url=WEATHER_OPENAPI_URL)
weather_client = OpenAPI.create(openapi_url=WEATHER_OPENAPI_URL)

# Set global security params for all methods
weather_client.set_security_params(APIKeyHeader.Parameters(value="secure weather key"))
Expand Down
6 changes: 3 additions & 3 deletions examples/cli/main_user_proxy.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@
from fastagency.core import Chatable
from fastagency.core.io.console import ConsoleIO
from fastagency.core.runtimes.autogen.base import AutoGenWorkflows
from fastagency.openapi.client import Client
from fastagency.openapi.security import APIKeyHeader
from fastagency.api.openapi.client import OpenAPI
from fastagency.api.openapi.security import APIKeyHeader

from fastagency import FastAgency

Expand Down Expand Up @@ -36,7 +36,7 @@ def simple_workflow(io: Chatable, initial_message: str, session_id: str) -> str:
llm_config=llm_config,
)

weather_client = Client.create(openapi_url="https://weather.tools.fastagency.ai/openapi.json")
weather_client = OpenAPI.create(openapi_url="https://weather.tools.fastagency.ai/openapi.json")
# Set global security params for all methods
weather_client.set_security_params(APIKeyHeader.Parameters(value="secure weather key"))

Expand Down
File renamed without changes.
3 changes: 3 additions & 0 deletions fastagency/api/openapi/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
from .client import OpenAPI

__all__ = ["OpenAPI"]
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
if TYPE_CHECKING:
from autogen.agentchat import ConversableAgent

__all__ = ["Client"]
__all__ = ["OpenAPI"]


@contextmanager
Expand All @@ -43,7 +43,7 @@ def add_to_globals(new_globals: dict[str, Any]) -> Iterator[None]:
globals()[key] = value


class Client:
class OpenAPI:
def __init__(
self, servers: list[dict[str, Any]], title: Optional[str] = None, **kwargs: Any
) -> None:
Expand Down Expand Up @@ -80,7 +80,7 @@ def _get_params(
def _process_params(
self, path: str, func: Callable[[Any], Any], **kwargs: Any
) -> tuple[str, dict[str, Any], dict[str, Any]]:
q_params, path_params, body, security = Client._get_params(path, func)
q_params, path_params, body, security = OpenAPI._get_params(path, func)

expanded_path = path.format(**{p: kwargs[p] for p in path_params})

Expand Down Expand Up @@ -199,7 +199,7 @@ def delete(self, path: str, **kwargs: Any) -> Callable[..., dict[str, Any]]:

@classmethod
def _get_template_dir(cls) -> Path:
path = Path(__file__).parents[2] / "templates"
path = Path(__file__).parents[3] / "templates"
if not path.exists():
raise RuntimeError(f"Template directory {path.resolve()} not found.")
return path
Expand Down Expand Up @@ -259,7 +259,7 @@ def set_globals(self, main: ModuleType, suffix: str) -> None:
@classmethod
def create(
cls, openapi_json: Optional[str] = None, openapi_url: Optional[str] = None
) -> "Client":
) -> "OpenAPI":
if openapi_json is None and openapi_url is None:
raise ValueError("Either openapi_json or openapi_url should be provided")

Expand All @@ -283,7 +283,7 @@ def create(
finally:
sys.path.remove(str(td))

client: Client = main.app # type: ignore [attr-defined]
client: OpenAPI = main.app # type: ignore [attr-defined]
client.set_globals(main, suffix=suffix)

return client
Expand Down
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
from fastapi_code_generator.parser import OpenAPIParser
from fastapi_code_generator.visitor import Visitor

from fastagency.openapi.security import BaseSecurity
from fastagency.api.openapi.security import BaseSecurity


def custom_visitor(parser: OpenAPIParser, model_path: Path) -> dict[str, object]:
Expand Down
4 changes: 2 additions & 2 deletions fastagency/studio/models/agents/assistant.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
import autogen
from pydantic import Field

from ....openapi.client import Client
from ....api.openapi import OpenAPI
from ..registry import register
from .base import AgentBaseModel

Expand All @@ -21,7 +21,7 @@ class AssistantAgent(AgentBaseModel):
@classmethod
async def create_autogen(
cls, model_id: UUID, user_id: UUID, **kwargs: Any
) -> tuple[autogen.agentchat.AssistantAgent, list[Client]]:
) -> tuple[autogen.agentchat.AssistantAgent, list[OpenAPI]]:
my_model = await cls.from_db(model_id)

llm_model = await my_model.llm.get_data_model().from_db(my_model.llm.uuid)
Expand Down
6 changes: 3 additions & 3 deletions fastagency/studio/models/agents/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
from pydantic import Field
from typing_extensions import TypeAlias

from fastagency.openapi.client import Client
from fastagency.api.openapi import OpenAPI

from ..base import Model
from ..registry import Registry
Expand Down Expand Up @@ -51,8 +51,8 @@ class AgentBaseModel(Model):
),
] = None

async def get_clients_from_toolboxes(self, user_id: UUID) -> list[Client]:
clients: list[Client] = []
async def get_clients_from_toolboxes(self, user_id: UUID) -> list[OpenAPI]:
clients: list[OpenAPI] = []
for i in range(3):
toolbox_property = getattr(self, f"toolbox_{i+1}")
if toolbox_property is None:
Expand Down
4 changes: 2 additions & 2 deletions fastagency/studio/models/agents/user_proxy.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
import autogen
from pydantic import Field

from ....openapi.client import Client
from ....api.openapi import OpenAPI
from ..base import Model
from ..registry import register

Expand All @@ -21,7 +21,7 @@ class UserProxyAgent(Model):
@classmethod
async def create_autogen(
cls, model_id: UUID, user_id: UUID, **kwargs: Any
) -> tuple[autogen.agentchat.AssistantAgent, list[Client]]:
) -> tuple[autogen.agentchat.AssistantAgent, list[OpenAPI]]:
my_model = await cls.from_db(model_id)

agent_name = my_model.name
Expand Down
4 changes: 2 additions & 2 deletions fastagency/studio/models/teams/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

from ..base import Model
from ..registry import Registry
from ..toolboxes.toolbox import Client
from ..toolboxes.toolbox import OpenAPI

__all__ = ["TeamBaseModel", "agent_type_refs"]

Expand Down Expand Up @@ -45,7 +45,7 @@ def is_termination_msg(self, msg: dict[str, Any]) -> bool:
def register_toolbox_functions(
agent: ConversableAgent,
execution_agents: list[ConversableAgent],
clients: list[Client],
clients: list[OpenAPI],
) -> None:
for client in clients:
client.register_for_llm(agent)
Expand Down
6 changes: 3 additions & 3 deletions fastagency/studio/models/teams/multi_agent_team.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
from pydantic import Field

from ..registry import Registry
from ..toolboxes.toolbox import Client
from ..toolboxes.toolbox import OpenAPI
from .base import TeamBaseModel, agent_type_refs, register_toolbox_functions

__all__ = ["MultiAgentTeam"]
Expand All @@ -16,7 +16,7 @@
class AutogenMultiAgentTeam:
def __init__(
self,
agents_and_clients: list[tuple[ConversableAgent, list[Client]]],
agents_and_clients: list[tuple[ConversableAgent, list[OpenAPI]]],
) -> None:
self.agents = [agent for agent, _ in agents_and_clients]
self.clients = [clients for _, clients in agents_and_clients]
Expand Down Expand Up @@ -79,7 +79,7 @@ class MultiAgentTeam(TeamBaseModel):
async def create_autogen(cls, model_id: UUID, user_id: UUID, **kwargs: Any) -> Any:
my_model = await cls.from_db(model_id)

agents_and_clients: list[tuple[ConversableAgent, list[Client]]] = []
agents_and_clients: list[tuple[ConversableAgent, list[OpenAPI]]] = []
for i in range(5):
agent_property = getattr(my_model, f"agent_{i+1}")
if agent_property is None:
Expand Down
Loading

0 comments on commit 98f57c2

Please sign in to comment.