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 17, 2024
2 parents 5115174 + a7ca53c commit 04aa2f4
Show file tree
Hide file tree
Showing 142 changed files with 1,120 additions and 8,694 deletions.
1 change: 1 addition & 0 deletions .env-template
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ WOLFRAM_ALPHA_APP_ID=<APP_ID_HERE>

# CORAL WEB
NEXT_PUBLIC_HAS_CUSTOM_LOGO=false
NEXT_PUBLIC_DARK_MODE=false

# DEPLOYMENTS
# To use the Toolkit, at least one deployment must be setup, the simplest
Expand Down
19 changes: 7 additions & 12 deletions .github/workflows/slack_bot_tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -19,26 +19,21 @@ jobs:
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"
cache: "npm"
cache-dependency-path: "src/interfaces/slack_bot/package-lock.json"
- name: Install dependencies with npm
shell: bash
working-directory: src/interfaces/slack_bot
run: pnpm install --frozen-lockfile
run: npm ci
- name: Check slack_bot is formatted
run: pnpm run format
run: npm run format
- name: Check slack_bot types
run: pnpm run tsc:check
run: npm run tsc:check
- name: Run slack_bot tests
run: pnpm run test
run: npm run test
- name: Check slack_bot can build
run: pnpm run build
run: npm run build
3 changes: 2 additions & 1 deletion CODEOWNERS
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
* @cohere-ai/toolkit @EugeneLightsOn @malexw @scottmx81 @tianjing-li
* @cohere-ai/toolkit @EugeneLightsOn @malexw @scottmx81 @tianjing-li
src/interfaces/coral_web @tomtobac @abimacarmes @knajjars @misspia-cohere
3 changes: 2 additions & 1 deletion docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,7 @@ services:
NEXT_PUBLIC_FRONTEND_HOSTNAME: ${NEXT_PUBLIC_FRONTEND_HOSTNAME}
NEXT_PUBLIC_GOOGLE_DRIVE_CLIENT_ID: ${NEXT_PUBLIC_GOOGLE_DRIVE_CLIENT_ID}
NEXT_PUBLIC_GOOGLE_DRIVE_DEVELOPER_KEY: ${NEXT_PUBLIC_GOOGLE_DRIVE_DEVELOPER_KEY}
NEXT_PUBLIC_DARK_MODE: ${NEXT_PUBLIC_DARK_MODE}
restart: always
networks:
- proxynet
Expand Down Expand Up @@ -120,4 +121,4 @@ volumes:

networks:
proxynet:
name: custom_network
name: custom_network
10 changes: 9 additions & 1 deletion docs/auth_guide.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ This is the current list of implemented Auth strategies:

To enable one or more of these strategies, add them to the `ENABLED_AUTH_STRATEGIES` list in the `backend/config/auth.py` file, then add any required environment variables in your `.env` file, and generate a secret key to be used as the `AUTH_SECRET_KEY` environment variable. This is used to encode and decode your access tokens.

For the `AUTH_SECRET_KEY`, if you want to test auth functionality you can use any string value.
Regarding the `AUTH_SECRET_KEY` variable, if you want to test auth any string will suffice.
For production use-cases, it is recommended to run the following python commands in a local CLI to generate a random key:

```
Expand All @@ -25,6 +25,14 @@ print(secrets.token_hex(32))
When configuring your OAuth apps, make sure to whitelist the Redirect URI to the frontend endpoint, it should look like
`<FRONTEND_HOST>/auth/<STRATEGY_NAME>`. For example, your Redirect URI will be `http://localhost:4000/auth/google` if you're running the GoogleOAuth class locally.

## Enabling Proof of Key Code Exchange (PKCE)

Many OIDC-compliant auth providers also implement PKCE for added protection. This involves generating `code_verifier` and `code_challenge` values in the frontend and using these values to validate that the same entity that initially logged in with the auth provider is the one requesting an access token from an authorization code.

For more [details click here.](https://oauth.net/2/pkce/)

To enable the additional PKCE auth flow, you will need to first ensure your auth provider is PKCE-compliant, then set the `PKCE_ENABLED` class attribute in your OIDCConnect auth strategy to `True`.

## Implementing new Auth strategies

To implement a new strategy, refer to the `backend/services/auth/strategies` folder. Auth strategies will need to inherit from one of two base classes, `BaseAuthenticationStrategy` or `BaseOAuthStrategy`.
Expand Down
6 changes: 3 additions & 3 deletions src/backend/alembic/versions/ed17f144f4bf_.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
"""empty message
Revision ID: ed17f144f4bf
Revises: 1acff4138b79
Create Date: 2024-07-10 10:00:50.507812
Revises: f077676dfd5d
Create Date: 2024-07-16 10:00:50.507812
"""

Expand All @@ -15,7 +15,7 @@

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

Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
"""empty message
Revision ID: 1acff4138b79
Revision ID: f077676dfd5d
Revises: a48691a80366
Create Date: 2024-07-09 15:27:44.022554
Create Date: 2024-07-16 18:05:41.127076
"""

Expand All @@ -12,7 +12,7 @@
from alembic import op

# revision identifiers, used by Alembic.
revision: str = "1acff4138b79"
revision: str = "f077676dfd5d"
down_revision: Union[str, None] = "a48691a80366"
branch_labels: Union[str, Sequence[str], None] = None
depends_on: Union[str, Sequence[str], None] = None
Expand All @@ -25,22 +25,45 @@ def upgrade() -> None:
"user_id",
existing_type=sa.TEXT(),
type_=sa.String(),
existing_nullable=False,
nullable=True,
)
op.alter_column(
"agents",
"user_id",
existing_type=sa.TEXT(),
type_=sa.String(),
existing_nullable=False,
nullable=True,
)
op.alter_column(
"tool_auth",
"user_id",
existing_type=sa.TEXT(),
type_=sa.String(),
existing_nullable=False,
nullable=True,
)
op.alter_column("citations", "user_id", existing_type=sa.VARCHAR(), nullable=True)
op.alter_column(
"conversations", "user_id", existing_type=sa.VARCHAR(), nullable=True
)
op.alter_column("documents", "user_id", existing_type=sa.VARCHAR(), nullable=True)
op.alter_column(
"documents", "conversation_id", existing_type=sa.VARCHAR(), nullable=True
)
op.alter_column("files", "user_id", existing_type=sa.VARCHAR(), nullable=True)
op.alter_column(
"files", "conversation_id", existing_type=sa.VARCHAR(), nullable=True
)
op.alter_column("messages", "user_id", existing_type=sa.VARCHAR(), nullable=True)
op.alter_column(
"messages", "conversation_id", existing_type=sa.VARCHAR(), nullable=True
)
op.alter_column(
"snapshot_access", "user_id", existing_type=sa.VARCHAR(), nullable=True
)
op.alter_column(
"snapshot_links", "user_id", existing_type=sa.VARCHAR(), nullable=True
)
op.alter_column("snapshots", "user_id", existing_type=sa.VARCHAR(), nullable=True)

op.drop_constraint(
"documents_conversation_id_fkey", "documents", type_="foreignkey"
Expand Down Expand Up @@ -118,30 +141,23 @@ def upgrade() -> None:

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_index("conversation_user_id_index", table_name="conversations")
op.drop_constraint("tool_auth_user_id_fkey", "tool_auth", type_="foreignkey")
op.drop_constraint(
"snapshot_links_user_id_fkey", "snapshot_links", 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_constraint(
"snapshot_access_user_id_fkey", "snapshot_access", type_="foreignkey"
)
op.drop_foreign_key(
"file_conversation_id_user_id_fkey", "files", type_="foreignkey"
op.drop_constraint(
"message_conversation_id_user_id_fkey", "messages", type_="foreignkey"
)
op.drop_foreign_key(
op.drop_constraint("file_conversation_id_user_id_fkey", "files", type_="foreignkey")
op.drop_constraint(
"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",
Expand Down Expand Up @@ -175,26 +191,102 @@ def downgrade() -> None:
["id"],
ondelete="CASCADE",
)

op.alter_column(
"snapshots",
"user_id",
existing_type=sa.VARCHAR(),
type_=sa.String(),
nullable=False,
)
op.alter_column(
"snapshot_links",
"user_id",
existing_type=sa.VARCHAR(),
type_=sa.String(),
nullable=False,
)
op.alter_column(
"snapshot_access",
"user_id",
existing_type=sa.VARCHAR(),
type_=sa.String(),
nullable=False,
)
op.alter_column(
"messages",
"conversation_id",
existing_type=sa.VARCHAR(),
type_=sa.String(),
nullable=False,
)
op.alter_column(
"messages",
"user_id",
existing_type=sa.VARCHAR(),
type_=sa.String(),
nullable=False,
)
op.alter_column(
"files",
"conversation_id",
existing_type=sa.VARCHAR(),
type_=sa.String(),
nullable=False,
)
op.alter_column(
"files",
"user_id",
existing_type=sa.VARCHAR(),
type_=sa.String(),
nullable=False,
)
op.alter_column(
"documents",
"conversation_id",
existing_type=sa.VARCHAR(),
type_=sa.String(),
nullable=False,
)
op.alter_column(
"documents",
"user_id",
existing_type=sa.VARCHAR(),
type_=sa.String(),
nullable=False,
)
op.alter_column(
"conversations",
"user_id",
existing_type=sa.VARCHAR(),
type_=sa.String(),
nullable=False,
)
op.alter_column(
"citations",
"user_id",
existing_type=sa.VARCHAR(),
type_=sa.String(),
nullable=False,
)
op.alter_column(
"tool_auth",
"user_id",
existing_type=sa.String(),
type_=sa.TEXT(),
existing_nullable=False,
existing_type=sa.TEXT(),
type_=sa.String(),
nullable=False,
)
op.alter_column(
"agents",
"user_id",
existing_type=sa.String(),
type_=sa.TEXT(),
existing_nullable=False,
existing_type=sa.TEXT(),
type_=sa.String(),
nullable=False,
)
op.alter_column(
"agent_tool_metadata",
"user_id",
existing_type=sa.String(),
type_=sa.TEXT(),
existing_nullable=False,
existing_type=sa.TEXT(),
type_=sa.String(),
nullable=False,
)
# ### end Alembic commands ###
11 changes: 11 additions & 0 deletions src/backend/config/routers.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ class RouterName(StrEnum):
TOOL = "tool"
USER = "user"
AGENT = "agent"
DEFAULT_AGENT = "default_agent"
SNAPSHOT = "snapshot"


Expand Down Expand Up @@ -102,6 +103,16 @@ class RouterName(StrEnum):
# Depends(validate_authorization),
],
},
RouterName.DEFAULT_AGENT: {
"default": [
Depends(get_session),
],
"auth": [
Depends(get_session),
# TODO: Add if the router's have to have authorization
# Depends(validate_authorization),
],
},
RouterName.SNAPSHOT: {
"default": [
Depends(get_session),
Expand Down
4 changes: 3 additions & 1 deletion src/backend/database_models/agent.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,9 @@ class Agent(Base):
nullable=False,
)

user_id: Mapped[str] = mapped_column(ForeignKey("users.id", ondelete="CASCADE"))
user_id: Mapped[str] = mapped_column(
ForeignKey("users.id", ondelete="CASCADE"), nullable=True
)
organization_id: Mapped[Optional[str]] = mapped_column(
ForeignKey(
"organizations.id", name="agents_organization_id_fkey", ondelete="CASCADE"
Expand Down
4 changes: 3 additions & 1 deletion src/backend/database_models/agent_tool_metadata.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,9 @@
class AgentToolMetadata(Base):
__tablename__ = "agent_tool_metadata"

user_id: Mapped[str] = mapped_column(ForeignKey("users.id", ondelete="CASCADE"))
user_id: Mapped[str] = mapped_column(
ForeignKey("users.id", ondelete="CASCADE"), nullable=True
)
agent_id: Mapped[str] = mapped_column(
ForeignKey("agents.id", ondelete="CASCADE"), nullable=False
)
Expand Down
4 changes: 3 additions & 1 deletion src/backend/database_models/citation.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,9 @@ class Citation(Base):
__tablename__ = "citations"

text: Mapped[str]
user_id: Mapped[str] = mapped_column(ForeignKey("users.id", ondelete="CASCADE"))
user_id: Mapped[str] = mapped_column(
ForeignKey("users.id", ondelete="CASCADE"), nullable=True
)
start: Mapped[int]
end: Mapped[int]

Expand Down
Loading

0 comments on commit 04aa2f4

Please sign in to comment.