Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix public assistants endpoint #318

Merged
merged 4 commits into from
Apr 26, 2024
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
11 changes: 2 additions & 9 deletions backend/app/storage.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,17 +25,10 @@ async def get_assistant(user_id: str, assistant_id: str) -> Optional[Assistant]:
)


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 = true;"))
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Double checking: I think the best practice (or technically correct) is to use the IS operator to evaluate boolean expressions.

WHERE public IS TRUE;

This might not matter.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sounds good. Changed.



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
Loading