-
Notifications
You must be signed in to change notification settings - Fork 1k
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
Paul assistant #1342
base: main
Are you sure you want to change the base?
Paul assistant #1342
Changes from 20 commits
81d21d1
dcfe390
2b1d0ac
b825360
4c8b119
1d749f6
c041027
179fd65
3876a26
eab3e47
e13dde7
07f2839
2b2d453
430376c
ef1face
e10bec5
661aa4b
c32d849
30baa5d
5384a6c
d075a22
9cff5b1
85e285d
108863f
243e87e
c5301f8
76140bb
42c83ea
c610991
50efe4a
4c05051
0424ae1
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
from typing import List, Dict | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. if we have multiple assistant file it can be in a dedicated folder/module |
||
from chainlit.input_widget import InputWidget | ||
|
||
class Assistant: | ||
input_widgets: List[InputWidget] = [] | ||
settings_values: Dict = {} | ||
|
||
def __init__(self, input_widgets: List[InputWidget], settings_values: Dict): | ||
self.input_widgets = input_widgets | ||
self.settings_values = settings_values | ||
|
||
def to_dict(self): | ||
return { | ||
"input_widgets": [widget.__repr__() for widget in self.input_widgets], | ||
"settings_values": self.settings_values | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
import logging | ||
from typing import List | ||
|
||
from chainlit.context import context | ||
from chainlit.input_widget import InputWidget | ||
from pydantic.dataclasses import Field, dataclass | ||
|
||
|
||
@dataclass | ||
class AssistantSettings: | ||
"""Useful to create chat settings that the user can change.""" | ||
|
||
inputs: List[InputWidget] = Field(default_factory=list, exclude=True) | ||
|
||
def __init__( | ||
self, | ||
inputs: List[InputWidget], | ||
) -> None: | ||
self.inputs = inputs | ||
|
||
def settings(self): | ||
return dict( | ||
[(input_widget.id, input_widget.initial) for input_widget in self.inputs] | ||
) | ||
|
||
async def send(self): | ||
settings = self.settings() | ||
context.emitter.set_assistant_settings(settings) | ||
|
||
inputs_content = [input_widget.to_dict() for input_widget in self.inputs] | ||
# logging.info(f"Sending assistant settings: {inputs_content}") | ||
await context.emitter.emit("assistant_settings", inputs_content) | ||
|
||
# logging.info(f"Assistant settings sent: {settings}") | ||
return settings |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -5,6 +5,8 @@ | |
import shutil | ||
import urllib.parse | ||
from typing import Any, Optional, Union | ||
import uuid | ||
import os | ||
|
||
from chainlit.oauth_providers import get_oauth_provider | ||
from chainlit.secret import random_secret | ||
|
@@ -194,11 +196,11 @@ def get_build_dir(local_target: str, packaged_target: str): | |
|
||
router = APIRouter(prefix=ROOT_PATH) | ||
|
||
app.mount( | ||
f"{ROOT_PATH}/public", | ||
StaticFiles(directory="public", check_dir=False), | ||
name="public", | ||
) | ||
# app.mount( | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Why is this commented? |
||
# f"{ROOT_PATH}/static", | ||
# StaticFiles(directory="static", check_dir=False), | ||
# name="static", | ||
# ) | ||
|
||
app.mount( | ||
f"{ROOT_PATH}/assets", | ||
|
@@ -218,7 +220,6 @@ def get_build_dir(local_target: str, packaged_target: str): | |
name="copilot", | ||
) | ||
|
||
|
||
# ------------------------------------------------------------------------------- | ||
# SLACK HANDLER | ||
# ------------------------------------------------------------------------------- | ||
|
@@ -921,7 +922,6 @@ async def get_avatar(avatar_id: str): | |
avatar_id = avatar_id.strip().lower().replace(" ", "_") | ||
|
||
avatar_path = os.path.join(APP_ROOT, "public", "avatars", f"{avatar_id}.*") | ||
|
||
files = glob.glob(avatar_path) | ||
|
||
if files: | ||
|
@@ -931,6 +931,34 @@ async def get_avatar(avatar_id: str): | |
else: | ||
return await get_favicon() | ||
|
||
# post avatar/{avatar_id} (only for authenticated users) | ||
@router.post("/avatars/{avatar_id}") | ||
async def upload_avatar( | ||
avatar_id: str, | ||
file: UploadFile, | ||
current_user: Annotated[ | ||
Union[None, User, PersistedUser], Depends(get_current_user) | ||
], | ||
): | ||
# if not current_user: | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. why is this commented? |
||
# raise HTTPException(status_code=401, detail="Not authenticated") | ||
|
||
# Save the file to the avatars directory | ||
try: | ||
# file_extension = os.path.splitext(file.filename)[1] | ||
# avatar_filename = f"{avatar_id}{file_extension}" | ||
avatar_path = os.path.join(APP_ROOT, "public", "avatars", avatar_id) | ||
|
||
# Ensure the avatars directory exists | ||
os.makedirs(os.path.dirname(avatar_path), exist_ok=True) | ||
|
||
with open(avatar_path, "wb") as f: | ||
f.write(await file.read()) | ||
except Exception as e: | ||
raise HTTPException(status_code=500, detail=str(e)) | ||
|
||
return {"id": avatar_id} | ||
|
||
|
||
@router.head("/") | ||
def status_check(): | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
remove comment