Skip to content

Commit

Permalink
Merge branch 'main' into refactor_methods
Browse files Browse the repository at this point in the history
  • Loading branch information
ahuang11 authored Oct 29, 2024
2 parents e26384e + 049a997 commit 1137073
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 3 deletions.
10 changes: 9 additions & 1 deletion lumen/ai/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import param

from panel.config import config, panel_extension
from panel.io.resources import CSS_URLS
from panel.io.state import state
from panel.layout import Row
from panel.viewable import Viewer
Expand Down Expand Up @@ -55,6 +56,9 @@ class LumenAI(Viewer):
llm = param.ClassSelector(class_=Llm, default=OpenAI(), doc="""
The LLM provider to be used by default""")

show_controls = param.Boolean(default=True, doc="""
Whether to show assistant controls in the sidebar.""")

template = param.Selector(
default=config.param.template.names['fast'],
objects=config.param.template.names, doc="""
Expand Down Expand Up @@ -121,6 +125,7 @@ def show(self, **kwargs):
return self._create_view(server=True).show(**kwargs)

def _create_view(self, server: bool | None = None):
config.css_files.append(CSS_URLS['font-awesome'])
if (state.curdoc and state.curdoc.session_context) or server is True:
panel_extension(
*{ext for agent in self._assistant.agents for ext in agent._extensions}, template=self.template
Expand All @@ -129,7 +134,8 @@ def _create_view(self, server: bool | None = None):
template = state.template
template.title = self.title
template.main.append(self._assistant)
template.sidebar.append(self._assistant.controls())
if self.show_controls:
template.sidebar.append(self._assistant.controls())
return template
return super()._create_view()

Expand All @@ -140,6 +146,8 @@ def servable(self, title: str | None = None, **kwargs):
return self._create_view().servable(title, **kwargs)

def __panel__(self):
if not self.show_controls:
return self._assistant
return Row(
Row(self._assistant.controls(), max_width=300),
self._assistant
Expand Down
7 changes: 6 additions & 1 deletion lumen/ai/llm.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,10 @@ class Llm(param.Parameterized):
# Allows defining a dictionary of default models.
model_kwargs = param.Dict(default={})

# Whether the LLM supports streaming of any kind
_supports_stream = True

# Whether the LLM supports streaming of Pydantic model output
_supports_model_stream = True

__abstract = True
Expand Down Expand Up @@ -94,7 +98,8 @@ async def stream(
model_key: str = "default",
**kwargs,
):
if response_model and not self._supports_model_stream:
if ((response_model and not self._supports_model_stream) or
not self._supports_stream):
yield await self.invoke(
messages,
system=system,
Expand Down
2 changes: 1 addition & 1 deletion lumen/command/ai.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
SOURCE_CODE = """
import lumen.ai as lmai
lmai.LumenAI({tables}).servable()"""
lmai.LumenAI([{tables}]).servable()"""

VALID_EXTENSIONS = ['.parq', '.parquet', '.csv', '.json']

Expand Down

0 comments on commit 1137073

Please sign in to comment.