Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(autogenstudio): Anthropic Support #3344

Closed
wants to merge 5 commits into from
Closed
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions samples/apps/autogen-studio/autogenstudio/database/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -166,6 +166,13 @@ def init_db_samples(dbmanager: Any):
user_id="guestuser@gmail.com",
api_type="google",
)

anthropic_claude_model = Model(
model="claude-3-sonnet-20240229",
description="Anthropic's Claude 3 Sonnet model",
user_id="guestuser@gmail.com",
api_type="anthropic",
)

# skills

Expand Down Expand Up @@ -272,6 +279,7 @@ def init_db_samples(dbmanager: Any):
with Session(dbmanager.engine) as session:
session.add(zephyr_model)
session.add(google_gemini_model)
session.add(anthropic_claude_model)
session.add(azure_model)
session.add(gpt_4_model)
session.add(generate_image_skill)
Expand Down
6 changes: 6 additions & 0 deletions samples/apps/autogen-studio/autogenstudio/datamodel.py
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,7 @@ class ModelTypes(str, Enum):
openai = "open_ai"
google = "google"
azure = "azure"
anthropic = "anthropic"


class Model(SQLModel, table=True):
Expand All @@ -126,6 +127,11 @@ class Model(SQLModel, table=True):
api_version: Optional[str] = None
description: Optional[str] = None
agents: List["Agent"] = Relationship(back_populates="models", link_model=AgentModelLink)
# AWS Configuration
aws_access_key: Optional[str] = None
aws_secret_key: Optional[str] = None
aws_session_token: Optional[str] = None
aws_region: Optional[str] = None


class CodeExecutionConfigTypes(str, Enum):
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,15 @@
"api_key": "EMPTY",
"base_url": "http://localhost:8000/v1",
"description": "Local model example with vLLM server endpoint"
},
{
"model": "anthropic.claude-3-sonnet-20240229-v1:0",
"api_key": "EMPTY",
"aws_access_key": "EMPTY",
"aws_secret_key": "EMPTY",
"aws_session_token": "EMPTY",
"aws_region": "us-east-1",
"description": "Anthropic model configuration"
}
],
"agents": [
Expand Down
7 changes: 6 additions & 1 deletion samples/apps/autogen-studio/autogenstudio/utils/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -394,7 +394,12 @@ def sanitize_model(model: Model):
"""
if isinstance(model, Model):
model = model.model_dump()
valid_keys = ["model", "base_url", "api_key", "api_type", "api_version"]
valid_keys = [
# OpenAI-compatible keys
"model", "base_url", "api_key", "api_type", "api_version",
# AWS keys
"aws_access_key", "aws_secret_key", "aws_session_token", "aws_region"
]
# only add key if value is not None
sanitized_model = {k: v for k, v in model.items() if (v is not None and v != "") and k in valid_keys}
return sanitized_model
Expand Down
7 changes: 6 additions & 1 deletion samples/apps/autogen-studio/frontend/src/components/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -78,12 +78,17 @@ export interface IModelConfig {
api_key?: string;
api_version?: string;
base_url?: string;
api_type?: "open_ai" | "azure" | "google";
api_type?: "open_ai" | "azure" | "google" | "anthropic";
user_id?: string;
created_at?: string;
updated_at?: string;
description?: string;
id?: number;
/* AWS Configuration */
aws_access_key?: string;
aws_secret_key?: string;
aws_session_token?: string;
aws_region?: string;
}

export interface IMetadataFile {
Expand Down
8 changes: 8 additions & 0 deletions samples/apps/autogen-studio/frontend/src/components/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -266,13 +266,21 @@ export const sampleModelConfig = (modelType: string = "open_ai") => {
description: "Google Gemini Model model",
};

const anthropicConfig: IModelConfig = {
model: "claude-3-sonnet-20240229",
api_type: "anthropic",
description: "Anthropic Claude Model model",
};

switch (modelType) {
case "open_ai":
return openaiConfig;
case "azure":
return azureConfig;
case "google":
return googleConfig;
case "anthropic":
return anthropicConfig;
default:
return openaiConfig;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,12 @@ const ModelTypeSelector = ({
description: "Gemini",
icon: <CpuChipIcon className="h-6 w-6 text-primary" />,
},
{
label: "Anthropic",
value: "anthropic",
description: "Anthropic or Anthropic Bedrock",
icon: <CpuChipIcon className="h-6 w-6 text-primary" />,
},
];

const [selectedType, setSelectedType] = React.useState<string | undefined>(
Expand Down Expand Up @@ -83,6 +89,7 @@ const ModelTypeSelector = ({
"In addition to OpenAI models, You can also use OSS models via tools like Ollama, vLLM, LMStudio etc. that provide OpenAI compatible endpoint.",
azure: "Azure OpenAI endpoint",
google: "Gemini",
anthropic: "Anthropic models available via Anthropic API or Amazon Bedrock"
};

const [selectedHint, setSelectedHint] = React.useState<string>("open_ai");
Expand Down Expand Up @@ -215,7 +222,7 @@ const ModelConfigMainView = ({
/>
}
/>

{model?.api_type != "anthropic" && (
<ControlRowView
title="Base URL"
className=""
Expand All @@ -231,6 +238,7 @@ const ModelConfigMainView = ({
/>
}
/>
)}
</div>
<div>
<ControlRowView
Expand Down Expand Up @@ -266,6 +274,69 @@ const ModelConfigMainView = ({
}
/>
)}
{/* AWS Configuration */}
{model?.api_type == "anthropic" ? [
<ControlRowView
title="AWS Access Key ID"
className=""
description="Required by Anthropic Bedrock models"
value=""
control={
<Input.Password
className="mt-2 w-full"
value={model?.aws_access_key || ""}
onChange={(e) => {
updateModelConfig("aws_access_key", e.target.value);
}}
/>
}
/>,
<ControlRowView
title="AWS Secret Access Key"
className=""
description="Required by Anthropic Bedrock models"
value=""
control={
<Input.Password
className="mt-2 w-full"
value={model?.aws_secret_key || ""}
onChange={(e) => {
updateModelConfig("aws_secret_key", e.target.value);
}}
/>
}
/>,
<ControlRowView
title="AWS Session Token"
className=""
description="Required by Anthropic Bedrock models"
value=""
control={
<Input.Password
className="mt-2 w-full"
value={model?.aws_session_token || ""}
onChange={(e) => {
updateModelConfig("aws_session_token", e.target.value);
}}
/>
}
/>,
<ControlRowView
title="AWS Region"
className=""
description="Required by Anthropic Bedrock models"
value={model?.aws_region || "us-east-1"}
control={
<Input
className="mt-2 w-full"
value={model?.aws_region}
onChange={(e) => {
updateModelConfig("aws_region", e.target.value);
}}
/>
}
/>
] : null}
</div>
</div>

Expand Down
3 changes: 2 additions & 1 deletion samples/apps/autogen-studio/pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,8 @@ dependencies = [
"typer",
"uvicorn",
"arxiv",
"pyautogen[gemini]>=0.2.0",
"pyautogen[anthropic,gemini]>=0.2.0",
"anthropic[bedrock]",
"python-dotenv",
"websockets",
"numpy < 2.0.0",
Expand Down
Loading