Skip to content

Commit

Permalink
fix: fix openai migrate autofix code
Browse files Browse the repository at this point in the history
  • Loading branch information
soulteary committed Dec 27, 2023
1 parent c3ea42d commit 826e432
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 33 deletions.
52 changes: 20 additions & 32 deletions agentverse/llms/openai.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,39 +17,25 @@
from .base import BaseChatModel, BaseCompletionModel, BaseModelArgs
from .utils.jsonrepair import JsonRepair

try:
from openai import AzureOpenAI, AsyncAzureOpenAI

client = AzureOpenAI(api_key=os.environ.get("OPENAI_API_KEY"),
api_key=os.environ.get("AZURE_OPENAI_API_KEY"),
azure_endpoint=os.environ.get("AZURE_OPENAI_API_BASE"),
api_version="2023-05-15",
azure_endpoint="http://localhost:5000/v1",
api_key="EMPTY")
aclient = AsyncAzureOpenAI(api_key=os.environ.get("OPENAI_API_KEY"),
api_key=os.environ.get("AZURE_OPENAI_API_KEY"),
azure_endpoint=os.environ.get("AZURE_OPENAI_API_BASE"),
api_version="2023-05-15",
azure_endpoint="http://localhost:5000/v1",
api_key="EMPTY")
from openai.error import OpenAIError
except ImportError:
is_openai_available = False
logger.warn("openai package is not installed")
import openai

# openai.proxy = os.environ.get("http_proxy")
# if openai.proxy is None:
# openai.proxy = os.environ.get("HTTP_PROXY")
if os.environ.get("OPENAI_API_KEY") != None:
openai.api_key = os.environ.get("OPENAI_API_KEY")
is_openai_available = True
elif os.environ.get("AZURE_OPENAI_API_KEY") != None:
openai.api_type = "azure"
openai.api_key = os.environ.get("AZURE_OPENAI_API_KEY")
openai.api_base = os.environ.get("AZURE_OPENAI_API_BASE")
openai.api_version = "2023-05-15"
is_openai_available = True
else:
# openai.proxy = os.environ.get("http_proxy")
# if openai.proxy is None:
# openai.proxy = os.environ.get("HTTP_PROXY")
if os.environ.get("OPENAI_API_KEY") != None:
is_openai_available = True
elif os.environ.get("AZURE_OPENAI_API_KEY") != None:
is_openai_available = True
else:
logger.warn(
"OpenAI API key is not set. Please set the environment variable OPENAI_API_KEY"
)
is_openai_available = False

logger.warn(
"OpenAI API key is not set. Please set the environment variable OPENAI_API_KEY"
)
is_openai_available = False

class OpenAIChatArgs(BaseModelArgs):
model: str = Field(default="gpt-3.5-turbo")
Expand Down Expand Up @@ -120,6 +106,8 @@ def __init__(self, max_retry: int = 3, **kwargs):
if len(kwargs) > 0:
logger.warn(f"Unused arguments: {kwargs}")
if args["model"] in LOCAL_LLMS:
openai.api_base = "http://localhost:5000/v1"
openai.api_key = "EMPTY"
super().__init__(args=args, max_retry=max_retry)

@classmethod
Expand Down
2 changes: 1 addition & 1 deletion requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ astunparse
langchain==0.0.157
scikit-learn
pydantic==1.10.7
typing-extensions==4.5.0
typing-extensions==4.9.0
typing-inspect==0.8.0
colorlog
rapidfuzz
Expand Down

0 comments on commit 826e432

Please sign in to comment.