Skip to content

Commit

Permalink
shore(backend): cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
ezawadski committed Jan 13, 2025
1 parent d2e3353 commit ee89fe9
Show file tree
Hide file tree
Showing 6 changed files with 57 additions and 120 deletions.
27 changes: 0 additions & 27 deletions src/backend/routers/chat.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,15 +37,6 @@ async def chat_stream(
) -> Generator[ChatResponseEvent, Any, None]:
"""
Stream chat endpoint to handle user messages and return chatbot responses.
Args:
session (DBSessionDep): Database session.
chat_request (CohereChatRequest): Chat request data.
request (Request): Request object.
ctx (Context): Context object.
Returns:
EventSourceResponse: Server-sent event response with chatbot responses.
"""
ctx.with_model(chat_request.model)
agent_id = chat_request.agent_id
Expand Down Expand Up @@ -92,15 +83,6 @@ async def regenerate_chat_stream(
) -> EventSourceResponse:
"""
Endpoint to regenerate stream chat response for the last user message.
Args:
session (DBSessionDep): Database session.
chat_request (CohereChatRequest): Chat request data.
request (Request): Request object.
ctx (Context): Context object.
Returns:
EventSourceResponse: Server-sent event response with chatbot responses.
"""
ctx.with_model(chat_request.model)

Expand Down Expand Up @@ -161,15 +143,6 @@ async def chat(
) -> NonStreamedChatResponse:
"""
Chat endpoint to handle user messages and return chatbot responses.
Args:
chat_request (CohereChatRequest): Chat request data.
session (DBSessionDep): Database session.
request (Request): Request object.
ctx (Context): Context object.
Returns:
NonStreamedChatResponse: Chatbot response.
"""
ctx.with_model(chat_request.model)
agent_id = chat_request.agent_id
Expand Down
45 changes: 0 additions & 45 deletions src/backend/routers/organization.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,13 +37,6 @@ def create_organization(
) -> Organization:
"""
Create a new organization.
Args:
organization (CreateOrganization): Organization data
session (DBSessionDep): Database session.
Returns:
Organization: Created organization.
"""
organization_data = OrganizationModel(**organization.dict())

Expand All @@ -65,15 +58,6 @@ def update_organization(
) -> Organization:
"""
Update organization by ID.
Args:
organization_id (str): Tool ID.
new_organization (ToolUpdate): New organization data.
session (DBSessionDep): Database session.
Returns:
Organization: Updated organization.
"""
organization = organization_crud.get_organization(session, organization_id)
return organization_crud.update_organization(
Expand All @@ -89,14 +73,6 @@ def get_organization(
) -> Organization:
"""
Get a organization by ID.
Args:
organization_id (str): Tool ID.
session (DBSessionDep): Database session.
ctx: Context.
Returns:
Organization: Organization with the given ID.
"""
organization = organization_crud.get_organization(session, organization_id)
if not organization:
Expand All @@ -112,13 +88,6 @@ def delete_organization(
) -> DeleteOrganization:
"""
Delete a organization by ID.
Args:
organization_id (str): Tool ID.
session (DBSessionDep): Database session.
Returns:
DeleteOrganization: Organization deleted.
"""
organization = organization_crud.get_organization(session, organization_id)
if not organization:
Expand All @@ -135,13 +104,6 @@ def list_organizations(
) -> list[Organization]:
"""
List all available organizations.
Args:
request (Request): Request object.
session (DBSessionDep): Database session.
Returns:
list[Organization]: List of available organizations.
"""
all_organizations = organization_crud.get_organizations(session)
return all_organizations
Expand All @@ -155,13 +117,6 @@ def get_organization_users(
) -> list[User]:
"""
Get organization users by ID.
Args:
organization_id (str): Organization ID.
session (DBSessionDep): Database session.
Returns:
list[User]: List of users in the organization
"""
organization = organization_crud.get_organization(session, organization_id)
if not organization:
Expand Down
39 changes: 0 additions & 39 deletions src/backend/routers/snapshot.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,14 +43,6 @@ async def create_snapshot(
) -> CreateSnapshotResponse:
"""
Create a new snapshot and snapshot link to share the conversation.
Args:
snapshot_request (CreateSnapshotRequest): Snapshot creation request.
session (DBSessionDep): Database session.
ctx (Context): Context object.
Returns:
CreateSnapshotResponse: Snapshot creation response.
"""
user_id = ctx.get_user_id()
conversation_id = snapshot_request.conversation_id
Expand Down Expand Up @@ -85,13 +77,6 @@ async def list_snapshots(
) -> list[SnapshotWithLinks]:
"""
List all snapshots.
Args:
session (DBSessionDep): Database session.
ctx (Context): Context object.
Returns:
list[SnapshotWithLinks]: List of all snapshots with their links.
"""
user_id = ctx.get_user_id()

Expand Down Expand Up @@ -119,14 +104,6 @@ async def get_snapshot(
) -> SnapshotPublic:
"""
Get a snapshot by link ID.
Args:
link_id (str): Snapshot link ID.
session (DBSessionDep): Database session.
ctx (Context): Context object.
Returns:
Snapshot: Snapshot with the given link ID.
"""
user_id = ctx.get_user_id()

Expand All @@ -145,14 +122,6 @@ async def delete_snapshot_link(
) -> DeleteSnapshotLinkResponse:
"""
Delete a snapshot link by ID.
Args:
link_id (str): Snapshot link ID.
session (DBSessionDep): Database session.
ctx (Context): Context object.
Returns:
DeleteSnapshotLinkResponse: Empty response.
"""
user_id = ctx.get_user_id()

Expand All @@ -178,14 +147,6 @@ async def delete_snapshot(
) -> DeleteSnapshotResponse:
"""
Delete a snapshot by ID.
Args:
snapshot_id (str): Snapshot ID.
session (DBSessionDep): Database session.
ctx (Context): Context object.
Returns:
DeleteSnapshotResponse: Empty response.
"""
user_id = ctx.get_user_id()

Expand Down
43 changes: 35 additions & 8 deletions src/backend/schemas/document.py
Original file line number Diff line number Diff line change
@@ -1,16 +1,43 @@
from typing import Union
from typing import Optional

from pydantic import BaseModel
from pydantic import BaseModel, Field


class Document(BaseModel):
text: str
document_id: str
"""
Schema for a Document
"""
text: str = Field(
...,
title="Text",
description="Document text",
)
document_id: str = Field(
...,
title="Document_Id",
description="Unique Identifier for the document",
)

title: Union[str, None]
url: Union[str, None]
fields: Union[dict, None]
tool_name: Union[str, None]
title: Optional[str] = Field(
None,
title="Title",
description="Document title",
)
url: Optional[str] = Field(
None,
title="URL",
description="Document URL",
)
fields: Optional[dict] = Field(
None,
title="Fields",
description="Document Fields",
)
tool_name: Optional[str] = Field(
None,
title="Tool Name",
description="Tool name for the document",
)

class Config:
from_attributes = True
8 changes: 7 additions & 1 deletion src/backend/schemas/message.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@

class MessageBase(ABC, BaseModel):
"""
Aabstract class for Message schemas
Abstract class for Message schemas
"""
text: str = Field(
...,
Expand All @@ -23,6 +23,9 @@ class MessageBase(ABC, BaseModel):


class Message(MessageBase):
"""
Message Schema
"""
id: str = Field(
...,
title="ID",
Expand Down Expand Up @@ -93,6 +96,9 @@ class Config:


class UpdateMessage(BaseModel):
"""
Request to update a message
"""
text: Optional[str] = Field(
None,
title="Text",
Expand Down
15 changes: 15 additions & 0 deletions src/backend/schemas/tool.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,19 @@


class ToolCategory(StrEnum):
"""
Supported Tool Categories
"""
DataLoader = "Data loader"
FileLoader = "File loader"
Function = "Function"
WebSearch = "Web search"


class Tool(BaseModel):
"""
Tool Schema
"""
name: Optional[str] = Field(
"",
title="Name",
Expand All @@ -24,6 +30,9 @@ class Tool(BaseModel):
)

class ToolDefinition(Tool):
"""
Tool Definition Schema
"""
display_name: str = Field(
"",
title="Display Name",
Expand Down Expand Up @@ -99,6 +108,9 @@ class Config:


class ToolCall(BaseModel):
"""
Schema for Tool Call
"""
name: str = Field(
...,
title="Name",
Expand All @@ -115,6 +127,9 @@ class Config:


class ToolCallDelta(BaseModel):
"""
Schema for Tool Call Delta
"""
name: Optional[str] = Field(
None,
title="Name",
Expand Down

0 comments on commit ee89fe9

Please sign in to comment.