Skip to content

Commit

Permalink
Past chats (#181)
Browse files Browse the repository at this point in the history
* past chats WIP

* past chats WIP(4)

* past chats WIP(5)

* clicking on past conversation works

* mesop one page design WIP(1)

* mesop one page design WIP(2)

* mesop one page design WIP(3)

* mesop autosave conversation

* workaround failing import from string

* handle autogen exceptions

* Sokoban pixel manipulation (1)

* documentation update

* removed bondo over import_from_string
  • Loading branch information
davorinrusevljan authored Sep 12, 2024
1 parent 98f57c2 commit 554b345
Show file tree
Hide file tree
Showing 12 changed files with 215 additions and 112 deletions.
8 changes: 4 additions & 4 deletions docs/docs/SUMMARY.md
Original file line number Diff line number Diff line change
Expand Up @@ -92,21 +92,21 @@ search:
- [input_prompt](api/fastagency/core/io/mesop/components/inputs/input_prompt.md)
- [input_user_feedback](api/fastagency/core/io/mesop/components/inputs/input_user_feedback.md)
- ui_common
- [conversation_completed](api/fastagency/core/io/mesop/components/ui_common/conversation_completed.md)
- [darken_hex_color](api/fastagency/core/io/mesop/components/ui_common/darken_hex_color.md)
- [header](api/fastagency/core/io/mesop/components/ui_common/header.md)
- data_model
- [Conversation](api/fastagency/core/io/mesop/data_model/Conversation.md)
- [State](api/fastagency/core/io/mesop/data_model/State.md)
- main
- [conversation_page](api/fastagency/core/io/mesop/main/conversation_page.md)
- [conversation_box](api/fastagency/core/io/mesop/main/conversation_box.md)
- [conversation_starter_box](api/fastagency/core/io/mesop/main/conversation_starter_box.md)
- [get_workflows](api/fastagency/core/io/mesop/main/get_workflows.md)
- [home_page](api/fastagency/core/io/mesop/main/home_page.md)
- [on_user_feedback](api/fastagency/core/io/mesop/main/on_user_feedback.md)
- [reset_conversation](api/fastagency/core/io/mesop/main/reset_conversation.md)
- [past_conversations_box](api/fastagency/core/io/mesop/main/past_conversations_box.md)
- [send_prompt](api/fastagency/core/io/mesop/main/send_prompt.md)
- message
- [MesopGUIMessageVisitor](api/fastagency/core/io/mesop/message/MesopGUIMessageVisitor.md)
- [darken_hex_color](api/fastagency/core/io/mesop/message/darken_hex_color.md)
- [message_box](api/fastagency/core/io/mesop/message/message_box.md)
- send_prompt
- [send_prompt_to_autogen](api/fastagency/core/io/mesop/send_prompt/send_prompt_to_autogen.md)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,4 @@ search:
boost: 0.5
---

::: fastagency.core.io.mesop.components.ui_common.conversation_completed
::: fastagency.core.io.mesop.components.ui_common.darken_hex_color
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,4 @@ search:
boost: 0.5
---

::: fastagency.core.io.mesop.main.conversation_page
::: fastagency.core.io.mesop.main.conversation_box
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,4 @@ search:
boost: 0.5
---

::: fastagency.core.io.mesop.message.darken_hex_color
::: fastagency.core.io.mesop.main.conversation_starter_box
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,4 @@ search:
boost: 0.5
---

::: fastagency.core.io.mesop.main.reset_conversation
::: fastagency.core.io.mesop.main.past_conversations_box
35 changes: 29 additions & 6 deletions fastagency/core/io/mesop/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -188,12 +188,35 @@ def conversation_worker(io: MesopIO, subconversation: MesopIO) -> None:
},
)
)
result = wf.run(
name=name,
session_id="session_id",
io=subconversation, # type: ignore[arg-type]
initial_message=initial_message,
)
try:
result = wf.run(
name=name,
session_id="session_id",
io=subconversation, # type: ignore[arg-type]
initial_message=initial_message,
)
except Exception as ex:
io.process_message(
IOMessage.create(
sender="user",
recipient="workflow",
type="system_message",
message={
"heading": "Workflow Exception",
"body": f"Ending workflow with exception: {ex}",
},
)
)
io.process_message(
IOMessage.create(
sender="user",
recipient="workflow",
type="workflow_completed",
result=None,
)
)
return

io.process_message(
IOMessage.create(
sender="user",
Expand Down
48 changes: 26 additions & 22 deletions fastagency/core/io/mesop/components/ui_common.py
Original file line number Diff line number Diff line change
@@ -1,17 +1,10 @@
from typing import Callable

import mesop as me


def header() -> None:
def navigate_home(e: me.ClickEvent) -> None:
me.navigate("/")

with me.box(
on_click=navigate_home,
style=me.Style(
cursor="pointer",
padding=me.Padding.all(16),
padding=me.Padding(bottom="24px"),
),
):
me.text(
Expand All @@ -25,18 +18,29 @@ def navigate_home(e: me.ClickEvent) -> None:
)


def conversation_completed(reset_conversation: Callable[[], None]) -> None:
def navigate_home(e: me.ClickEvent) -> None:
reset_conversation()
me.navigate("/")
def darken_hex_color(hex_color: str, factor: float = 0.8) -> str:
"""Darkens a hex color by a given factor.
with me.box(
style=me.Style(
cursor="pointer",
padding=me.Padding.all(16),
),
):
me.button(
"Conversation with team has ended, start a new one",
on_click=navigate_home,
)
Args:
hex_color: The hex color code (e.g., '#FF0000').
factor: The darkening factor (0.0 to 1.0, where 1.0 is no change and 0.0 is completely dark).
Returns:
The darkened hex color code.
"""
# Remove the '#' prefix if it exists
hex_color = hex_color.lstrip("#")

if len(hex_color) == 3:
hex_color = "".join(char * 2 for char in hex_color)

# Convert hex to RGB values
rgb = tuple(int(hex_color[i : i + 2], 16) for i in (0, 2, 4))

# Darken each component
darkened_rgb = tuple(int(channel * factor) for channel in rgb)

# Convert back to hex
darkened_hex = "#{:02X}{:02X}{:02X}".format(*darkened_rgb)

return darkened_hex
13 changes: 10 additions & 3 deletions fastagency/core/io/mesop/data_model.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,15 +6,22 @@

@dataclass
class Conversation:
id: str = ""
title: str = ""
completed: bool = False
waiting_for_feedback: bool = False
feedback: str = ""
is_from_the_past: bool = False
# messages: list[ConversationMessage] = field(default_factory=list)
messages: list[str] = field(default_factory=list)
fastagency: Optional[str] = None


@me.stateclass
class State:
conversation_completed: bool = False
waiting_for_feedback: bool = False
in_conversation: bool = False # True when in active conversation, or past one.
prompt: str = ""
feedback: str = ""
conversation: Conversation
past_conversations: list[Conversation] = field(default_factory=list)
hide_past: bool = True
fastagency: Optional[str] = None
Loading

0 comments on commit 554b345

Please sign in to comment.