mirror of
https://github.com/microsoft/autogen.git
synced 2025-06-26 22:30:10 +00:00

<!-- Thank you for your contribution! Please review https://microsoft.github.io/autogen/docs/Contribute before opening a pull request. --> <!-- Please add a reviewer to the assignee section when you create a PR. If you don't have the access to it, we will shortly find a reviewer and assign them to your PR. --> ## Why are these changes needed? https://github.com/user-attachments/assets/e160f16d-f42d-49e2-a6c6-687e4e6786f4 Enable file upload/paste as a task in AGS. Enables tasks like - Can you research and fact check the ideas in this screenshot? - Summarize this file Only text and images supported for now Underneath, it constructs TextMessage and Multimodal messages as the task. <!-- Please give a short summary of the change and the problem this solves. --> ## Related issue number <!-- For example: "Closes #1234" --> Closes #5773 ## Checks - [ ] I've included any doc changes needed for <https://microsoft.github.io/autogen/>. See <https://github.com/microsoft/autogen/blob/main/CONTRIBUTING.md> to build and test documentation locally. - [ ] I've added tests (if relevant) corresponding to the changes introduced in this PR. - [ ] I've made sure all auto checks have passed. --------- Co-authored-by: Jack Gerrits <jackgerrits@users.noreply.github.com>
24 lines
680 B
Python
24 lines
680 B
Python
from contextlib import contextmanager
|
|
from contextvars import ContextVar
|
|
from typing import Any, ClassVar, Generator
|
|
|
|
|
|
class RunContext:
|
|
RUN_CONTEXT_VAR: ClassVar[ContextVar] = ContextVar("RUN_CONTEXT_VAR")
|
|
|
|
@classmethod
|
|
@contextmanager
|
|
def populate_context(cls, run_id) -> Generator[None, Any, None]:
|
|
token = RunContext.RUN_CONTEXT_VAR.set(run_id)
|
|
try:
|
|
yield
|
|
finally:
|
|
RunContext.RUN_CONTEXT_VAR.reset(token)
|
|
|
|
@classmethod
|
|
def current_run_id(cls) -> str:
|
|
try:
|
|
return cls.RUN_CONTEXT_VAR.get()
|
|
except LookupError as e:
|
|
raise RuntimeError("Error getting run id") from e
|