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

Fixing support for AzureOpenAI #6927

Merged
merged 7 commits into from
Feb 29, 2024
Merged
Show file tree
Hide file tree
Changes from 2 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
Original file line number Diff line number Diff line change
Expand Up @@ -330,7 +330,11 @@ def __init__(

# API key and org (if configured) are passed, the rest of the required
# credentials is loaded from the environment by the AzureOpenAI client.
self._client = AsyncAzureOpenAI(**self._credentials.get_api_access_kwargs())
args = self._credentials.get_api_access_kwargs()
for key in args:
if isinstance(args[key], SecretStr):
args[key] = args[key].get_secret_value()
self._client = AsyncAzureOpenAI(**args)
else:
from openai import AsyncOpenAI

Expand Down
18 changes: 14 additions & 4 deletions autogpts/autogpt/autogpt/llm/api_manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,9 @@
import logging
from typing import List, Optional

from openai import OpenAI
from openai import OpenAI, AzureOpenAI
from openai.types import Model
from pydantic import SecretStr

from autogpt.core.resource.model_providers.openai import (
OPEN_AI_MODELS,
Expand Down Expand Up @@ -107,9 +108,18 @@ def get_models(self, openai_credentials: OpenAICredentials) -> List[Model]:
list[Model]: List of available GPT models.
"""
if self.models is None:
all_models = (
OpenAI(**openai_credentials.get_api_access_kwargs()).models.list().data
)
if openai_credentials.api_type == "azure":
args = openai_credentials.get_api_access_kwargs()
for key in args:
if isinstance(args[key], SecretStr):
args[key] = args[key].get_secret_value()
all_models = (
AzureOpenAI(**args).models.list().data
)
else:
all_models = (
OpenAI(**openai_credentials.get_api_access_kwargs()).models.list().data
)
self.models = [model for model in all_models if "gpt" in model.id]

return self.models
Loading