Skip to content

Commit

Permalink
Merge pull request #318 from Sema4AI/fix-public-assistants-endpoint
Browse files Browse the repository at this point in the history
Fix public assistants endpoint
  • Loading branch information
mkorpela authored Apr 26, 2024
2 parents e1ebc7b + 4ba6635 commit 9f5a41f
Show file tree
Hide file tree
Showing 6 changed files with 14 additions and 35 deletions.
16 changes: 4 additions & 12 deletions backend/app/api/assistants.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
from typing import Annotated, List, Optional
from typing import Annotated, List
from uuid import uuid4

from fastapi import APIRouter, HTTPException, Path, Query
from fastapi import APIRouter, HTTPException, Path
from pydantic import BaseModel, Field

import app.storage as storage
Expand All @@ -10,8 +10,6 @@

router = APIRouter()

FEATURED_PUBLIC_ASSISTANTS = []


class AssistantPayload(BaseModel):
"""Payload for creating an assistant."""
Expand All @@ -31,15 +29,9 @@ async def list_assistants(user: AuthedUser) -> List[Assistant]:


@router.get("/public/")
async def list_public_assistants(
shared_id: Annotated[
Optional[str], Query(description="ID of a publicly shared assistant.")
] = None,
) -> List[Assistant]:
async def list_public_assistants() -> List[Assistant]:
"""List all public assistants."""
return await storage.list_public_assistants(
FEATURED_PUBLIC_ASSISTANTS + ([shared_id] if shared_id else [])
)
return await storage.list_public_assistants()


@router.get("/{aid}")
Expand Down
3 changes: 2 additions & 1 deletion backend/app/chatbot.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
from typing import Annotated, List

from app.message_types import add_messages_liberal
from langchain_core.language_models.base import LanguageModelLike
from langchain_core.messages import BaseMessage, SystemMessage
from langgraph.checkpoint import BaseCheckpointSaver
from langgraph.graph.state import StateGraph

from app.message_types import add_messages_liberal


def get_chatbot_executor(
llm: LanguageModelLike,
Expand Down
2 changes: 1 addition & 1 deletion backend/app/message_types.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
MessageLikeRepresentation,
ToolMessage,
)
from langgraph.graph.message import add_messages, Messages
from langgraph.graph.message import Messages, add_messages


class LiberalFunctionMessage(FunctionMessage):
Expand Down
13 changes: 3 additions & 10 deletions backend/app/storage.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,23 +19,16 @@ async def get_assistant(user_id: str, assistant_id: str) -> Optional[Assistant]:
"""Get an assistant by ID."""
async with get_pg_pool().acquire() as conn:
return await conn.fetchrow(
"SELECT * FROM assistant WHERE assistant_id = $1 AND (user_id = $2 OR public = true)",
"SELECT * FROM assistant WHERE assistant_id = $1 AND (user_id = $2 OR public IS true)",
assistant_id,
user_id,
)


async def list_public_assistants(assistant_ids: Sequence[str]) -> List[Assistant]:
async def list_public_assistants() -> List[Assistant]:
"""List all the public assistants."""
async with get_pg_pool().acquire() as conn:
return await conn.fetch(
(
"SELECT * FROM assistant "
"WHERE assistant_id = ANY($1::uuid[]) "
"AND public = true;"
),
assistant_ids,
)
return await conn.fetch(("SELECT * FROM assistant WHERE public IS true;"))


async def put_assistant(
Expand Down
2 changes: 1 addition & 1 deletion backend/app/upload.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@
import os
from typing import BinaryIO, List, Optional

from langchain_core.document_loaders.blob_loaders import Blob
from langchain_community.vectorstores.pgvector import PGVector
from langchain_core.document_loaders.blob_loaders import Blob
from langchain_core.runnables import (
ConfigurableField,
RunnableConfig,
Expand Down
13 changes: 3 additions & 10 deletions frontend/src/components/Config.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -412,11 +412,8 @@ function ToolSelectionField(props: {
);
}

function PublicLink(props: { assistantId: string }) {
const currentLink = window.location.href;
const link = currentLink.includes(props.assistantId)
? currentLink
: currentLink + "?shared_id=" + props.assistantId;
function PublicLink() {
const link = window.location.href;
return (
<div className="flex rounded-md shadow-sm mb-4">
<button
Expand Down Expand Up @@ -591,11 +588,7 @@ export function Config(props: {
<PublicToggle enabled={isPublic} setEnabled={setPublic} />
</div>
) : (
<>
{props.config?.public && (
<PublicLink assistantId={props.config?.assistant_id} />
)}
</>
<>{props.config?.public && <PublicLink />}</>
);
return (
<form
Expand Down

0 comments on commit 9f5a41f

Please sign in to comment.