Skip to content

Commit

Permalink
Merge branch 'main' into staging/deploy
Browse files Browse the repository at this point in the history
  • Loading branch information
scott-cohere authored Aug 22, 2024
2 parents ef0f620 + 28d16a9 commit dd5bc56
Show file tree
Hide file tree
Showing 330 changed files with 1,526 additions and 2,444 deletions.
20 changes: 10 additions & 10 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -45,16 +45,16 @@ COPY src/backend src/backend
COPY docker_scripts/ ${PG_APP_HOME}/

# Install frontend dependencies
WORKDIR /workspace/src/interfaces/coral_web
COPY src/interfaces/coral_web/src ./src
COPY src/interfaces/coral_web/public ./public
COPY src/interfaces/coral_web/next.config.mjs .
COPY src/interfaces/coral_web/tsconfig.json .
COPY src/interfaces/coral_web/tailwind.config.js .
COPY src/interfaces/coral_web/postcss.config.js .
COPY src/interfaces/coral_web/package.json src/interfaces/coral_web/yarn.lock* src/interfaces/coral_web/package-lock.json* src/interfaces/coral_web/pnpm-lock.yaml* ./
COPY src/interfaces/coral_web/.env.development .
COPY src/interfaces/coral_web/.env.production .
WORKDIR /workspace/src/interfaces/assistants_web
COPY src/interfaces/assistants_web/src ./src
COPY src/interfaces/assistants_web/public ./public
COPY src/interfaces/assistants_web/next.config.mjs .
COPY src/interfaces/assistants_web/tsconfig.json .
COPY src/interfaces/assistants_web/tailwind.config.js .
COPY src/interfaces/assistants_web/postcss.config.js .
COPY src/interfaces/assistants_web/package.json src/interfaces/assistants_web/yarn.lock* src/interfaces/assistants_web/package-lock.json* src/interfaces/assistants_web/pnpm-lock.yaml* ./
COPY src/interfaces/assistants_web/.env.development .
COPY src/interfaces/assistants_web/.env.production .

ENV NEXT_PUBLIC_API_HOSTNAME='/api'
RUN npm install \
Expand Down
10 changes: 5 additions & 5 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ exec-db:

.PHONY: migration
migration:
docker compose run --build backend alembic -c src/backend/alembic.ini revision --autogenerate
docker compose run --build backend alembic -c src/backend/alembic.ini revision --autogenerate -m "$(message)"

.PHONY: migrate
migrate:
Expand Down Expand Up @@ -100,19 +100,19 @@ win-first-run:

.PHONY: format-web
format-web:
cd src/interfaces/coral_web && npm run format:write
cd src/interfaces/assistants_web && npm run format:write

.PHONY: generate-client-web
generate-client-web:
cd src/interfaces/coral_web && npm run generate:client && npm run format:write
cd src/interfaces/assistants_web && npm run generate:client && npm run format:write

.PHONY: install-web
install-web:
cd src/interfaces/coral_web && npm install
cd src/interfaces/assistants_web && npm install

.PHONY: build-web
build-web:
cd src/interfaces/coral_web && npm run build
cd src/interfaces/assistants_web && npm run build

.PHONY: test-db
test-db:
Expand Down
4 changes: 2 additions & 2 deletions docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,7 @@ services:
frontend:
build:
target: ${BUILD_TARGET:-prod}
context: ./src/interfaces/coral_web
context: ./src/interfaces/assistants_web
dockerfile: Dockerfile
# Set environment variables directly in the docker-compose file
environment:
Expand All @@ -158,7 +158,7 @@ services:
develop:
watch:
- action: sync
path: ./src/interfaces/coral_web
path: ./src/interfaces/assistants_web
target: /app
ignore:
- node_modules/
Expand Down
4 changes: 2 additions & 2 deletions docker_scripts/functions
Original file line number Diff line number Diff line change
Expand Up @@ -270,14 +270,14 @@ run_backend_poetry() {
}

run_frontend_proxy() {
cd /workspace/src/interfaces/coral_web
cd /workspace/src/interfaces/assistants_web
echo "Starting Frontend..."
pm2 start npm -- run -- start:single-docker-proxy
echo "Frontend started..."
}

run_frontend() {
cd /workspace/src/interfaces/coral_web
cd /workspace/src/interfaces/assistants_web
echo "Building Frontend"
npm run next:build
echo "Starting Frontend..."
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
"""Remove file path
Revision ID: 08bcb9a24d9b
Revises: c301506b3676
Create Date: 2024-08-21 15:59:18.678457
"""
from typing import Sequence, Union

import sqlalchemy as sa
from alembic import op

# revision identifiers, used by Alembic.
revision: str = '08bcb9a24d9b'
down_revision: Union[str, None] = 'c301506b3676'
branch_labels: Union[str, Sequence[str], None] = None
depends_on: Union[str, Sequence[str], None] = None


def upgrade() -> None:
# ### commands auto generated by Alembic - please adjust! ###
op.drop_column('files', 'file_path')
# ### end Alembic commands ###


def downgrade() -> None:
# ### commands auto generated by Alembic - please adjust! ###
op.add_column('files', sa.Column('file_path', sa.VARCHAR(), autoincrement=False, nullable=False))
# ### end Alembic commands ###
11 changes: 10 additions & 1 deletion src/backend/chat/custom/tool_calls.py
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,16 @@ async def _call_tool_async(
) -> List[Dict[str, Any]]:
tool = AVAILABLE_TOOLS.get(tool_call["name"])
if not tool:
return []
logger.info(
event=f"[Custom Chat] Tool not included in tools parameter: {tool_call['name']}",
)
outputs = [
{
"call": tool_call,
"outputs": [{"text": f"Tool {tool_call['name']} not found", "success": False}],
}
]
return outputs

try:
outputs = await tool.implementation().call(
Expand Down
4 changes: 2 additions & 2 deletions src/backend/config/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,7 @@ class CompassSettings(BaseSettings, BaseModel):
)


class WebSearchSettings(BaseSettings, BaseModel):
class TavilySearchSettings(BaseSettings, BaseModel):
model_config = SETTINGS_CONFIG
api_key: Optional[str] = Field(
default=None, validation_alias=AliasChoices("TAVILY_API_KEY", "api_key")
Expand Down Expand Up @@ -185,7 +185,7 @@ class ToolSettings(BaseSettings, BaseModel):
python_interpreter: Optional[PythonToolSettings] = Field(
default=PythonToolSettings()
)
web_search: Optional[WebSearchSettings] = Field(default=WebSearchSettings())
tavily: Optional[TavilySearchSettings] = Field(default=TavilySearchSettings())
wolfram_alpha: Optional[WolframAlphaSettings] = Field(
default=WolframAlphaSettings()
)
Expand Down
31 changes: 30 additions & 1 deletion src/backend/crud/agent_tool_metadata.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ def create_agent_tool_metadata(

def get_agent_tool_metadata_by_id(
db: Session, agent_tool_metadata_id: str
) -> AgentToolMetadata:
) -> AgentToolMetadata | None:
"""
Get a agent tool metadata by its ID.
Expand Down Expand Up @@ -61,6 +61,35 @@ def get_all_agent_tool_metadata_by_agent_id(
)


def get_agent_tool_metadata(
db: Session,
agent_id: str,
tool_name: str,
user_id: str,
) -> AgentToolMetadata | None:
"""
Get a agent tool metadata.
Args:
db (Session): Database session.
agent_id (str): Agent ID.
tool_name (str): Tool name.
user_id (str): User ID.
Returns:
AgentToolMetadata: Agent tool metadata.
"""
return (
db.query(AgentToolMetadata)
.filter(
AgentToolMetadata.agent_id == agent_id,
AgentToolMetadata.tool_name == tool_name,
AgentToolMetadata.user_id == user_id,
)
.first()
)


def update_agent_tool_metadata(
db: Session,
agent_tool_metadata: AgentToolMetadata,
Expand Down
1 change: 0 additions & 1 deletion src/backend/database_models/file.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ class File(Base):

user_id: Mapped[str] = mapped_column(String, nullable=True)
file_name: Mapped[str]
file_path: Mapped[str]
file_size: Mapped[int] = mapped_column(default=0)
file_content: Mapped[str] = mapped_column(default="")

Expand Down
4 changes: 0 additions & 4 deletions src/backend/model_deployments/bedrock.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,10 +33,6 @@ class BedrockDeployment(BaseDeployment):

def __init__(self, **kwargs: Any):
self.client = cohere.BedrockClient(
# TODO: remove hardcoded models once the SDK is updated
chat_model="cohere.command-r-plus-v1:0",
embed_model="cohere.embed-multilingual-v3",
generate_model="cohere.command-text-v14",
aws_access_key=get_model_config_var(
BEDROCK_ACCESS_KEY_ENV_VAR, BedrockDeployment.access_key, **kwargs
),
Expand Down
78 changes: 39 additions & 39 deletions src/backend/routers/agent.py
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,7 @@ async def create_agent(
}
)
if file_ids:
await consolidate_agent_files_in_compass(file_ids, created_agent.id)
await consolidate_agent_files_in_compass(file_ids, created_agent.id, ctx)

if deployment_db and model_db:
deployment_config = (
Expand Down Expand Up @@ -384,6 +384,43 @@ async def update_agent(
return agent


@router.delete("/{agent_id}", response_model=DeleteAgent)
async def delete_agent(
agent_id: str,
session: DBSessionDep,
ctx: Context = Depends(get_context),
) -> DeleteAgent:
"""
Delete an agent by ID.
Args:
agent_id (str): Agent ID.
session (DBSessionDep): Database session.
ctx (Context): Context object.
Returns:
DeleteAgent: Empty response.
Raises:
HTTPException: If the agent with the given ID is not found.
"""
user_id = ctx.get_user_id()
ctx.with_event_type(MetricsMessageType.ASSISTANT_DELETED)
agent = validate_agent_exists(session, agent_id, user_id)
agent_schema = Agent.model_validate(agent)
ctx.with_agent(agent_schema)
ctx.with_metrics_agent(agent_to_metrics_agent(agent))

deleted = agent_crud.delete_agent(session, agent_id, user_id)
if not deleted:
raise HTTPException(status_code=401, detail="Could not delete Agent.")

return DeleteAgent()


# Agent Tool Metadata endpoints


async def handle_tool_metadata_update(
agent: Agent,
new_agent: Agent,
Expand Down Expand Up @@ -453,43 +490,6 @@ async def update_or_create_tool_metadata(
create_agent_tool_metadata(session, agent.id, create_metadata_req, ctx)


@router.delete("/{agent_id}", response_model=DeleteAgent)
async def delete_agent(
agent_id: str,
session: DBSessionDep,
ctx: Context = Depends(get_context),
) -> DeleteAgent:
"""
Delete an agent by ID.
Args:
agent_id (str): Agent ID.
session (DBSessionDep): Database session.
ctx (Context): Context object.
Returns:
DeleteAgent: Empty response.
Raises:
HTTPException: If the agent with the given ID is not found.
"""
user_id = ctx.get_user_id()
ctx.with_event_type(MetricsMessageType.ASSISTANT_DELETED)
agent = validate_agent_exists(session, agent_id, user_id)
agent_schema = Agent.model_validate(agent)
ctx.with_agent(agent_schema)
ctx.with_metrics_agent(agent_to_metrics_agent(agent))

deleted = agent_crud.delete_agent(session, agent_id, user_id)
if not deleted:
raise HTTPException(status_code=401, detail="Could not delete Agent.")

return DeleteAgent()


# Tool Metadata Endpoints


@router.get("/{agent_id}/tool-metadata", response_model=list[AgentToolMetadataPublic])
async def list_agent_tool_metadata(
agent_id: str, session: DBSessionDep, ctx: Context = Depends(get_context)
Expand Down Expand Up @@ -539,7 +539,7 @@ def create_agent_tool_metadata(
ctx (Context): Context object.
Returns:
AgentToolMetadata: Created agent tool metadata.
AgentToolMetadataPublic: Created agent tool metadata.
Raises:
HTTPException: If the agent tool metadata creation fails.
Expand Down
8 changes: 3 additions & 5 deletions src/backend/schemas/file.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import datetime
from typing import Optional

from pydantic import BaseModel, Field

Expand All @@ -9,10 +10,9 @@ class File(BaseModel):
updated_at: datetime.datetime

user_id: str
conversation_id: str
file_content: str
conversation_id: Optional[str] = ""
file_content: Optional[str] = ""
file_name: str
file_path: str
file_size: int = Field(default=0, ge=0)

class Config:
Expand All @@ -26,7 +26,6 @@ class ConversationFilePublic(BaseModel):

conversation_id: str
file_name: str
file_path: str
file_size: int = Field(default=0, ge=0)


Expand All @@ -37,7 +36,6 @@ class AgentFilePublic(BaseModel):
updated_at: datetime.datetime

file_name: str
file_path: str
file_size: int = Field(default=0, ge=0)

class ListConversationFile(ConversationFilePublic):
Expand Down
Loading

0 comments on commit dd5bc56

Please sign in to comment.