Skip to content

Commit a8a8991

Browse files
authored
Merge pull request #20 from kagent-dev/peterj/addmodelendpoint
add /models endpoint
2 parents 586bda8 + 4a72b6e commit a8a8991

3 files changed

Lines changed: 57 additions & 3 deletions

File tree

python/packages/autogen-studio/autogenstudio/web/app.py

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
from .config import settings
1616
from .deps import cleanup_managers, init_auth_manager, init_managers, register_auth_dependencies
1717
from .initialization import AppInitializer
18-
from .routes import gallery, runs, sessions, settingsroute, teams, tool_servers, tools, validation, ws
18+
from .routes import gallery, models, runs, sessions, settingsroute, teams, tool_servers, tools, validation, ws
1919

2020
# Initialize application
2121
app_file_path = os.path.dirname(os.path.abspath(__file__))
@@ -155,6 +155,13 @@ async def lifespan(app: FastAPI) -> AsyncGenerator[None, None]:
155155
responses={404: {"description": "Not found"}},
156156
)
157157

158+
api.include_router(
159+
models.router,
160+
prefix="/models",
161+
tags=["models"],
162+
responses={404: {"description": "Not found"}},
163+
)
164+
158165
# Version endpoint
159166

160167

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
from typing import Any, Dict, List
2+
3+
from autogen_ext.models.anthropic._model_info import _MODEL_INFO as anthropic_models
4+
from autogen_ext.models.ollama._model_info import _MODEL_INFO as ollama_models
5+
from autogen_ext.models.openai._model_info import _MODEL_INFO as openai_models
6+
from fastapi import APIRouter
7+
8+
router = APIRouter()
9+
10+
11+
@router.get("/")
12+
async def list_models() -> Dict[str, List[Dict[str, Any]]]:
13+
# Get the model names from the model info, also get the "function_calling" value for each model
14+
15+
response = {
16+
"anthropic": [
17+
{
18+
"name": model,
19+
"function_calling": anthropic_models[model]["function_calling"],
20+
}
21+
for model in anthropic_models.keys()
22+
],
23+
"ollama": [
24+
{
25+
"name": model,
26+
"function_calling": ollama_models[model]["function_calling"],
27+
}
28+
for model in ollama_models.keys()
29+
],
30+
"openAI": [
31+
{
32+
"name": model,
33+
"function_calling": openai_models[model]["function_calling"],
34+
}
35+
for model in openai_models.keys()
36+
],
37+
"azureOpenAI": [
38+
{
39+
"name": model,
40+
"function_calling": openai_models[model]["function_calling"],
41+
}
42+
for model in openai_models.keys()
43+
],
44+
}
45+
46+
return response

python/packages/autogen-studio/pyproject.toml

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,10 +22,10 @@ dependencies = [
2222
"pydantic",
2323
"pydantic-settings",
2424
"fastapi[standard]",
25-
"typer",
25+
"typer",
2626
"aiofiles",
2727
"python-dotenv",
28-
"websockets",
28+
"websockets",
2929
"sqlmodel",
3030
"psycopg",
3131
"alembic",
@@ -36,6 +36,7 @@ dependencies = [
3636
"autogen-agentchat>=0.4.9.2,<0.6",
3737
"autogen-ext[magentic-one, openai, azure]>=0.4.2,<0.6",
3838
"anthropic",
39+
"ollama>=0.4.7",
3940
]
4041
optional-dependencies = {web = ["fastapi", "uvicorn"], database = ["psycopg"]}
4142

0 commit comments

Comments
 (0)