Open noobHappylife opened 2 months ago
@AlexandreSajus Could you check this issue?
@AlexandreSajus Could you check this issue?
EDIT: My bad, I always thought you said the code works when debug was off. I don't really know how I could help here. Maybe R&D has an idea on what can be causing this.
We already discussed this on Discord. I think this is expected behavior. Debug mode has to consume performance somewhere (R&D should know more), and this causes any real-time application to be slower. I'm not sure this is an issue.
Kindly allow me to help u to solve the bug
@KunjShah95 You are already assigned to another issue. For hacktoberfest, we only assign issues one at a time. Please submit a PR on the other issue first, or remove your assignment.
Thank you.
i wanrt to work on this issue as i have removed my previous issue
hey there, this seems interesting and would love to work on this! Can this issue be assigned to me?
A new Quest has been launched in @Avaiga’s repo. Merge a PR that solves this issue to loot the Quest and earn your reward.
Some loot has been stashed in this issue to reward the solver!
🗡 Comment @quest-bot embark
to check-in for this Quest and start solving the issue. Other solvers will be notified!
⚔️ When you submit a PR, comment @quest-bot loot #1814
to link your PR to this Quest.
Questions? Check out the docs.
@quest-bot embark
@Rishi-0007 has embarked on their Quest. 🗡
HTML
and TypeScript
magic ✨This is not an assignment to the issue. Please check the repo’s contribution guidelines before submitting a PR.
Questions? Check out the docs.
Hi @jrobinAV , Please assign this to me.
hey @jrobinAV @AlexandreSajus Could you please assign this to me , I am interested in working on this issuse
Can you please assign this to me?
@noobHappylife I think we should help you use the chat control with streaming and all your problems will disappear :-) Partial does not seem to be a good fit for what you're trying to do. I'm not sure slowing down the refresh of partials so that it can show streaming data in a more convincing manner will help the Taipy community :-)
@noobHappylife I think we should help you use the chat control with streaming and all your problems will disappear :-) Partial does not seem to be a good fit for what you're trying to do. I'm not sure slowing down the refresh of partials so that it can show streaming data in a more convincing manner will help the Taipy community :-)
Sure it's understandable, perhaps a chat control is the way forward. Looking forward to have a working example with chat streaming. Thank you.
Here is a chat streaming example
import datetime
import re
import time
import typing as t
import requests # type: ignore[import-untyped]
import taipy.gui.builder as tgb
from taipy.gui import Gui, Icon, State, get_state_id, invoke_callback, invoke_long_callback
# The Wikipedia API used to generate content for a date
wiki_url = "https://en.wikipedia.org/api/rest_v1/feed/onthisday/{type}/{month}/{day}"
event_types = {
"happen": "events",
"passé": "events",
"born": "births",
"né": "births",
"dead": "deaths",
"mort": "deaths",
}
user_agent = "https://taipy.io/demo"
# the list of messages
messages: list[tuple[str, str, str]] = [] # (Message id, message, sender)
# the users
users = [
["wikipedia", Icon("https://www.wikipedia.org/static/apple-touch/wikipedia.png", "Wikipedia")],
["taipy", Icon("https://docs.taipy.io/en/latest/assets/images/favicon.png", "Taipy")],
]
def on_init(state: State):
# Do not share the message list with other users
state.messages = []
def add_image_to_message(state: State, idx: int, text: str, image_url: str):
msg_content: str = state.messages[idx][1]
pos = msg_content.find(text)
if pos > -1:
msg_content = msg_content[: pos + len(text)] + f"\n\n![{text}]({image_url})" + msg_content[pos + len(text) :]
set_message(state, msg_content, idx)
def update_message_with_image(gui: Gui, state_id: str, message_idx: int, text: str, image: dict):
if src := image.get("source"):
time.sleep(0.2)
invoke_callback(
gui,
state_id,
add_image_to_message,
[message_idx, text, src],
)
def update_message(state: State, json, event_type: str, for_date: str, idx: int):
if isinstance(json, dict):
# response header
set_message(state, f"{event_type} for {for_date}: \n", idx)
for event in json.get(event_type, []):
time.sleep(0.2)
# update response
append_to_message(state, f"\n* {event.get('year', '')}: {event.get('text', '')}", idx)
invoke_long_callback(
state=state,
user_function=update_message_with_image,
user_function_args=[
gui,
get_state_id(state),
idx,
event.get("text", ""),
event.get("pages", [{}])[0].get("thumbnail", {}),
],
)
def set_message(state: State, message: str, idx: t.Optional[int] = None):
if idx is not None and idx < len(state.messages):
msg = state.messages[idx]
state.messages[idx] = (msg[0], message, msg[2])
else:
idx = len(state.messages)
state.messages.append((f"{len(state.messages)}", message, users[0][0]))
state.refresh("messages")
return idx
def append_to_message(state: State, message: str, idx: int):
if idx < len(state.messages):
msg = state.messages[idx]
state.messages[idx] = (msg[0], f"{msg[1]}{message}", msg[2])
state.refresh("messages")
return idx
def request_wikipedia(gui: Gui, state_id: str, event_type: str, month: str, day: str):
idx = invoke_callback(
gui,
state_id,
set_message,
["requesting Wikipedia ..."],
)
request = wiki_url.format(type=event_type, month=month, day=day)
req = requests.get(request, headers={"accept": "application/json; charset=utf-8;", "User-Agent": user_agent})
if req.status_code == 200:
# display response
invoke_callback(
gui,
state_id,
update_message,
[req.json(), event_type, f"{month}/{day}", idx],
)
else:
invoke_callback(
gui,
state_id,
set_message,
[f"requesting Wikipedia failed: {req.status_code}", idx],
)
def send_message(state: State, id: str, payload: dict):
args = payload.get("args", [])
# display request
state.messages.append((f"{len(state.messages)}", args[2], args[3]))
state.refresh("messages")
# analyse request
request = args[2].lower()
type_event = None
for word in event_types:
if word in request:
type_event = event_types[word]
break
type_event = type_event if type_event else "events"
month = None
day = None
for m in re.finditer(r"(\d\d?)", request):
if month is None:
month = m.group()
elif day is None:
day = m.group()
break
if month is None:
month = f"{datetime.datetime.now().month}"
if day is None:
day = f"{datetime.datetime.now().day}"
# process request
invoke_long_callback(
state=state,
user_function=request_wikipedia,
user_function_args=[gui, get_state_id(state), type_event, month, day],
)
if __name__ == "__main__":
with tgb.Page() as page:
tgb.chat(
"{messages}",
users=users,
on_action=send_message,
height="80vh",
)
gui = Gui(page)
gui.run(title="🤖Wikipedia ChatBot")
you can ask what happened in 11 05 ? or who was born today ? No intelligence here :-)
What went wrong? 🤔
I'm working on a LLM chatbot example, I'm using update_content to update the partial while streaming response from the LLM. However, while it works, it only works well in debug mode. While turning debug mode off, the update becomes "chunky". (see the video attached).
Debug off, streaming and update_content seems to be very "chunky/jumpy" https://github.com/user-attachments/assets/39cebd87-95eb-4a65-8e38-1581032a7686
Debug on, streaming and update_content works https://github.com/user-attachments/assets/7fb47928-b991-4ee5-b5be-caabd1954386
Env: Taipy is installed from source, commit 2f33ab1e3cdbc2f91553fe16ff60ea8eeab73422 Ubuntu server 20.04 (Also tested on windows 10)
p.s. I'm not using chat control, because I can't get the streaming response work with it.
Expected Behavior
No response
Steps to Reproduce Issue
Here is the sample code
Solution Proposed
No response
Screenshots
Runtime Environment
No response
Browsers
No response
OS
No response
Version of Taipy
No response
Additional Context
No response
Acceptance Criteria
Code of Conduct