mirror of
https://github.com/microsoft/autogen.git
synced 2025-07-07 09:01:29 +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? <!-- Please give a short summary of the change and the problem this solves. --> ## Related issue number <!-- For example: "Closes #1234" --> ## Checks - [x] 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. - [x] I've added tests (if relevant) corresponding to the changes introduced in this PR. - [x] I've made sure all auto checks have passed. Signed-off-by: zhanluxianshen <zhanluxianshen@163.com> Co-authored-by: Victor Dibia <victordibia@microsoft.com>
28 lines
785 B
Python
28 lines
785 B
Python
import os
|
|
|
|
from fastapi import FastAPI
|
|
|
|
from ..datamodel import Response
|
|
from ..teammanager import TeamManager
|
|
|
|
app = FastAPI()
|
|
team_manager = TeamManager()
|
|
|
|
|
|
@app.get("/predict/{task}")
|
|
async def predict(task: str):
|
|
response = Response(message="Task successfully completed", status=True, data=None)
|
|
try:
|
|
team_file_path = os.environ.get("AUTOGENSTUDIO_TEAM_FILE")
|
|
|
|
# Check if team_file_path is set
|
|
if team_file_path is None:
|
|
raise ValueError("AUTOGENSTUDIO_TEAM_FILE environment variable is not set")
|
|
|
|
result_message = await team_manager.run(task=task, team_config=team_file_path)
|
|
response.data = result_message
|
|
except Exception as e:
|
|
response.message = str(e)
|
|
response.status = False
|
|
return response
|