You can not select more than 25 topics Topics must start with a chinese character,a letter or number, can include dashes ('-') and can be up to 35 characters long.

db.py 6.3 kB

Add Token Streaming in AGS , Support Env variables (#5659) <!-- Thank you for your contribution! Please review https://microsoft.github.io/autogen/docs/Contribute before opening a pull request. --> This PR has 3 main improvements. - Token streaming - Adds support for environment variables in the app settings - Updates AGS to persist Gallery entry in db. ## Adds Token Streaming in AGS. Agentchat now supports streaming of tokens via `ModelClientStreamingChunkEvent `. This PR is to track progress on supporting that in the AutoGen Studio UI. If `model_client_stream` is enabled in an assitant agent, then token will be streamed in UI. ```python streaming_assistant = AssistantAgent( name="assistant", model_client=model_client, system_message="You are a helpful assistant.", model_client_stream=True, # Enable streaming tokens. ) ``` https://github.com/user-attachments/assets/74d43d78-6359-40c3-a78e-c84dcb5e02a1 ## Env Variables Also adds support for env variables in AGS Settings You can set env variables that are loaded just before a team is run. Handy to set variable to be used by tools etc. <img width="1291" alt="image" src="https://github.com/user-attachments/assets/437b9d90-ccee-42f7-be5d-94ab191afd67" /> > Note: the set variables are available to the server process. <!-- 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? <!-- Please give a short summary of the change and the problem this solves. --> ## Related issue number <!-- For example: "Closes #1234" --> Closes #5627 Closes #5662 Closes #5619 ## 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.
1 year ago
Add Token Streaming in AGS , Support Env variables (#5659) <!-- Thank you for your contribution! Please review https://microsoft.github.io/autogen/docs/Contribute before opening a pull request. --> This PR has 3 main improvements. - Token streaming - Adds support for environment variables in the app settings - Updates AGS to persist Gallery entry in db. ## Adds Token Streaming in AGS. Agentchat now supports streaming of tokens via `ModelClientStreamingChunkEvent `. This PR is to track progress on supporting that in the AutoGen Studio UI. If `model_client_stream` is enabled in an assitant agent, then token will be streamed in UI. ```python streaming_assistant = AssistantAgent( name="assistant", model_client=model_client, system_message="You are a helpful assistant.", model_client_stream=True, # Enable streaming tokens. ) ``` https://github.com/user-attachments/assets/74d43d78-6359-40c3-a78e-c84dcb5e02a1 ## Env Variables Also adds support for env variables in AGS Settings You can set env variables that are loaded just before a team is run. Handy to set variable to be used by tools etc. <img width="1291" alt="image" src="https://github.com/user-attachments/assets/437b9d90-ccee-42f7-be5d-94ab191afd67" /> > Note: the set variables are available to the server process. <!-- 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? <!-- Please give a short summary of the change and the problem this solves. --> ## Related issue number <!-- For example: "Closes #1234" --> Closes #5627 Closes #5662 Closes #5619 ## 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.
1 year ago
Add Token Streaming in AGS , Support Env variables (#5659) <!-- Thank you for your contribution! Please review https://microsoft.github.io/autogen/docs/Contribute before opening a pull request. --> This PR has 3 main improvements. - Token streaming - Adds support for environment variables in the app settings - Updates AGS to persist Gallery entry in db. ## Adds Token Streaming in AGS. Agentchat now supports streaming of tokens via `ModelClientStreamingChunkEvent `. This PR is to track progress on supporting that in the AutoGen Studio UI. If `model_client_stream` is enabled in an assitant agent, then token will be streamed in UI. ```python streaming_assistant = AssistantAgent( name="assistant", model_client=model_client, system_message="You are a helpful assistant.", model_client_stream=True, # Enable streaming tokens. ) ``` https://github.com/user-attachments/assets/74d43d78-6359-40c3-a78e-c84dcb5e02a1 ## Env Variables Also adds support for env variables in AGS Settings You can set env variables that are loaded just before a team is run. Handy to set variable to be used by tools etc. <img width="1291" alt="image" src="https://github.com/user-attachments/assets/437b9d90-ccee-42f7-be5d-94ab191afd67" /> > Note: the set variables are available to the server process. <!-- 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? <!-- Please give a short summary of the change and the problem this solves. --> ## Related issue number <!-- For example: "Closes #1234" --> Closes #5627 Closes #5662 Closes #5619 ## 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.
1 year ago
Add Token Streaming in AGS , Support Env variables (#5659) <!-- Thank you for your contribution! Please review https://microsoft.github.io/autogen/docs/Contribute before opening a pull request. --> This PR has 3 main improvements. - Token streaming - Adds support for environment variables in the app settings - Updates AGS to persist Gallery entry in db. ## Adds Token Streaming in AGS. Agentchat now supports streaming of tokens via `ModelClientStreamingChunkEvent `. This PR is to track progress on supporting that in the AutoGen Studio UI. If `model_client_stream` is enabled in an assitant agent, then token will be streamed in UI. ```python streaming_assistant = AssistantAgent( name="assistant", model_client=model_client, system_message="You are a helpful assistant.", model_client_stream=True, # Enable streaming tokens. ) ``` https://github.com/user-attachments/assets/74d43d78-6359-40c3-a78e-c84dcb5e02a1 ## Env Variables Also adds support for env variables in AGS Settings You can set env variables that are loaded just before a team is run. Handy to set variable to be used by tools etc. <img width="1291" alt="image" src="https://github.com/user-attachments/assets/437b9d90-ccee-42f7-be5d-94ab191afd67" /> > Note: the set variables are available to the server process. <!-- 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? <!-- Please give a short summary of the change and the problem this solves. --> ## Related issue number <!-- For example: "Closes #1234" --> Closes #5627 Closes #5662 Closes #5619 ## 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.
1 year ago
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160
  1. # defines how core data types in autogenstudio are serialized and stored in the database
  2. from datetime import datetime
  3. from enum import Enum
  4. from typing import List, Optional, Union
  5. from autogen_core import ComponentModel
  6. from pydantic import ConfigDict
  7. from sqlalchemy import ForeignKey, Integer, String
  8. from sqlmodel import JSON, Column, DateTime, Field, SQLModel, func
  9. from .types import (
  10. GalleryComponents,
  11. GalleryConfig,
  12. GalleryMetadata,
  13. MessageConfig,
  14. MessageMeta,
  15. SettingsConfig,
  16. TeamResult,
  17. )
  18. class Team(SQLModel, table=True):
  19. __table_args__ = {"sqlite_autoincrement": True}
  20. id: Optional[int] = Field(default=None, primary_key=True)
  21. created_at: datetime = Field(
  22. default_factory=datetime.now,
  23. sa_column=Column(DateTime(timezone=True), server_default=func.now()),
  24. ) # pylint: disable=not-callable
  25. updated_at: datetime = Field(
  26. default_factory=datetime.now,
  27. sa_column=Column(DateTime(timezone=True), onupdate=func.now()),
  28. ) # pylint: disable=not-callable
  29. user_id: Optional[str] = None
  30. version: Optional[str] = "0.0.1"
  31. component: Union[ComponentModel, dict] = Field(sa_column=Column(JSON))
  32. class Message(SQLModel, table=True):
  33. __table_args__ = {"sqlite_autoincrement": True}
  34. id: Optional[int] = Field(default=None, primary_key=True)
  35. created_at: datetime = Field(
  36. default_factory=datetime.now,
  37. sa_column=Column(DateTime(timezone=True), server_default=func.now()),
  38. ) # pylint: disable=not-callable
  39. updated_at: datetime = Field(
  40. default_factory=datetime.now,
  41. sa_column=Column(DateTime(timezone=True), onupdate=func.now()),
  42. ) # pylint: disable=not-callable
  43. user_id: Optional[str] = None
  44. version: Optional[str] = "0.0.1"
  45. config: Union[MessageConfig, dict] = Field(
  46. default_factory=lambda: MessageConfig(source="", content=""), sa_column=Column(JSON)
  47. )
  48. session_id: Optional[int] = Field(
  49. default=None, sa_column=Column(Integer, ForeignKey("session.id", ondelete="NO ACTION"))
  50. )
  51. run_id: Optional[int] = Field(default=None, sa_column=Column(Integer, ForeignKey("run.id", ondelete="CASCADE")))
  52. message_meta: Optional[Union[MessageMeta, dict]] = Field(default={}, sa_column=Column(JSON))
  53. class Session(SQLModel, table=True):
  54. __table_args__ = {"sqlite_autoincrement": True}
  55. id: Optional[int] = Field(default=None, primary_key=True)
  56. created_at: datetime = Field(
  57. default_factory=datetime.now,
  58. sa_column=Column(DateTime(timezone=True), server_default=func.now()),
  59. ) # pylint: disable=not-callable
  60. updated_at: datetime = Field(
  61. default_factory=datetime.now,
  62. sa_column=Column(DateTime(timezone=True), onupdate=func.now()),
  63. ) # pylint: disable=not-callable
  64. user_id: Optional[str] = None
  65. version: Optional[str] = "0.0.1"
  66. team_id: Optional[int] = Field(default=None, sa_column=Column(Integer, ForeignKey("team.id", ondelete="CASCADE")))
  67. name: Optional[str] = None
  68. class RunStatus(str, Enum):
  69. CREATED = "created"
  70. ACTIVE = "active"
  71. COMPLETE = "complete"
  72. ERROR = "error"
  73. STOPPED = "stopped"
  74. class Run(SQLModel, table=True):
  75. """Represents a single execution run within a session"""
  76. __table_args__ = {"sqlite_autoincrement": True}
  77. id: Optional[int] = Field(default=None, primary_key=True)
  78. created_at: datetime = Field(
  79. default_factory=datetime.now, sa_column=Column(DateTime(timezone=True), server_default=func.now())
  80. )
  81. updated_at: datetime = Field(
  82. default_factory=datetime.now, sa_column=Column(DateTime(timezone=True), onupdate=func.now())
  83. )
  84. session_id: Optional[int] = Field(
  85. default=None, sa_column=Column(Integer, ForeignKey("session.id", ondelete="CASCADE"), nullable=False)
  86. )
  87. status: RunStatus = Field(default=RunStatus.CREATED)
  88. # Store the original user task
  89. task: Union[MessageConfig, dict] = Field(
  90. default_factory=lambda: MessageConfig(source="", content=""), sa_column=Column(JSON)
  91. )
  92. # Store TeamResult which contains TaskResult
  93. team_result: Union[TeamResult, dict] = Field(default=None, sa_column=Column(JSON))
  94. error_message: Optional[str] = None
  95. version: Optional[str] = "0.0.1"
  96. messages: Union[List[Message], List[dict]] = Field(default_factory=list, sa_column=Column(JSON))
  97. model_config = ConfigDict(json_encoders={datetime: lambda v: v.isoformat()}) # type: ignore[call-arg]
  98. user_id: Optional[str] = None
  99. class Gallery(SQLModel, table=True):
  100. __table_args__ = {"sqlite_autoincrement": True}
  101. id: Optional[int] = Field(default=None, primary_key=True)
  102. created_at: datetime = Field(
  103. default_factory=datetime.now,
  104. sa_column=Column(DateTime(timezone=True), server_default=func.now()),
  105. ) # pylint: disable=not-callable
  106. updated_at: datetime = Field(
  107. default_factory=datetime.now,
  108. sa_column=Column(DateTime(timezone=True), onupdate=func.now()),
  109. ) # pylint: disable=not-callable
  110. user_id: Optional[str] = None
  111. version: Optional[str] = "0.0.1"
  112. config: Union[GalleryConfig, dict] = Field(
  113. default_factory=lambda: GalleryConfig(
  114. id="",
  115. name="",
  116. metadata=GalleryMetadata(author="", version=""),
  117. components=GalleryComponents(agents=[], models=[], tools=[], terminations=[], teams=[]),
  118. ),
  119. sa_column=Column(JSON),
  120. )
  121. model_config = ConfigDict(json_encoders={datetime: lambda v: v.isoformat()}) # type: ignore[call-arg]
  122. class Settings(SQLModel, table=True):
  123. __table_args__ = {"sqlite_autoincrement": True}
  124. id: Optional[int] = Field(default=None, primary_key=True)
  125. created_at: datetime = Field(
  126. default_factory=datetime.now,
  127. sa_column=Column(DateTime(timezone=True), server_default=func.now()),
  128. ) # pylint: disable=not-callable
  129. updated_at: datetime = Field(
  130. default_factory=datetime.now,
  131. sa_column=Column(DateTime(timezone=True), onupdate=func.now()),
  132. ) # pylint: disable=not-callable
  133. user_id: Optional[str] = None
  134. version: Optional[str] = "0.0.1"
  135. config: Union[SettingsConfig, dict] = Field(default_factory=SettingsConfig, sa_column=Column(JSON))