Skip to content

Commit

Permalink
Merge branch 'alpha' into feature/openapi-fetch
Browse files Browse the repository at this point in the history
  • Loading branch information
eksno committed Apr 18, 2024
2 parents 0fbe392 + e5b72cc commit 5091677
Show file tree
Hide file tree
Showing 73 changed files with 1,247 additions and 495 deletions.
17 changes: 16 additions & 1 deletion apps/api/poetry.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 2 additions & 0 deletions apps/api/pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,8 @@ selenium = "^4.19.0"
mail = "^2.1.0"
duckduckgo-search = "^5.2.2"
langchain-exa = "^0.0.1"
stackapi = "^0.3.0"
mypy = "^1.9.0"

[tool.poetry.group.dev.dependencies]
mypy = "^1.7.0"
Expand Down
24 changes: 19 additions & 5 deletions apps/api/src/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
from uuid import UUID

import autogen
from fastapi import Depends, FastAPI
from fastapi import Depends, FastAPI
from fastapi.middleware.cors import CORSMiddleware
from fastapi.responses import RedirectResponse

Expand All @@ -18,9 +18,20 @@
)
from .improver import PromptType, improve_prompt
from .interfaces import db
from .models import CrewProcessed
from .models import Profile
from .routers import agents, api_key_types, api_keys
from .routers import auth as auth_router
from .routers import agents, crews, messages, sessions, profiles, api_key_types, rest, api_keys
from .routers import (
billing_information,
crews,
messages,
profiles,
rest,
sessions,
subscriptions,
tiers,
tools,
)

logger = logging.getLogger("root")

Expand All @@ -34,7 +45,11 @@
app.include_router(api_keys.router)
app.include_router(auth_router.router)
app.include_router(api_key_types.router)
app.include_router(tools.router)
app.include_router(subscriptions.router)
app.include_router(rest.router)
app.include_router(tiers.router)
app.include_router(billing_information.router)

app.add_middleware(
CORSMiddleware,
Expand Down Expand Up @@ -97,6 +112,5 @@ def auto_build_crew(general_task: str) -> str:


@app.get("/me")
def get_profile_from_header(current_user=Depends(get_current_user)):
def get_profile_from_header(current_user=Depends(get_current_user)) -> Profile:
return current_user

11 changes: 4 additions & 7 deletions apps/api/src/auth.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,10 @@
import jwt
from dotenv import load_dotenv
from fastapi import Depends, FastAPI, HTTPException, status
from fastapi.security import (
HTTPAuthorizationCredentials,
HTTPBearer,

)
from fastapi.security import HTTPAuthorizationCredentials, HTTPBearer

from src.interfaces import db
from src.models import Profile

load_dotenv()

Expand All @@ -21,7 +18,7 @@
logger = logging.getLogger("root")


async def get_current_user(token: HTTPAuthorizationCredentials = Depends(HTTPBearer())):
async def get_current_user(token: HTTPAuthorizationCredentials = Depends(HTTPBearer())) -> Profile:
credentials_exception = HTTPException(
status_code=status.HTTP_401_UNAUTHORIZED,
detail="Could not validate credentials",
Expand All @@ -43,4 +40,4 @@ async def get_current_user(token: HTTPAuthorizationCredentials = Depends(HTTPBea
if not user_id or not profile:
raise credentials_exception

return profile
return profile
27 changes: 7 additions & 20 deletions apps/api/src/crew.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@

import autogen
from autogen.cache import Cache
from langchain.tools import BaseTool

from src.models.session import SessionStatus

Expand All @@ -18,6 +19,7 @@

logger = logging.getLogger("root")


class AutogenCrew:
def __init__(
self,
Expand All @@ -32,10 +34,8 @@ def __init__(
self.profile_id = profile_id
self.session = session
self.on_reply = on_message
if not self._validate_crew_model(crew_model):
raise ValueError("composition is invalid")
self.crew_model = crew_model
self.valid_tools = []
self.valid_tools: list[BaseTool] = []

self.agents: list[autogen.ConversableAgent | autogen.Agent] = (
self._create_agents(crew_model)
Expand All @@ -58,7 +58,7 @@ def __init__(
)
if self.valid_tools
else None
)
)
self.user_proxy.register_reply([autogen.Agent, None], self._on_reply)

self.base_config_list = autogen.config_list_from_json(
Expand Down Expand Up @@ -131,26 +131,12 @@ async def _on_reply(
]
):
logger.error(
f"on_reply: both ids are none, sender is not admin and recipient is not chat manager"
"on_reply: both ids are none, sender is not admin and recipient is not chat manager"
)

await self.on_reply(recipient_id, sender_id, content, role)
return False, None

def _validate_crew_model(self, crew_model: CrewProcessed) -> bool:
if len(crew_model.agents) == 0:
return False

# Validate agents
for agent in crew_model.agents:
if agent.role == "":
return False
if agent.title == "":
return False
if agent.system_message == "":
return False
return True

def _extract_uuid(self, dictionary: dict[UUID, list[str]]) -> dict[UUID, list[str]]:
new_dict = {}
for key, value in dictionary.items():
Expand Down Expand Up @@ -190,7 +176,7 @@ def _create_agents(

for agent in crew_model.agents:
valid_agent_tools = []
tool_schemas = {}
tool_schemas: list[dict] | None
config_list = autogen.config_list_from_json(
"OAI_CONFIG_LIST",
filter_dict={
Expand All @@ -208,6 +194,7 @@ def _create_agents(
tool, api_key_types, profile_api_keys
)
except TypeError as e:
logger.error(f"tried to generate tool, got error: {e}")
raise e
(
(
Expand Down
1 change: 1 addition & 0 deletions apps/api/src/dependencies/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
if url is None or key is None:
raise ValueError("SUPABASE_URL and SUPABASE_ANON_KEY must be set")


@dataclass
class RateLimitResponse:
limit: int
Expand Down
Loading

0 comments on commit 5091677

Please sign in to comment.