Skip to content

Commit

Permalink
simplify settings
Browse files Browse the repository at this point in the history
  • Loading branch information
tylertitsworth committed Jan 2, 2024
1 parent 9de1983 commit a2a108a
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 15 deletions.
17 changes: 5 additions & 12 deletions main.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,13 +54,10 @@ def set_chat_settings(self, settings):
if isinstance(settings, dict):
for key, val in settings.items():
setattr(wiki, key, val)
if settings:
wiki.settings = settings


### Globals
wiki = MultiWiki()
wiki.set_chat_settings(None)


def rename_duplicates(documents):
Expand Down Expand Up @@ -114,9 +111,6 @@ def create_vector_db():
)
vectordb.persist()

###
# https://python.langchain.com/docs/integrations/retrievers/merger_retriever
###

def create_chain():
# https://python.langchain.com/docs/modules/memory/chat_messages/
Expand Down Expand Up @@ -159,7 +153,8 @@ def create_chain():
return chain


async def update_cl():
async def update_cl(settings):
wiki.set_chat_settings(settings)
chain = create_chain()
# https://docs.chainlit.io/api-reference/chat-settings
inputs = [
Expand Down Expand Up @@ -206,7 +201,6 @@ async def update_cl():
description="Works together with top-k. A higher value will lead to more diverse text. (Default: 0.9)",
),
]
wiki.set_chat_settings(inputs)
# https://docs.chainlit.io/observability-iteration/prompt-playground/llm-providers#langchain-provider
add_llm_provider(
LangchainGenericProvider(
Expand All @@ -216,7 +210,7 @@ async def update_cl():
is_chat=True,
# Not enough context to LangchainGenericProvider
# https://github.com/Chainlit/chainlit/blob/main/backend/chainlit/playground/providers/langchain.py#L27
inputs=wiki.settings,
inputs=[input for input in inputs if isinstance(input, Slider)],
)
)
await cl.ChatSettings(inputs).send()
Expand All @@ -227,7 +221,7 @@ async def update_cl():
# https://docs.chainlit.io/examples/qa
@cl.on_chat_start
async def on_chat_start():
await update_cl()
await update_cl(None)
await cl.Message(content=wiki.introduction, disable_human_feedback=True).send()


Expand Down Expand Up @@ -264,8 +258,7 @@ async def on_message(message: cl.Message):

@cl.on_settings_update
async def setup_agent(settings):
wiki.set_chat_settings(settings)
await update_cl()
await update_cl(settings)


if __name__ == "__main__":
Expand Down
5 changes: 2 additions & 3 deletions provider.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from chainlit import input_widget
from chainlit.input_widget import InputWidget
from chainlit.playground.provider import BaseProvider
from chainlit.prompt import PromptMessage
from chainlit.sync import make_async
Expand All @@ -18,7 +18,7 @@ def __init__(
id: str,
name: str,
llm: Union[LLM, BaseChatModel],
inputs: List[input_widget.InputWidget],
inputs: List[InputWidget],
is_chat: bool = False,
):
super().__init__(
Expand Down Expand Up @@ -65,7 +65,6 @@ async def create_completion(self, request):
await super().create_completion(request)

self.require_settings(request.prompt.settings)
del request.prompt.settings["num_sources"]

messages = self.create_prompt(request)

Expand Down

0 comments on commit a2a108a

Please sign in to comment.