-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branches 'dev-x-bot' and 'dev-x-bot' of github.com:myshell-ai/S…
…hellAgent into dev-x-bot
- Loading branch information
Showing
71 changed files
with
753 additions
and
2,919 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -17,7 +17,7 @@ | |
'transitions', | ||
'states', | ||
'context', | ||
'payload', | ||
# 'payload', | ||
'condition', | ||
'blocks', | ||
'buttons', | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,141 @@ | ||
import json | ||
from pydantic import BaseModel | ||
from typing import List, Literal | ||
from proconfig.core import Automata, State | ||
from proconfig.core.automata import StateWithTransitions | ||
from proconfig.core.variables import InputTextVar | ||
from proconfig.core.common import TransitionCase | ||
from proconfig.core.render import Button | ||
from proconfig.utils.misc import tree_map | ||
from datetime import date | ||
|
||
|
||
class TwitterUser(BaseModel): | ||
creation_date: str = str(date.today()) | ||
user_id: str = "user_id_123" | ||
username: str = "username_default" | ||
name: str = "Default Name" | ||
is_private: bool = False | ||
is_verified: bool = False | ||
is_blue_verified: bool = False | ||
bot: bool = False | ||
verified_type: Literal['blue', 'business', 'government'] = 'blue' | ||
|
||
|
||
class TweetDetail(BaseModel): | ||
tweet_id: str = "tweet_id_123" | ||
creation_date: str = str(date.today()) | ||
text: str = "This is an example text" | ||
user: TwitterUser = TwitterUser() | ||
media_url: List[str] = [] | ||
|
||
|
||
x_special_events = { | ||
"X.MENTIONED": { | ||
"button_name": "Reply to mentioned", | ||
}, | ||
"X.PINNED.REPLIED": { | ||
"button_name": "Reply to pinned tweet" | ||
}, | ||
} | ||
|
||
# content: str = "" | ||
# description: Optional[str] = Field(default=None, description="Tooltip when hovering button") | ||
# on_click: Union[CustomEventName, EventPayload] = Field(..., description="event name triggered") | ||
# style: Dict[str, str] = None # TODO | ||
|
||
def replace_payload_to_payload1(x): | ||
if type(x) == str: | ||
x = x.replace("payload.", "payload1.") | ||
return x | ||
|
||
def convert_x_bot_to_automata(automata_x): | ||
# build default_payload | ||
default_payload = TweetDetail().model_dump_json(indent=2) | ||
# user = default_payload["user"] | ||
# default_payload["user"] = f"{{{{{user}}}}}" | ||
|
||
# automata_x = Automata.model_validate(automata_x) | ||
|
||
|
||
new_states = {} | ||
automata_x["blocks"] = automata_x.get("blocks", {}) | ||
for state_name, state in automata_x["blocks"].items(): | ||
timers = {} | ||
state["properties"] = state.get("properties", {}) | ||
if "timers" in state["properties"]: | ||
for timer_key, timer_info in state["properties"]["timers"].items(): | ||
timers[timer_info["event"]] = timer_key | ||
|
||
state["render"] = state.get("render", {}) | ||
buttons = state["render"].get("buttons", []) | ||
# buttons = state.render.buttons | ||
# print("buttons:", buttons) | ||
# first, handle the special events | ||
count = 0 | ||
state["transitions"] = state.get("transitions") or {} | ||
for event_name, transition_cases in state["transitions"].items(): | ||
if event_name in x_special_events: | ||
new_button = { | ||
"content": x_special_events[event_name]["button_name"], | ||
"on_click": { | ||
"event": event_name, | ||
"payload": {} | ||
} | ||
} | ||
# add a pseudo state | ||
new_state = { | ||
"display_name": "", | ||
"inputs": { | ||
"payload_str": { | ||
"type": "text", | ||
"name": "payload_str", | ||
"default_value": default_payload, | ||
"user_input": True, | ||
"source": "form" | ||
} | ||
}, | ||
"outputs": { | ||
"payload1": "{{json.loads(payload_str)}}" | ||
}, | ||
"transitions": { | ||
"ALWAYS": tree_map(replace_payload_to_payload1, transition_cases) | ||
} | ||
} | ||
new_state_name = f"{state_name}_event_{count}" | ||
# state.transitions[event_name] = TransitionCase(target=new_state_name) | ||
# new_states[new_state_name] = StateWithTransitions.model_validate(new_state) | ||
|
||
state["transitions"][event_name] = { | ||
"target": new_state_name | ||
} | ||
new_states[new_state_name] = new_state | ||
elif event_name in timers: | ||
new_button = { | ||
"content": f"Timer [{timers[event_name]}] triggered", | ||
"on_click": { | ||
"event": event_name, | ||
"payload": {} | ||
} | ||
} | ||
else: | ||
continue | ||
count += 1 | ||
buttons.append(new_button) | ||
# buttons.append(Button.model_validate(new_button)) | ||
state["render"]["buttons"] = buttons | ||
automata_x["blocks"].update(new_states) | ||
return automata_x | ||
return automata_x.model_dump() | ||
|
||
|
||
if __name__ == "__main__": | ||
automata_x_hello = json.load(open("temp/automata_x.json")) | ||
automata_hello = convert_x_bot_to_automata(automata_x_hello) | ||
# import pdb; pdb.set_trace() | ||
# InputTextVar.model_validate(automata_hello["blocks"]["idle_event_0"]["inputs"]["payload_str"]) | ||
# automata_hello_load = Automata.model_validate(automata_hello) | ||
json.dump(automata_hello, open("temp/automata_x_converted.json", "w"), indent=2) | ||
|
||
|
||
import pdb; pdb.set_trace() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,5 @@ | ||
from proconfig.widgets.myshell_widgets.tools.image_text_fuser import ImageTextFuserWidget | ||
from proconfig.widgets.myshell_widgets.tools.image_canvas import ImageCanvasWidget | ||
from proconfig.widgets.myshell_widgets.tools.twitter_search import XWidget | ||
from proconfig.widgets.myshell_widgets.tools.html2img import Html2ImgWidget | ||
from proconfig.widgets.myshell_widgets.tools.html2img import Html2ImgWidget | ||
from proconfig.widgets.myshell_widgets.myshell_widget_caller import MyShellAnyWidgetCallerWidget |
Oops, something went wrong.