Build applications that make decisions (chatbots, agents, simulations, etc...). Monitor, trace, persist, and execute on your own infrastructure.
Python aiburrchatbot-frameworkdagsgenerative-aigraphshacktoberfestllmopsllmsmlopspersistent-data-structurestate-machinestate-managementvisibility
Changes the gpt app example to use inputs
elijahbenizzy5a4d72265bbc
diff --git a/burr/core/action.py b/burr/core/action.pyindex d10cd024..f806dbae 100644--- a/burr/core/action.py+++ b/burr/core/action.py@@ -56,7 +56,7 @@ class Function(abc.ABC):if missing_inputs or additional_inputs:raise ValueError(f"Inputs to function {self} are invalid. "- f"Missing the following inputs: {', '.join(missing_inputs)}."+ + f"Missing the following inputs: {', '.join(missing_inputs)}."if missing_inputselse "" f"Additional inputs: {','.join(additional_inputs)}."if additional_inputsdiff --git a/examples/gpt/application.py b/examples/gpt/application.pyindex 47a8c810..734115d2 100644--- a/examples/gpt/application.py+++ b/examples/gpt/application.py@@ -18,12 +18,12 @@ MODES = {}-@action(reads=["prompt"], writes=["chat_history"])-def process_prompt(state: State) -> Tuple[dict, State]:- result = {"processed_prompt": {"role": "user", "content": state["prompt"], "type": "text"}}+@action(reads=[], writes=["chat_history", "prompt"])+def process_prompt(state: State, prompt: str) -> Tuple[dict, State]:+ result = {"processed_prompt": {"role": "user", "content": prompt, "type": "text"}}return result, state.wipe(keep=["prompt", "chat_history"]).append(chat_history=result["processed_prompt"]- )+ ).update(prompt=prompt)@action(reads=["prompt"], writes=["safe"])diff --git a/examples/gpt/streamlit_app.py b/examples/gpt/streamlit_app.pyindex 13cb8eff..ed114678 100644--- a/examples/gpt/streamlit_app.py+++ b/examples/gpt/streamlit_app.py@@ -12,6 +12,13 @@ from burr.integrations.streamlit import (update_state,)+st.set_page_config(layout="wide")++"""This file is a work in progress. Note that this will be replaced shortly+with a simple chatbot + a reference to the Burr UI (to be run in a separate page),+which is more powerful and much simpler to understand. For now,+this is purely for demos."""+def render_chat_message(record: Record):if record.action in ["prompt", "response"]:@@ -32,6 +39,8 @@ def render_chat_message(record: Record):def retrieve_state():if "burr_state" not in st.session_state:+ # TODO --enable usage of hamilton. Currently its not wiring in inputs+ # But it should be easy enoughstate = AppState.from_empty(app=chatbot_application.application(use_hamilton=False),)@@ -47,15 +56,17 @@ def chatbot_step(app_state: AppState, prompt: Optional[str]) -> bool::param prompt: Prompt to set the chatbot to. If this is None it means it should continue and not be reset.:return:"""+ inputs = Noneif prompt is not None:# We need to update- app_state.app.update_state(app_state.app.state.update(prompt=prompt))+ inputs = {"prompt": prompt}+ # app_state.app.update_state(app_state.app.state.update(prompt=prompt))st.session_state.running = True # set to running# if its not running this is a no-opif not st.session_state.get("running", False):return Falseapplication = app_state.app- step_output = application.step()+ step_output = application.step(inputs=inputs)if step_output is None:st.session_state.running = Falsereturn False@@ -70,7 +81,6 @@ def chatbot_step(app_state: AppState, prompt: Optional[str]) -> bool:def main():- st.set_page_config(layout="wide")st.title("Chatbot example with Burr")app_state = retrieve_state() # retrieve first so we can use for the ret of the stepcolumns = st.columns(2)