Skip to content

Commit

Permalink
Multiple choice WIP(3)
Browse files Browse the repository at this point in the history
  • Loading branch information
davorinrusevljan committed Sep 12, 2024
1 parent 9d1073c commit acff58f
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 20 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@ def retrieve_exam_questions(
"4) The Last Supper",
"5) Vitruvian Man",
],
default="1) Mona Lisa"
)
return io.process_message(msg)
except Exception as e:
Expand Down
16 changes: 12 additions & 4 deletions fastagency/core/io/mesop/components/inputs.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,12 @@ def _on_blur(e: me.InputBlurEvent) -> None:


def input_user_feedback(
send_feedback: Callable[[me.ClickEvent], Iterator[None]],
send_feedback: Callable[[me.ClickEvent], Iterator[None]], disabled: bool = False
) -> None:
def _on_feedback_blur(e: me.InputBlurEvent) -> None:
state = me.state(State)
state.conversation.feedback = e.value

with me.box(
style=me.Style(
border_radius=16,
Expand All @@ -26,16 +30,20 @@ def input_user_feedback(
with me.box(style=me.Style(flex_grow=1)):
me.native_textarea(
placeholder="Provide a feedback to the team",
on_blur=_on_blur,
key="feedback",
on_blur=_on_feedback_blur,
disabled=disabled,
style=me.Style(
padding=me.Padding(top=16, left=16),
outline="none",
width="100%",
border=me.Border.all(me.BorderSide(style="none")),
),
)
with me.content_button(type="icon", on_click=send_feedback):
with me.content_button(
type="icon",
on_click=send_feedback,
disabled=disabled,
):
me.icon("send")


Expand Down
42 changes: 26 additions & 16 deletions fastagency/core/io/mesop/message.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@

from fastagency.core.base import AskingMessage, WorkflowCompleted
from fastagency.core.io.mesop.base import MesopMessage
from fastagency.core.io.mesop.components.inputs import input_user_feedback
from fastagency.core.io.mesop.send_prompt import send_user_feedback_to_autogen

from ...base import (
Expand Down Expand Up @@ -99,6 +100,17 @@ def __init__(
def _has_feedback(self) -> bool:
return len(self._conversation_message.feedback) > 0

def _provide_feedback(self, feedback: str) -> Iterator[None]:
state = me.state(State)
conversation = state.conversation
conversation.feedback = ""
conversation.waiting_for_feedback = False
yield
me.scroll_into_view(key="end_of_messages")
yield
responses = send_user_feedback_to_autogen(feedback)
yield from consume_responses(responses)

def visit_default(self, message: IOMessage) -> None:
base_color = "#aff"
with me.box(
Expand Down Expand Up @@ -139,12 +151,18 @@ def visit_system_message(self, message: SystemMessage) -> None:
me.markdown(json.dumps(message.message, indent=2))

def visit_text_input(self, message: TextInput) -> str:
text = message.prompt if message.prompt else "Please enter a value"
def on_input(ev: me.RadioChangeEvent) -> Iterator[None]:
state = me.state(State)
feedback = state.conversation.feedback
self._conversation_message.feedback = [feedback]
yield from self._provide_feedback(feedback)

base_color = "#dff"
prompt = message.prompt if message.prompt else "Please enter a value"
if message.suggestions:
suggestions = ",".join(suggestion for suggestion in message.suggestions)
text += "\n" + suggestions
prompt += "\n" + suggestions

base_color = "#dff"
with me.box(
style=me.Style(
background=base_color,
Expand All @@ -154,26 +172,19 @@ def visit_text_input(self, message: TextInput) -> str:
)
):
self._header(message, base_color, title="Input requested")
me.markdown(text)
me.markdown(prompt)
input_user_feedback(
on_input, disabled=self._readonly or self._has_feedback()
)
return ""

def _provide_feedback(self, feedback: str) -> Iterator[None]:
state = me.state(State)
conversation = state.conversation
conversation.feedback = ""
conversation.waiting_for_feedback = False
yield
me.scroll_into_view(key="end_of_messages")
yield
responses = send_user_feedback_to_autogen(feedback)
yield from consume_responses(responses)

def visit_multiple_choice(self, message: MultipleChoice) -> str:
def on_change(ev: me.RadioChangeEvent) -> Iterator[None]:
feedback = ev.value
self._conversation_message.feedback = [feedback]
yield from self._provide_feedback(feedback)

base_color = "#dff"
prompt = message.prompt if message.prompt else "Please enter a value"
if message.choices:
options = map(
Expand All @@ -183,7 +194,6 @@ def on_change(ev: me.RadioChangeEvent) -> Iterator[None]:
),
message.choices,
)
base_color = "#dff"
if self._has_feedback():
pre_selected = {"value": self._conversation_message.feedback[0]}
else:
Expand Down

0 comments on commit acff58f

Please sign in to comment.