From 4b18aa5db2abcb56732ce29110ae5278582577a7 Mon Sep 17 00:00:00 2001 From: Oscar Fimbres Date: Sun, 29 Sep 2024 20:56:18 +0000 Subject: [PATCH 1/5] Expose ImportEndpoint --- .../autogen-studio/autogenstudio/datamodel.py | 29 ++++++++++++++ .../autogen-studio/autogenstudio/web/app.py | 40 ++++++++++++++++++- 2 files changed, 67 insertions(+), 2 deletions(-) diff --git a/samples/apps/autogen-studio/autogenstudio/datamodel.py b/samples/apps/autogen-studio/autogenstudio/datamodel.py index 92d60cf5c52..5efcd75e760 100644 --- a/samples/apps/autogen-studio/autogenstudio/datamodel.py +++ b/samples/apps/autogen-studio/autogenstudio/datamodel.py @@ -1,6 +1,7 @@ from datetime import datetime from enum import Enum from typing import Any, Callable, Dict, List, Literal, Optional, Union +from pydantic import BaseModel from sqlalchemy import ForeignKey, Integer, orm from sqlmodel import ( @@ -294,3 +295,31 @@ class SocketMessage(SQLModel, table=False): connection_id: str data: Dict[str, Any] type: str + + +class ExportedAgent(BaseModel): + id: Optional[int] = None + user_id: Optional[str] = None + version: Optional[str] = "0.0.1" + type: AgentType = AgentType.assistant + config: Union[AgentConfig, dict] + skills: List[Skill] + models: List[Model] + agents: List["ExportedAgent"] + task_instruction: Optional[str] = None + + +class ExportedAgentWithLink(BaseModel): + agent: ExportedAgent + link: WorkflowAgentLink + +class ExportedWorkflow(BaseModel): + id: Optional[int] = None + user_id: str = None + name: str + summary_method: str = WorkFlowSummaryMethod.last + sample_tasks: Optional[List[str]] + version: str = "0.0.1" + description: str + type: str = WorkFlowType.autonomous + agents: List[ExportedAgentWithLink] diff --git a/samples/apps/autogen-studio/autogenstudio/web/app.py b/samples/apps/autogen-studio/autogenstudio/web/app.py index bbd087f52ea..c68631e8a42 100644 --- a/samples/apps/autogen-studio/autogenstudio/web/app.py +++ b/samples/apps/autogen-studio/autogenstudio/web/app.py @@ -4,7 +4,7 @@ import threading import traceback from contextlib import asynccontextmanager -from typing import Any, Union +from typing import Any, List, Optional, Union from fastapi import FastAPI, WebSocket, WebSocketDisconnect from fastapi.middleware.cors import CORSMiddleware @@ -15,7 +15,7 @@ from ..chatmanager import AutoGenChatManager from ..database import workflow_from_id from ..database.dbmanager import DBManager -from ..datamodel import Agent, Message, Model, Response, Session, Skill, Workflow +from ..datamodel import Agent, ExportedAgent, ExportedWorkflow, Message, Model, Response, Session, Skill, Workflow from ..profiler import Profiler from ..utils import check_and_cast_datetime_fields, init_app_folders, md5_hash, test_model from ..version import VERSION @@ -322,6 +322,42 @@ async def export_workflow(workflow_id: int, user_id: str): return response.model_dump(mode="json") +@api.post("/workflows/import") +async def import_workflow(exported_workflow: ExportedWorkflow): + """Import a user workflow""" + async def create_agent_with_links(agent_data: ExportedAgent, parent_agent_id: Optional[int] = None): + agent = Agent(**agent_data.model_dump(exclude={"id", "models", "skills", "agents"})) + await create_agent(agent) + + for model in agent_data.models: + model.id = None + await create_model(model) + await link_agent_model(agent.id, model.id) + + for skill in agent_data.skills: + skill.id = None + await create_skill(skill) + await link_agent_skill(agent.id, skill.id) + + if parent_agent_id: + await link_agent_agent(parent_agent_id, agent.id) + + for nested_agent_data in agent_data.agents: + await create_agent_with_links(nested_agent_data, agent.id) + + return agent + + workflow = Workflow(**exported_workflow.model_dump(exclude={"id", "agents"})) + await create_workflow(workflow) + + for agent_with_link in exported_workflow.agents: + created_agent = await create_agent_with_links(agent_with_link.agent, None) + await link_workflow_agent(workflow.id, created_agent.id, agent_with_link.link.agent_type) + + response: Response = Response(status=True, message="Imported workflow", data=workflow) + return response + + @api.post("/workflows") async def create_workflow(workflow: Workflow): """Create a new workflow""" From 7a48828f2e163017cc3b5c49e93c833850ffccc5 Mon Sep 17 00:00:00 2001 From: ofimbres Date: Sun, 29 Sep 2024 16:01:51 -0700 Subject: [PATCH 2/5] Checkstyle --- samples/apps/autogen-studio/autogenstudio/datamodel.py | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/samples/apps/autogen-studio/autogenstudio/datamodel.py b/samples/apps/autogen-studio/autogenstudio/datamodel.py index 5efcd75e760..f2558771446 100644 --- a/samples/apps/autogen-studio/autogenstudio/datamodel.py +++ b/samples/apps/autogen-studio/autogenstudio/datamodel.py @@ -1,8 +1,8 @@ from datetime import datetime from enum import Enum from typing import Any, Callable, Dict, List, Literal, Optional, Union -from pydantic import BaseModel +from pydantic import BaseModel from sqlalchemy import ForeignKey, Integer, orm from sqlmodel import ( JSON, @@ -306,7 +306,7 @@ class ExportedAgent(BaseModel): skills: List[Skill] models: List[Model] agents: List["ExportedAgent"] - task_instruction: Optional[str] = None + task_instruction: Optional[str] = None class ExportedAgentWithLink(BaseModel): @@ -315,11 +315,11 @@ class ExportedAgentWithLink(BaseModel): class ExportedWorkflow(BaseModel): id: Optional[int] = None - user_id: str = None + user_id: str = None name: str summary_method: str = WorkFlowSummaryMethod.last sample_tasks: Optional[List[str]] - version: str = "0.0.1" + version: str = "0.0.1" description: str type: str = WorkFlowType.autonomous agents: List[ExportedAgentWithLink] From 28d8490fe231c1f5cbc61e097eee7bf4254b3ab5 Mon Sep 17 00:00:00 2001 From: ofimbres Date: Sun, 29 Sep 2024 16:05:18 -0700 Subject: [PATCH 3/5] Checkstyle --- .../autogen-studio/autogenstudio/datamodel.py | 1 + .../autogen-studio/autogenstudio/web/app.py | 2 + test/browser_utils/test_files/test_serp.html | 264 +++++++++--------- 3 files changed, 135 insertions(+), 132 deletions(-) diff --git a/samples/apps/autogen-studio/autogenstudio/datamodel.py b/samples/apps/autogen-studio/autogenstudio/datamodel.py index f2558771446..0a639b98341 100644 --- a/samples/apps/autogen-studio/autogenstudio/datamodel.py +++ b/samples/apps/autogen-studio/autogenstudio/datamodel.py @@ -313,6 +313,7 @@ class ExportedAgentWithLink(BaseModel): agent: ExportedAgent link: WorkflowAgentLink + class ExportedWorkflow(BaseModel): id: Optional[int] = None user_id: str = None diff --git a/samples/apps/autogen-studio/autogenstudio/web/app.py b/samples/apps/autogen-studio/autogenstudio/web/app.py index c68631e8a42..7d51a4a33ff 100644 --- a/samples/apps/autogen-studio/autogenstudio/web/app.py +++ b/samples/apps/autogen-studio/autogenstudio/web/app.py @@ -325,6 +325,8 @@ async def export_workflow(workflow_id: int, user_id: str): @api.post("/workflows/import") async def import_workflow(exported_workflow: ExportedWorkflow): """Import a user workflow""" + + async def create_agent_with_links(agent_data: ExportedAgent, parent_agent_id: Optional[int] = None): agent = Agent(**agent_data.model_dump(exclude={"id", "models", "skills", "agents"})) await create_agent(agent) diff --git a/test/browser_utils/test_files/test_serp.html b/test/browser_utils/test_files/test_serp.html index a5d89a22d9e..1daf5b7fb9e 100644 --- a/test/browser_utils/test_files/test_serp.html +++ b/test/browser_utils/test_files/test_serp.html @@ -1,147 +1,147 @@ -Microsoft wikipedia - Search
Copilot
Your everyday AI companion
About 310,000 results
Open links in new tab
  1. History of Microsoft - Wikipedia

  2. Microsoft Windows - Wikipedia

    WEBMicrosoft Windows is a product line of proprietary graphical operating systems developed and marketed by Microsoft. It is grouped into families …

    • Developer: Microsoft
    • Latest release: 22H2 (10.0.22621.2428) (October 10, 2023; 0 days ago) [±]
    • Initial release: November 20, 1985; 37 years ago
  3. Microsoft - Simple English Wikipedia, the free encyclopedia

  4. People also ask
    Microsoft was founded by Bill Gates and Paul Allen on April 4, 1975, to develop and sell BASIC interpreters for the Altair 8800. It rose to dominate the personal computer operating system market with MS-DOS in the mid-1980s, followed by Windows.
    en.wikipedia.org/wiki/Microsoft
    Its best-known software products are the Windows line of operating systems, the Microsoft Office suite, and the Internet Explorer and Edge web browsers. Its flagship hardware products are the Xbox video game consoles and the Microsoft Surface lineup of touchscreen personal computers.
    en.wikipedia.org/wiki/Microsoft
    Microsoft offers a variety of services, such as Azure, Bing, LinkedIn, Yammer, MSDN, Microsoft 365, OneDrive, Outlook.com, GitHub, TechNet, Pay, Microsoft Store, Windows Update, Xbox Game Pass and Xbox network. How to write a complaint about Microsoft?
    www.complaintsboard.com/microsoft-b107628/contacts
    Microsoft Corporation is an American multinational technology company with headquarters in Redmond, Washington. It develops, manufactures, licenses, supports, and sells computer software, consumer electronics, personal computers, and related services.
    www.definitions.net/definition/Microsoft
  5. About Microsoft | Mission and Vision | Microsoft

    WEBOur mission is to empower every person and every organization on the planet to achieve more. Learn more about our company, who we are and what we value.

  6. Timeline of Microsoft - Wikipedia

  7. Microsoft Corporation | History, Products, & Facts

    WEB2 days ago · Microsoft Corporation is a leading developer of computer software, operating systems, cloud computing, and artificial intelligence applications. The company also produces its own line of hybrid tablet …

  8. A Short History of Microsoft - ThoughtCo

    WEBJan 10, 2020 · Learn how Microsoft was founded by two childhood friends and became a global leader in software and hardware. Explore the milestones of Microsoft products, from MS-DOS and Windows to Office …

  9. Microsoft - Wikiwand

  10. Outline of Microsoft - Wikipedia

  11.  
Copilot
Your everyday AI companion
About 310,000 results
Open links in new tab
  1. History of Microsoft - Wikipedia

  2. Microsoft Windows - Wikipedia

    WEBMicrosoft Windows is a product line of proprietary graphical operating systems developed and marketed by Microsoft. It is grouped into families …

    • Developer: Microsoft
    • Latest release: 22H2 (10.0.22621.2428) (October 10, 2023; 0 days ago) [±]
    • Initial release: November 20, 1985; 37 years ago
  3. Microsoft - Simple English Wikipedia, the free encyclopedia

  4. People also ask
    Microsoft was founded by Bill Gates and Paul Allen on April 4, 1975, to develop and sell BASIC interpreters for the Altair 8800. It rose to dominate the personal computer operating system market with MS-DOS in the mid-1980s, followed by Windows.
    en.wikipedia.org/wiki/Microsoft
    Its best-known software products are the Windows line of operating systems, the Microsoft Office suite, and the Internet Explorer and Edge web browsers. Its flagship hardware products are the Xbox video game consoles and the Microsoft Surface lineup of touchscreen personal computers.
    en.wikipedia.org/wiki/Microsoft
    Microsoft offers a variety of services, such as Azure, Bing, LinkedIn, Yammer, MSDN, Microsoft 365, OneDrive, Outlook.com, GitHub, TechNet, Pay, Microsoft Store, Windows Update, Xbox Game Pass and Xbox network. How to write a complaint about Microsoft?
    www.complaintsboard.com/microsoft-b107628/contacts
    Microsoft Corporation is an American multinational technology company with headquarters in Redmond, Washington. It develops, manufactures, licenses, supports, and sells computer software, consumer electronics, personal computers, and related services.
    www.definitions.net/definition/Microsoft
  5. About Microsoft | Mission and Vision | Microsoft

    WEBOur mission is to empower every person and every organization on the planet to achieve more. Learn more about our company, who we are and what we value.

  6. Timeline of Microsoft - Wikipedia

  7. Microsoft Corporation | History, Products, & Facts

    WEB2 days ago · Microsoft Corporation is a leading developer of computer software, operating systems, cloud computing, and artificial intelligence applications. The company also produces its own line of hybrid tablet …

  8. A Short History of Microsoft - ThoughtCo

    WEBJan 10, 2020 · Learn how Microsoft was founded by two childhood friends and became a global leader in software and hardware. Explore the milestones of Microsoft products, from MS-DOS and Windows to Office …

  9. Microsoft - Wikiwand

  10. Outline of Microsoft - Wikipedia

  11.  
From 1992d286b34485b3e6e69f8a7c8484b9c5d897b7 Mon Sep 17 00:00:00 2001 From: ofimbres Date: Sun, 29 Sep 2024 16:08:10 -0700 Subject: [PATCH 4/5] Checkstyle --- samples/apps/autogen-studio/autogenstudio/web/app.py | 2 -- 1 file changed, 2 deletions(-) diff --git a/samples/apps/autogen-studio/autogenstudio/web/app.py b/samples/apps/autogen-studio/autogenstudio/web/app.py index 7d51a4a33ff..c68631e8a42 100644 --- a/samples/apps/autogen-studio/autogenstudio/web/app.py +++ b/samples/apps/autogen-studio/autogenstudio/web/app.py @@ -325,8 +325,6 @@ async def export_workflow(workflow_id: int, user_id: str): @api.post("/workflows/import") async def import_workflow(exported_workflow: ExportedWorkflow): """Import a user workflow""" - - async def create_agent_with_links(agent_data: ExportedAgent, parent_agent_id: Optional[int] = None): agent = Agent(**agent_data.model_dump(exclude={"id", "models", "skills", "agents"})) await create_agent(agent) From e0206a01eb92d89d62229edb72365605342f168a Mon Sep 17 00:00:00 2001 From: ofimbres Date: Sun, 29 Sep 2024 16:10:41 -0700 Subject: [PATCH 5/5] Checkstyle --- samples/apps/autogen-studio/autogenstudio/web/app.py | 1 + 1 file changed, 1 insertion(+) diff --git a/samples/apps/autogen-studio/autogenstudio/web/app.py b/samples/apps/autogen-studio/autogenstudio/web/app.py index c68631e8a42..7f9025bdf66 100644 --- a/samples/apps/autogen-studio/autogenstudio/web/app.py +++ b/samples/apps/autogen-studio/autogenstudio/web/app.py @@ -325,6 +325,7 @@ async def export_workflow(workflow_id: int, user_id: str): @api.post("/workflows/import") async def import_workflow(exported_workflow: ExportedWorkflow): """Import a user workflow""" + async def create_agent_with_links(agent_data: ExportedAgent, parent_agent_id: Optional[int] = None): agent = Agent(**agent_data.model_dump(exclude={"id", "models", "skills", "agents"})) await create_agent(agent)