Skip to content

Commit

Permalink
Merge branch 'main' of github.com:cohere-ai/cohere-toolkit into assis…
Browse files Browse the repository at this point in the history
…tants/deploy
  • Loading branch information
BeatrixCohere committed Jul 16, 2024
2 parents ec07f09 + 16c780b commit 5115174
Show file tree
Hide file tree
Showing 90 changed files with 18,382 additions and 3,951 deletions.
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
name: Interface Tests
name: Coral Web Tests

on:
push:
Expand Down
44 changes: 44 additions & 0 deletions .github/workflows/slack_bot_tests.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
name: Slack Bot Tests

on:
push:
branches: [main]
paths:
- src/interfaces/slack_bot/**
pull_request: {}
merge_group: {}

jobs:
interface_tests:
runs-on: ubuntu-latest
defaults:
run:
working-directory: src/interfaces/slack_bot
steps:
- name: Checkout repo
uses: actions/checkout@v3
with:
fetch-depth: 2
- uses: pnpm/action-setup@v4
name: Install pnpm
with:
version: 9
run_install: false
- name: Install Node.js
uses: actions/setup-node@v4
with:
node-version-file: "src/interfaces/slack_bot/.nvmrc"
cache: "pnpm"
cache-dependency-path: "src/interfaces/slack_bot/pnpm-lock.yaml"
- name: Install dependencies with npm
shell: bash
working-directory: src/interfaces/slack_bot
run: pnpm install --frozen-lockfile
- name: Check slack_bot is formatted
run: pnpm run format
- name: Check slack_bot types
run: pnpm run tsc:check
- name: Run slack_bot tests
run: pnpm run test
- name: Check slack_bot can build
run: pnpm run build
5 changes: 4 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -141,4 +141,7 @@ secrets.toml
.DS_Store

# Local file storage
/src/backend/data
/src/backend/data

# Redis volume
/data
10 changes: 9 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
@@ -1,9 +1,17 @@
dev:
@docker compose watch
make -j 2 watch up
watch:
@docker compose watch --no-up
up:
@docker compose up
down:
@docker compose down
run-tests:
docker compose run --build backend poetry run pytest src/backend/tests/$(file)
run-agent-router-tests:
docker compose run --build backend poetry run pytest src/backend/tests/routers/test_agent.py
run-user-router-tests:
docker compose run --build backend poetry run pytest src/backend/tests/routers/test_user.py
run-community-tests:
docker compose run --build backend poetry run pytest src/community/tests/$(file)
attach:
Expand Down
17 changes: 16 additions & 1 deletion docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -24,10 +24,24 @@ services:
- PGUSER=postgres
- POSTGRES_PASSWORD=postgres
ports:
- "5433:5432"
- '5433:5432'
networks:
- proxynet

redis:
image: redis:7.2-alpine
restart: always
healthcheck:
test: ["CMD-SHELL", "redis-cli ping | grep PONG"]
interval: 10s
timeout: 5s
retries: 5
ports:
- '6379:6379'
command: redis-server --save 60 1 --loglevel warning --requirepass redis
volumes:
- ./data:/data

backend:
build:
context: .
Expand Down Expand Up @@ -56,6 +70,7 @@ services:
- "8000:8000"
depends_on:
- db
- redis
volumes:
# Mount alembic folder to sync migrations
- ./src/backend/alembic:/workspace/src/backend/alembic
Expand Down
2 changes: 1 addition & 1 deletion poetry.lock

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

3 changes: 1 addition & 2 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -46,8 +46,7 @@ google-auth-httplib2="^0.2.0"
google-api-python-client="^2.133.0"
openpyxl = "^3.1.5"

# compass dependencies. to be removed
# once compass is OSS
# Compass dependencies - To be removed once Compass is OSS
[tool.poetry.group.compass]
optional = false

Expand Down
200 changes: 200 additions & 0 deletions src/backend/alembic/versions/1acff4138b79_.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,200 @@
"""empty message
Revision ID: 1acff4138b79
Revises: a48691a80366
Create Date: 2024-07-09 15:27:44.022554
"""

from typing import Sequence, Union

import sqlalchemy as sa
from alembic import op

# revision identifiers, used by Alembic.
revision: str = "1acff4138b79"
down_revision: Union[str, None] = "a48691a80366"
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.alter_column(
"agent_tool_metadata",
"user_id",
existing_type=sa.TEXT(),
type_=sa.String(),
existing_nullable=False,
)
op.alter_column(
"agents",
"user_id",
existing_type=sa.TEXT(),
type_=sa.String(),
existing_nullable=False,
)
op.alter_column(
"tool_auth",
"user_id",
existing_type=sa.TEXT(),
type_=sa.String(),
existing_nullable=False,
)

op.drop_constraint(
"documents_conversation_id_fkey", "documents", type_="foreignkey"
)
op.drop_constraint("files_conversation_id_fkey", "files", type_="foreignkey")
op.drop_constraint("messages_conversation_id_fkey", "messages", type_="foreignkey")
op.drop_constraint(
"snapshots_conversation_id_fkey", "snapshots", type_="foreignkey"
)
op.drop_constraint("conversations_pkey", "conversations", type_="primary")

op.create_unique_constraint(
"conversation_id_user_id", "conversations", ["id", "user_id"]
)
op.create_primary_key("conversations_pkey", "conversations", ["id", "user_id"])
op.create_index(
"conversation_user_id_index", "conversations", ["id", "user_id"], unique=True
)

op.create_foreign_key(
None, "agent_tool_metadata", "users", ["user_id"], ["id"], ondelete="CASCADE"
)
op.create_foreign_key(
None, "agents", "users", ["user_id"], ["id"], ondelete="CASCADE"
)
op.create_foreign_key(
None, "citations", "users", ["user_id"], ["id"], ondelete="CASCADE"
)
op.create_foreign_key(
None, "conversations", "users", ["user_id"], ["id"], ondelete="CASCADE"
)
op.create_foreign_key(
"document_conversation_id_user_id_fkey",
"documents",
"conversations",
["conversation_id", "user_id"],
["id", "user_id"],
ondelete="CASCADE",
)
op.create_foreign_key(
"file_conversation_id_user_id_fkey",
"files",
"conversations",
["conversation_id", "user_id"],
["id", "user_id"],
ondelete="CASCADE",
)
op.create_foreign_key(
"message_conversation_id_user_id_fkey",
"messages",
"conversations",
["conversation_id", "user_id"],
["id", "user_id"],
ondelete="CASCADE",
)
op.create_foreign_key(
None, "snapshot_access", "users", ["user_id"], ["id"], ondelete="CASCADE"
)
op.create_foreign_key(
None, "snapshot_links", "users", ["user_id"], ["id"], ondelete="CASCADE"
)
op.create_foreign_key(
"snapshot_conversation_id_user_id_fkey",
"snapshots",
"conversations",
["conversation_id", "user_id"],
["id", "user_id"],
ondelete="CASCADE",
)
op.create_foreign_key(
None, "tool_auth", "users", ["user_id"], ["id"], ondelete="CASCADE"
)
# ### end Alembic commands ###


def downgrade() -> None:
# ### commands auto generated by Alembic - please adjust! ###
op.drop_foreign_key(
"snapshot_conversation_id_user_id_fkey", "snapshots", type_="foreignkey"
)
op.drop_foreign_key(None, "tool_auth", "users", type_="foreignkey")
op.drop_foreign_key(None, "snapshot_links", "users", type_="foreignkey")
op.drop_foreign_key(None, "snapshot_access", "users", type_="foreignkey")
op.drop_foreign_key(
"message_conversation_id_user_id_fkey", "messages", type_="foreignkey"
)
op.drop_foreign_key(
"file_conversation_id_user_id_fkey", "files", type_="foreignkey"
)
op.drop_foreign_key(
"document_conversation_id_user_id_fkey", "documents", type_="foreignkey"
)
op.drop_foreign_key(None, "conversations", "users", type_="foreignkey")
op.drop_foreign_key(None, "citations", "users", type_="foreignkey")
op.drop_foreign_key(None, "agents", "users", type_="foreignkey")
op.drop_foreign_key(None, "agent_tool_metadata", "users", type_="foreignkey")

op.drop_index("conversation_user_id_index", table_name="conversations")
op.drop_constraint("conversations_pkey", "conversations", type_="primary")
op.drop_constraint("conversation_id_user_id", "conversations", type_="unique")

op.create_primary_key("conversations_pkey", "conversations", ["id"])
op.create_foreign_key(
"snapshots_conversation_id_fkey",
"snapshots",
"conversations",
["conversation_id"],
["id"],
ondelete="CASCADE",
)
op.create_foreign_key(
"messages_conversation_id_fkey",
"messages",
"conversations",
["conversation_id"],
["id"],
ondelete="CASCADE",
)
op.create_foreign_key(
"files_conversation_id_fkey",
"files",
"conversations",
["conversation_id"],
["id"],
ondelete="CASCADE",
)
op.create_foreign_key(
"documents_conversation_id_fkey",
"documents",
"conversations",
["conversation_id"],
["id"],
ondelete="CASCADE",
)

op.alter_column(
"tool_auth",
"user_id",
existing_type=sa.String(),
type_=sa.TEXT(),
existing_nullable=False,
)
op.alter_column(
"agents",
"user_id",
existing_type=sa.String(),
type_=sa.TEXT(),
existing_nullable=False,
)
op.alter_column(
"agent_tool_metadata",
"user_id",
existing_type=sa.String(),
type_=sa.TEXT(),
existing_nullable=False,
)
# ### end Alembic commands ###
35 changes: 35 additions & 0 deletions src/backend/alembic/versions/ed17f144f4bf_.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
"""empty message
Revision ID: ed17f144f4bf
Revises: 1acff4138b79
Create Date: 2024-07-10 10:00:50.507812
"""

from typing import Sequence, Union

import sqlalchemy as sa
from alembic import op

from src.backend.schemas.user import DEFAULT_USER_ID, DEFAULT_USER_NAME

# revision identifiers, used by Alembic.
revision: str = "ed17f144f4bf"
down_revision: Union[str, None] = "1acff4138b79"
branch_labels: Union[str, Sequence[str], None] = None
depends_on: Union[str, Sequence[str], None] = None


def upgrade() -> None:
# Populate the users table with the default user
op.execute(
f"""
INSERT INTO users (id, fullname, created_at, updated_at)
VALUES ('{DEFAULT_USER_ID}', '{DEFAULT_USER_NAME}', now(), now())
ON CONFLICT (id) DO NOTHING;
"""
)


def downgrade() -> None:
pass
12 changes: 2 additions & 10 deletions src/backend/chat/custom/custom.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import asyncio
from itertools import tee
from typing import Any, AsyncGenerator, Dict, Generator, List
from typing import Any, AsyncGenerator, Dict, List

from fastapi import HTTPException

Expand Down Expand Up @@ -57,13 +56,6 @@ async def chat(
stream = self.call_chat(self.chat_request, deployment_model, **kwargs)

async for event in stream:
send_log_message(
logger,
f"Stream event: {event}",
level="info",
conversation_id=kwargs.get("conversation_id"),
user_id=kwargs.get("user_id"),
)
result = self.handle_event(event, chat_request)

if result:
Expand Down Expand Up @@ -292,7 +284,7 @@ async def handle_tool_calls_stream(self, tool_results_stream):
is_direct_answer = True

chat_history = []
for event in stream:
async for event in stream:
if event["event_type"] == StreamEvent.STREAM_END:
stream_chat_history = []
if "response" in event:
Expand Down
Loading

0 comments on commit 5115174

Please sign in to comment.