chainlit 1.1.306__py3-none-any.whl → 1.1.400rc0__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.

Potentially problematic release.


This version of chainlit might be problematic. Click here for more details.

Files changed (43) hide show
  1. chainlit/__init__.py +16 -3
  2. chainlit/config.py +4 -4
  3. chainlit/context.py +9 -0
  4. chainlit/copilot/dist/index.js +131 -129
  5. chainlit/data/__init__.py +2 -4
  6. chainlit/data/sql_alchemy.py +0 -4
  7. chainlit/discord/app.py +34 -6
  8. chainlit/emitter.py +5 -9
  9. chainlit/frontend/dist/assets/{DailyMotion-4ebdfef1.js → DailyMotion-5ec5da99.js} +1 -1
  10. chainlit/frontend/dist/assets/{Facebook-40982be3.js → Facebook-5a35cd37.js} +1 -1
  11. chainlit/frontend/dist/assets/{FilePlayer-5b3a4ad0.js → FilePlayer-57960f33.js} +1 -1
  12. chainlit/frontend/dist/assets/{Kaltura-6c5cb748.js → Kaltura-4e536514.js} +1 -1
  13. chainlit/frontend/dist/assets/{Mixcloud-7a304880.js → Mixcloud-dcf9d9d8.js} +1 -1
  14. chainlit/frontend/dist/assets/{Mux-1bd85c69.js → Mux-9eeb2f85.js} +1 -1
  15. chainlit/frontend/dist/assets/{Preview-e91eb05e.js → Preview-e47b3c35.js} +1 -1
  16. chainlit/frontend/dist/assets/{SoundCloud-2f2116b2.js → SoundCloud-ceb64ec3.js} +1 -1
  17. chainlit/frontend/dist/assets/{Streamable-b92c07ce.js → Streamable-917b74f2.js} +1 -1
  18. chainlit/frontend/dist/assets/{Twitch-58a2eb9a.js → Twitch-bb9e2900.js} +1 -1
  19. chainlit/frontend/dist/assets/{Vidyard-ad5bffa0.js → Vidyard-01a5b6c5.js} +1 -1
  20. chainlit/frontend/dist/assets/{Vimeo-8fb43e9c.js → Vimeo-c31b01d5.js} +1 -1
  21. chainlit/frontend/dist/assets/{Wistia-d03e6237.js → Wistia-17e84a59.js} +1 -1
  22. chainlit/frontend/dist/assets/{YouTube-6b7d1dae.js → YouTube-e58540d7.js} +1 -1
  23. chainlit/frontend/dist/assets/{index-4f01eb67.js → index-bfba5bbb.js} +103 -101
  24. chainlit/frontend/dist/assets/{react-plotly-ef3ac5f0.js → react-plotly-78a75e40.js} +1 -1
  25. chainlit/frontend/dist/index.html +1 -1
  26. chainlit/haystack/callbacks.py +1 -3
  27. chainlit/langchain/callbacks.py +0 -8
  28. chainlit/llama_index/callbacks.py +0 -6
  29. chainlit/message.py +0 -16
  30. chainlit/mistralai/__init__.py +2 -5
  31. chainlit/openai/__init__.py +0 -2
  32. chainlit/server.py +1 -1
  33. chainlit/session.py +2 -12
  34. chainlit/slack/app.py +18 -7
  35. chainlit/socket.py +10 -10
  36. chainlit/step.py +18 -26
  37. chainlit/teams/app.py +15 -6
  38. chainlit/user_session.py +0 -3
  39. {chainlit-1.1.306.dist-info → chainlit-1.1.400rc0.dist-info}/METADATA +1 -1
  40. chainlit-1.1.400rc0.dist-info/RECORD +81 -0
  41. chainlit-1.1.306.dist-info/RECORD +0 -81
  42. {chainlit-1.1.306.dist-info → chainlit-1.1.400rc0.dist-info}/WHEEL +0 -0
  43. {chainlit-1.1.306.dist-info → chainlit-1.1.400rc0.dist-info}/entry_points.txt +0 -0
@@ -21,7 +21,7 @@
21
21
  <script>
22
22
  const global = globalThis;
23
23
  </script>
24
- <script type="module" crossorigin src="/assets/index-4f01eb67.js"></script>
24
+ <script type="module" crossorigin src="/assets/index-bfba5bbb.js"></script>
25
25
  <link rel="stylesheet" href="/assets/index-aaf974a9.css">
26
26
  </head>
27
27
  <body>
@@ -68,9 +68,7 @@ class HaystackAgentCallbackHandler:
68
68
  self.last_tokens: List[str] = []
69
69
  self.answer_reached = False
70
70
 
71
- root_message = context.session.root_message
72
- parent_id = root_message.id if root_message else None
73
- run_step = Step(name=self.agent_name, type="run", parent_id=parent_id)
71
+ run_step = Step(name=self.agent_name, type="run")
74
72
  run_step.start = utc_now()
75
73
  run_step.input = kwargs
76
74
 
@@ -267,8 +267,6 @@ class LangchainTracer(BaseTracer, GenerationHelper, FinalStreamHelper):
267
267
 
268
268
  if self.context.current_step:
269
269
  self.root_parent_id = self.context.current_step.id
270
- elif self.context.session.root_message:
271
- self.root_parent_id = self.context.session.root_message.id
272
270
  else:
273
271
  self.root_parent_id = None
274
272
 
@@ -431,9 +429,6 @@ class LangchainTracer(BaseTracer, GenerationHelper, FinalStreamHelper):
431
429
  self.ignored_runs.add(str(run.id))
432
430
  return ignore, parent_id
433
431
 
434
- def _is_annotable(self, run: Run):
435
- return run.run_type in ["retriever", "llm"]
436
-
437
432
  def _start_trace(self, run: Run) -> None:
438
433
  super()._start_trace(run)
439
434
  context_var.set(self.context)
@@ -463,14 +458,11 @@ class LangchainTracer(BaseTracer, GenerationHelper, FinalStreamHelper):
463
458
  elif run.run_type == "embedding":
464
459
  step_type = "embedding"
465
460
 
466
- disable_feedback = not self._is_annotable(run)
467
-
468
461
  step = Step(
469
462
  id=str(run.id),
470
463
  name=run.name,
471
464
  type=step_type,
472
465
  parent_id=parent_id,
473
- disable_feedback=disable_feedback,
474
466
  )
475
467
  step.start = utc_now()
476
468
  step.input = run.inputs
@@ -41,11 +41,6 @@ class LlamaIndexCallbackHandler(TokenCountingHandler):
41
41
  return event_parent_id
42
42
  elif context_var.get().current_step:
43
43
  return context_var.get().current_step.id
44
- elif context_var.get().session.root_message:
45
- root_message = context_var.get().session.root_message
46
- if root_message:
47
- return root_message.id
48
- return None
49
44
  else:
50
45
  return None
51
46
 
@@ -73,7 +68,6 @@ class LlamaIndexCallbackHandler(TokenCountingHandler):
73
68
  type=step_type,
74
69
  parent_id=self._get_parent_id(parent_id),
75
70
  id=event_id,
76
- disable_feedback=True,
77
71
  )
78
72
 
79
73
  self.steps[event_id] = step
chainlit/message.py CHANGED
@@ -32,7 +32,6 @@ class MessageBase(ABC):
32
32
  author: str
33
33
  content: str = ""
34
34
  type: MessageStepType = "assistant_message"
35
- disable_feedback = False
36
35
  streaming = False
37
36
  created_at: Union[str, None] = None
38
37
  fail_on_persist_error: bool = False
@@ -67,7 +66,6 @@ class MessageBase(ABC):
67
66
  content=_dict["output"],
68
67
  author=_dict.get("name", config.ui.name),
69
68
  type=type, # type: ignore
70
- disable_feedback=_dict.get("disableFeedback", False),
71
69
  language=_dict.get("language"),
72
70
  )
73
71
 
@@ -87,7 +85,6 @@ class MessageBase(ABC):
87
85
  "createdAt": self.created_at,
88
86
  "language": self.language,
89
87
  "streaming": self.streaming,
90
- "disableFeedback": self.disable_feedback,
91
88
  "isError": self.is_error,
92
89
  "waitForAnswer": self.wait_for_answer,
93
90
  "indent": self.indent,
@@ -208,7 +205,6 @@ class Message(MessageBase):
208
205
  language (str, optional): Language of the code is the content is code. See https://react-code-blocks-rajinwonderland.vercel.app/?path=/story/codeblock--supported-languages for a list of supported languages.
209
206
  actions (List[Action], optional): A list of actions to send with the message.
210
207
  elements (List[ElementBased], optional): A list of elements to send with the message.
211
- disable_feedback (bool, optional): Hide the feedback buttons for this specific message
212
208
  """
213
209
 
214
210
  def __init__(
@@ -218,7 +214,6 @@ class Message(MessageBase):
218
214
  language: Optional[str] = None,
219
215
  actions: Optional[List[Action]] = None,
220
216
  elements: Optional[List[ElementBased]] = None,
221
- disable_feedback: bool = False,
222
217
  type: MessageStepType = "assistant_message",
223
218
  metadata: Optional[Dict] = None,
224
219
  tags: Optional[List[str]] = None,
@@ -257,7 +252,6 @@ class Message(MessageBase):
257
252
  self.type = type
258
253
  self.actions = actions if actions is not None else []
259
254
  self.elements = elements if elements is not None else []
260
- self.disable_feedback = disable_feedback
261
255
 
262
256
  super().__post_init__()
263
257
 
@@ -269,8 +263,6 @@ class Message(MessageBase):
269
263
  trace_event("send_message")
270
264
  await super().send()
271
265
 
272
- context.session.root_message = self
273
-
274
266
  # Create tasks for all actions and elements
275
267
  tasks = [action.send(for_id=self.id) for action in self.actions]
276
268
  tasks.extend(element.send(for_id=self.id) for element in self.elements)
@@ -355,7 +347,6 @@ class AskUserMessage(AskMessageBase):
355
347
  Args:
356
348
  content (str): The content of the prompt.
357
349
  author (str, optional): The author of the message, this will be used in the UI. Defaults to the assistant name (see config).
358
- disable_feedback (bool, optional): Hide the feedback buttons for this specific message
359
350
  timeout (int, optional): The number of seconds to wait for an answer before raising a TimeoutError.
360
351
  raise_on_timeout (bool, optional): Whether to raise a socketio TimeoutError if the user does not answer in time.
361
352
  """
@@ -365,7 +356,6 @@ class AskUserMessage(AskMessageBase):
365
356
  content: str,
366
357
  author: str = config.ui.name,
367
358
  type: MessageStepType = "assistant_message",
368
- disable_feedback: bool = True,
369
359
  timeout: int = 60,
370
360
  raise_on_timeout: bool = False,
371
361
  ):
@@ -373,7 +363,6 @@ class AskUserMessage(AskMessageBase):
373
363
  self.author = author
374
364
  self.timeout = timeout
375
365
  self.type = type
376
- self.disable_feedback = disable_feedback
377
366
  self.raise_on_timeout = raise_on_timeout
378
367
 
379
368
  super().__post_init__()
@@ -420,7 +409,6 @@ class AskFileMessage(AskMessageBase):
420
409
  max_size_mb (int, optional): Maximum size per file in MB. Maximum value is 100.
421
410
  max_files (int, optional): Maximum number of files to upload. Maximum value is 10.
422
411
  author (str, optional): The author of the message, this will be used in the UI. Defaults to the assistant name (see config).
423
- disable_feedback (bool, optional): Hide the feedback buttons for this specific message
424
412
  timeout (int, optional): The number of seconds to wait for an answer before raising a TimeoutError.
425
413
  raise_on_timeout (bool, optional): Whether to raise a socketio TimeoutError if the user does not answer in time.
426
414
  """
@@ -433,7 +421,6 @@ class AskFileMessage(AskMessageBase):
433
421
  max_files=1,
434
422
  author=config.ui.name,
435
423
  type: MessageStepType = "assistant_message",
436
- disable_feedback: bool = True,
437
424
  timeout=90,
438
425
  raise_on_timeout=False,
439
426
  ):
@@ -445,7 +432,6 @@ class AskFileMessage(AskMessageBase):
445
432
  self.author = author
446
433
  self.timeout = timeout
447
434
  self.raise_on_timeout = raise_on_timeout
448
- self.disable_feedback = disable_feedback
449
435
 
450
436
  super().__post_init__()
451
437
 
@@ -509,14 +495,12 @@ class AskActionMessage(AskMessageBase):
509
495
  content: str,
510
496
  actions: List[Action],
511
497
  author=config.ui.name,
512
- disable_feedback=True,
513
498
  timeout=90,
514
499
  raise_on_timeout=False,
515
500
  ):
516
501
  self.content = content
517
502
  self.actions = actions
518
503
  self.author = author
519
- self.disable_feedback = disable_feedback
520
504
  self.timeout = timeout
521
505
  self.raise_on_timeout = raise_on_timeout
522
506
 
@@ -1,12 +1,11 @@
1
1
  import asyncio
2
2
  from typing import Union
3
3
 
4
- from literalai import ChatGeneration, CompletionGeneration
5
- from literalai.helper import timestamp_utc
6
-
7
4
  from chainlit.context import get_context
8
5
  from chainlit.step import Step
9
6
  from chainlit.utils import check_module_version
7
+ from literalai import ChatGeneration, CompletionGeneration
8
+ from literalai.helper import timestamp_utc
10
9
 
11
10
 
12
11
  def instrument_mistralai():
@@ -20,8 +19,6 @@ def instrument_mistralai():
20
19
  parent_id = None
21
20
  if context.current_step:
22
21
  parent_id = context.current_step.id
23
- elif context.session.root_message:
24
- parent_id = context.session.root_message.id
25
22
 
26
23
  step = Step(
27
24
  name=generation.model if generation.model else generation.provider,
@@ -24,8 +24,6 @@ def instrument_openai():
24
24
  parent_id = None
25
25
  if context.current_step:
26
26
  parent_id = context.current_step.id
27
- elif context.session.root_message:
28
- parent_id = context.session.root_message.id
29
27
 
30
28
  step = Step(
31
29
  name=generation.model if generation.model else generation.provider,
chainlit/server.py CHANGED
@@ -332,7 +332,7 @@ def get_user_facing_url(url: URL):
332
332
  if config_url.path.endswith("/"):
333
333
  config_url = config_url.replace(path=config_url.path[:-1])
334
334
 
335
- return config_url.__str__()
335
+ return config_url.__str__() + url.path
336
336
 
337
337
 
338
338
  @router.get("/auth/config")
chainlit/session.py CHANGED
@@ -35,17 +35,16 @@ class JSONEncoderIgnoreNonSerializable(json.JSONEncoder):
35
35
  return None
36
36
 
37
37
 
38
-
39
38
  def clean_metadata(metadata: Dict, max_size: int = 1048576):
40
39
  cleaned_metadata = json.loads(
41
40
  json.dumps(metadata, cls=JSONEncoderIgnoreNonSerializable, ensure_ascii=False)
42
41
  )
43
42
 
44
- metadata_size = len(json.dumps(cleaned_metadata).encode('utf-8'))
43
+ metadata_size = len(json.dumps(cleaned_metadata).encode("utf-8"))
45
44
  if metadata_size > max_size:
46
45
  # Redact the metadata if it exceeds the maximum size
47
46
  cleaned_metadata = {
48
- 'message': f'Metadata size exceeds the limit of {max_size} bytes. Redacted.'
47
+ "message": f"Metadata size exceeds the limit of {max_size} bytes. Redacted."
49
48
  }
50
49
 
51
50
  return cleaned_metadata
@@ -71,8 +70,6 @@ class BaseSession:
71
70
  token: Optional[str],
72
71
  # User specific environment variables. Empty if no user environment variables are required.
73
72
  user_env: Optional[Dict[str, str]],
74
- # Last message at the root of the chat
75
- root_message: Optional["Message"] = None,
76
73
  # Chat profile selected before the session was created
77
74
  chat_profile: Optional[str] = None,
78
75
  # Origin of the request
@@ -84,7 +81,6 @@ class BaseSession:
84
81
  self.user = user
85
82
  self.client_type = client_type
86
83
  self.token = token
87
- self.root_message = root_message
88
84
  self.has_first_interaction = False
89
85
  self.user_env = user_env or {}
90
86
  self.chat_profile = chat_profile
@@ -178,8 +174,6 @@ class HTTPSession(BaseSession):
178
174
  # Logged-in user token
179
175
  token: Optional[str] = None,
180
176
  user_env: Optional[Dict[str, str]] = None,
181
- # Last message at the root of the chat
182
- root_message: Optional["Message"] = None,
183
177
  # Origin of the request
184
178
  http_referer: Optional[str] = None,
185
179
  ):
@@ -190,7 +184,6 @@ class HTTPSession(BaseSession):
190
184
  token=token,
191
185
  client_type=client_type,
192
186
  user_env=user_env,
193
- root_message=root_message,
194
187
  http_referer=http_referer,
195
188
  )
196
189
 
@@ -233,8 +226,6 @@ class WebsocketSession(BaseSession):
233
226
  user: Optional[Union["User", "PersistedUser"]] = None,
234
227
  # Logged-in user token
235
228
  token: Optional[str] = None,
236
- # Last message at the root of the chat
237
- root_message: Optional["Message"] = None,
238
229
  # Chat profile selected before the session was created
239
230
  chat_profile: Optional[str] = None,
240
231
  # Languages of the user's browser
@@ -249,7 +240,6 @@ class WebsocketSession(BaseSession):
249
240
  token=token,
250
241
  user_env=user_env,
251
242
  client_type=client_type,
252
- root_message=root_message,
253
243
  chat_profile=chat_profile,
254
244
  http_referer=http_referer,
255
245
  )
chainlit/slack/app.py CHANGED
@@ -2,12 +2,13 @@ import asyncio
2
2
  import os
3
3
  import re
4
4
  import uuid
5
+ from datetime import datetime
5
6
  from functools import partial
6
7
  from typing import Dict, List, Optional, Union
7
8
 
8
9
  import httpx
9
10
  from chainlit.config import config
10
- from chainlit.context import ChainlitContext, HTTPSession, context_var
11
+ from chainlit.context import ChainlitContext, HTTPSession, context, context_var
11
12
  from chainlit.data import get_data_layer
12
13
  from chainlit.element import Element, ElementDict
13
14
  from chainlit.emitter import BaseChainlitEmitter
@@ -78,7 +79,7 @@ class SlackEmitter(BaseChainlitEmitter):
78
79
  if is_chain_of_thought or is_empty_output or not is_message:
79
80
  return
80
81
 
81
- enable_feedback = not step_dict.get("disableFeedback") and get_data_layer()
82
+ enable_feedback = get_data_layer()
82
83
  blocks: List[Dict] = [
83
84
  {
84
85
  "type": "section",
@@ -86,6 +87,8 @@ class SlackEmitter(BaseChainlitEmitter):
86
87
  }
87
88
  ]
88
89
  if enable_feedback:
90
+ current_run = context.current_run
91
+ scorable_id = current_run.id if current_run else step_dict.get("id")
89
92
  blocks.append(
90
93
  {
91
94
  "type": "actions",
@@ -98,7 +101,7 @@ class SlackEmitter(BaseChainlitEmitter):
98
101
  "emoji": True,
99
102
  "text": ":thumbsdown:",
100
103
  },
101
- "value": step_dict.get("id"),
104
+ "value": scorable_id,
102
105
  },
103
106
  {
104
107
  "action_id": "thumbup",
@@ -108,7 +111,7 @@ class SlackEmitter(BaseChainlitEmitter):
108
111
  "emoji": True,
109
112
  "text": ":thumbsup:",
110
113
  },
111
- "value": step_dict.get("id"),
114
+ "value": scorable_id,
112
115
  },
113
116
  ],
114
117
  }
@@ -247,6 +250,7 @@ async def download_slack_files(session: HTTPSession, files, token):
247
250
  async def process_slack_message(
248
251
  event,
249
252
  say,
253
+ thread_id: str,
250
254
  thread_name: Optional[str] = None,
251
255
  bind_thread_to_user=False,
252
256
  thread_ts: Optional[str] = None,
@@ -254,7 +258,6 @@ async def process_slack_message(
254
258
  user = await get_user(event["user"])
255
259
 
256
260
  channel_id = event["channel"]
257
- thread_id = str(uuid.uuid5(uuid.NAMESPACE_DNS, thread_ts or channel_id))
258
261
 
259
262
  text = event.get("text")
260
263
  slack_files = event.get("files", [])
@@ -325,13 +328,21 @@ async def handle_app_home_opened(event, say):
325
328
  @slack_app.event("app_mention")
326
329
  async def handle_app_mentions(event, say):
327
330
  thread_ts = event.get("thread_ts", event["ts"])
328
- await process_slack_message(event, say, thread_ts=thread_ts)
331
+ thread_id = str(uuid.uuid5(uuid.NAMESPACE_DNS, thread_ts))
332
+
333
+ await process_slack_message(event, say, thread_id=thread_id, thread_ts=thread_ts)
329
334
 
330
335
 
331
336
  @slack_app.event("message")
332
337
  async def handle_message(message, say):
333
338
  user = await get_user(message["user"])
334
- thread_name = f"{user.identifier} Slack DM"
339
+ thread_id = str(
340
+ uuid.uuid5(
341
+ uuid.NAMESPACE_DNS,
342
+ message["channel"] + datetime.today().strftime("%Y-%m-%d"),
343
+ )
344
+ )
345
+ thread_name = f"{user.identifier} Slack DM {datetime.today().strftime('%Y-%m-%d')}"
335
346
  await process_slack_message(message, say, thread_name, True)
336
347
 
337
348
 
chainlit/socket.py CHANGED
@@ -7,9 +7,9 @@ from urllib.parse import unquote
7
7
 
8
8
  from chainlit.action import Action
9
9
  from chainlit.auth import get_current_user, require_login
10
+ from chainlit.chat_context import chat_context
10
11
  from chainlit.config import config
11
12
  from chainlit.context import init_ws_context
12
- from chainlit.chat_context import chat_context
13
13
  from chainlit.data import get_data_layer
14
14
  from chainlit.element import Element
15
15
  from chainlit.logger import logger
@@ -184,11 +184,11 @@ async def connection_successful(sid):
184
184
  {"interaction": "resume", "thread_id": thread.get("id")},
185
185
  )
186
186
  await config.code.on_chat_resume(thread)
187
-
187
+
188
188
  for step in thread.get("steps", []):
189
189
  if "message" in step["type"]:
190
190
  chat_context.add(Message.from_dict(step))
191
-
191
+
192
192
  await context.emitter.resume_thread(thread)
193
193
  return
194
194
 
@@ -244,7 +244,7 @@ async def stop(sid):
244
244
  trace_event("stop_task")
245
245
 
246
246
  init_ws_context(session)
247
- await Message(content="Task manually stopped.", disable_feedback=True).send()
247
+ await Message(content="Task manually stopped.").send()
248
248
 
249
249
  if session.current_task:
250
250
  session.current_task.cancel()
@@ -282,18 +282,18 @@ async def edit_message(sid, payload: MessagePayload):
282
282
  context = init_ws_context(session)
283
283
 
284
284
  messages = chat_context.get()
285
-
285
+
286
286
  orig_message = None
287
-
287
+
288
288
  for message in messages:
289
289
  if orig_message:
290
- await message.remove()
291
-
290
+ await message.remove()
291
+
292
292
  if message.id == payload["message"]["id"]:
293
293
  message.content = payload["message"]["output"]
294
294
  await message.update()
295
295
  orig_message = message
296
-
296
+
297
297
  await context.emitter.task_start()
298
298
 
299
299
  if config.code.on_message:
@@ -303,7 +303,7 @@ async def edit_message(sid, payload: MessagePayload):
303
303
  pass
304
304
  finally:
305
305
  await context.emitter.task_end()
306
-
306
+
307
307
 
308
308
  @sio.on("client_message")
309
309
  async def message(sid, payload: MessagePayload):
chainlit/step.py CHANGED
@@ -7,7 +7,7 @@ from functools import wraps
7
7
  from typing import Callable, Dict, List, Optional, TypedDict, Union
8
8
 
9
9
  from chainlit.config import config
10
- from chainlit.context import context, local_steps
10
+ from chainlit.context import CL_RUN_NAMES, context, local_steps
11
11
  from chainlit.data import get_data_layer
12
12
  from chainlit.element import Element
13
13
  from chainlit.logger import logger
@@ -18,13 +18,23 @@ from literalai.helper import utc_now
18
18
  from literalai.step import StepType, TrueStepType
19
19
 
20
20
 
21
+ def check_add_step_in_cot(step: "Step"):
22
+ is_message = step.type in [
23
+ "user_message",
24
+ "assistant_message",
25
+ ]
26
+ is_cl_run = step.name in CL_RUN_NAMES and step.type == "run"
27
+ if config.ui.cot == "hidden" and not is_message and not is_cl_run:
28
+ return False
29
+ return True
30
+
31
+
21
32
  class StepDict(TypedDict, total=False):
22
33
  name: str
23
34
  type: StepType
24
35
  id: str
25
36
  threadId: str
26
37
  parentId: Optional[str]
27
- disableFeedback: bool
28
38
  streaming: bool
29
39
  waitForAnswer: Optional[bool]
30
40
  isError: Optional[bool]
@@ -48,8 +58,8 @@ def step(
48
58
  name: Optional[str] = "",
49
59
  type: TrueStepType = "undefined",
50
60
  id: Optional[str] = None,
61
+ parent_id: Optional[str] = None,
51
62
  tags: Optional[List[str]] = None,
52
- disable_feedback: bool = True,
53
63
  language: Optional[str] = None,
54
64
  show_input: Union[bool, str] = "json",
55
65
  ):
@@ -70,7 +80,7 @@ def step(
70
80
  type=type,
71
81
  name=name,
72
82
  id=id,
73
- disable_feedback=disable_feedback,
83
+ parent_id=parent_id,
74
84
  tags=tags,
75
85
  language=language,
76
86
  show_input=show_input,
@@ -97,7 +107,7 @@ def step(
97
107
  type=type,
98
108
  name=name,
99
109
  id=id,
100
- disable_feedback=disable_feedback,
110
+ parent_id=parent_id,
101
111
  tags=tags,
102
112
  language=language,
103
113
  show_input=show_input,
@@ -130,7 +140,6 @@ class Step:
130
140
  type: TrueStepType
131
141
  id: str
132
142
  parent_id: Optional[str]
133
- disable_feedback: bool
134
143
 
135
144
  streaming: bool
136
145
  persisted: bool
@@ -158,7 +167,6 @@ class Step:
158
167
  elements: Optional[List[Element]] = None,
159
168
  metadata: Optional[Dict] = None,
160
169
  tags: Optional[List[str]] = None,
161
- disable_feedback: bool = True,
162
170
  language: Optional[str] = None,
163
171
  show_input: Union[bool, str] = "json",
164
172
  ):
@@ -170,7 +178,6 @@ class Step:
170
178
  self.name = name or ""
171
179
  self.type = type
172
180
  self.id = id or str(uuid.uuid4())
173
- self.disable_feedback = disable_feedback
174
181
  self.metadata = metadata or {}
175
182
  self.tags = tags
176
183
  self.is_error = False
@@ -256,7 +263,6 @@ class Step:
256
263
  "id": self.id,
257
264
  "threadId": self.thread_id,
258
265
  "parentId": self.parent_id,
259
- "disableFeedback": self.disable_feedback,
260
266
  "streaming": self.streaming,
261
267
  "metadata": self.metadata,
262
268
  "tags": self.tags,
@@ -295,10 +301,7 @@ class Step:
295
301
  tasks = [el.send(for_id=self.id) for el in self.elements]
296
302
  await asyncio.gather(*tasks)
297
303
 
298
- if config.ui.hide_cot and self.type not in [
299
- "user_message",
300
- "assistant_message",
301
- ]:
304
+ if not check_add_step_in_cot(self):
302
305
  return True
303
306
 
304
307
  await context.emitter.update_step(step_dict)
@@ -352,10 +355,7 @@ class Step:
352
355
  tasks = [el.send(for_id=self.id) for el in self.elements]
353
356
  await asyncio.gather(*tasks)
354
357
 
355
- if config.ui.hide_cot and self.type not in [
356
- "user_message",
357
- "assistant_message",
358
- ]:
358
+ if not check_add_step_in_cot(self):
359
359
  return self
360
360
 
361
361
  await context.emitter.send_step(step_dict)
@@ -380,10 +380,7 @@ class Step:
380
380
 
381
381
  assert self.id
382
382
 
383
- if config.ui.hide_cot and self.type not in [
384
- "user_message",
385
- "assistant_message",
386
- ]:
383
+ if not check_add_step_in_cot(self):
387
384
  return
388
385
 
389
386
  if not self.streaming:
@@ -404,7 +401,6 @@ class Step:
404
401
  id=self.id,
405
402
  parent_id=self.parent_id,
406
403
  thread_id=self.thread_id,
407
- disable_feedback=self.disable_feedback,
408
404
  )
409
405
 
410
406
  # Handle Context Manager Protocol
@@ -416,8 +412,6 @@ class Step:
416
412
  if not self.parent_id:
417
413
  if parent_step:
418
414
  self.parent_id = parent_step.id
419
- elif context.session.root_message:
420
- self.parent_id = context.session.root_message.id
421
415
  context.active_steps.append(self)
422
416
  local_steps.set(previous_steps + [self])
423
417
  await self.send()
@@ -449,8 +443,6 @@ class Step:
449
443
  if not self.parent_id:
450
444
  if parent_step:
451
445
  self.parent_id = parent_step.id
452
- elif context.session.root_message:
453
- self.parent_id = context.session.root_message.id
454
446
  context.active_steps.append(self)
455
447
  local_steps.set(previous_steps + [self])
456
448
 
chainlit/teams/app.py CHANGED
@@ -3,6 +3,7 @@ import base64
3
3
  import mimetypes
4
4
  import os
5
5
  import uuid
6
+ from datetime import datetime
6
7
  from typing import TYPE_CHECKING, Dict, List, Literal, Optional, Union
7
8
 
8
9
  import filetype
@@ -28,7 +29,7 @@ from botbuilder.schema import (
28
29
  HeroCard,
29
30
  )
30
31
  from chainlit.config import config
31
- from chainlit.context import ChainlitContext, HTTPSession, context_var
32
+ from chainlit.context import ChainlitContext, HTTPSession, context, context_var
32
33
  from chainlit.data import get_data_layer
33
34
  from chainlit.element import Element, ElementDict
34
35
  from chainlit.emitter import BaseChainlitEmitter
@@ -96,19 +97,21 @@ class TeamsEmitter(BaseChainlitEmitter):
96
97
  return
97
98
  else:
98
99
  reply = MessageFactory.text(step_dict["output"])
99
- enable_feedback = not step_dict.get("disableFeedback") and get_data_layer()
100
+ enable_feedback = get_data_layer()
100
101
  if enable_feedback:
102
+ current_run = context.current_run
103
+ scorable_id = current_run.id if current_run else step_dict["id"]
101
104
  like_button = CardAction(
102
105
  type=ActionTypes.message_back,
103
106
  title="👍",
104
107
  text="like",
105
- value={"feedback": "like", "step_id": step_dict["id"]},
108
+ value={"feedback": "like", "step_id": scorable_id},
106
109
  )
107
110
  dislike_button = CardAction(
108
111
  type=ActionTypes.message_back,
109
112
  title="👎",
110
113
  text="dislike",
111
- value={"feedback": "dislike", "step_id": step_dict["id"]},
114
+ value={"feedback": "dislike", "step_id": scorable_id},
112
115
  )
113
116
  card = HeroCard(buttons=[like_button, dislike_button])
114
117
  attachment = Attachment(
@@ -225,7 +228,13 @@ async def process_teams_message(
225
228
  user = await get_user(turn_context.activity.from_property)
226
229
 
227
230
  thread_id = str(
228
- uuid.uuid5(uuid.NAMESPACE_DNS, str(turn_context.activity.conversation.id))
231
+ uuid.uuid5(
232
+ uuid.NAMESPACE_DNS,
233
+ str(
234
+ turn_context.activity.conversation.id
235
+ + datetime.today().strftime("%Y-%m-%d")
236
+ ),
237
+ )
229
238
  )
230
239
 
231
240
  text = clean_content(turn_context.activity)
@@ -314,7 +323,7 @@ async def handle_message(turn_context: TurnContext):
314
323
  conversation=turn_context.activity.conversation,
315
324
  )
316
325
  await turn_context.send_activity(typing_activity)
317
- thread_name = f"{turn_context.activity.from_property.name} Teams DM"
326
+ thread_name = f"{turn_context.activity.from_property.name} Teams DM {datetime.today().strftime('%Y-%m-%d')}"
318
327
  await process_teams_message(turn_context, thread_name)
319
328
 
320
329