Merge pull request #25 from send18/feature-openai-settings

remove openai global settings
This commit is contained in:
Justin-ZL 2023-09-03 22:33:38 +08:00 committed by GitHub
commit c4cf84aac7
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -77,21 +77,12 @@ class OpenAIGPTAPI(BaseGPTAPI, RateLimiter):
"""
def __init__(self):
self.__init_openai(CONFIG)
self.llm = openai
self.model = CONFIG.openai_api_model
self.auto_max_tokens = False
self.rpm = int(CONFIG.get("RPM", 10))
RateLimiter.__init__(self, rpm=self.rpm)
def __init_openai(self, config):
openai.api_key = config.openai_api_key
if config.openai_api_base:
openai.api_base = config.openai_api_base
if config.openai_api_type:
openai.api_type = config.openai_api_type
openai.api_version = config.openai_api_version
self.rpm = int(config.get("RPM", 10))
async def _achat_completion_stream(self, messages: list[dict]) -> str:
response = await self.async_retry_call(
openai.ChatCompletion.acreate, **self._cons_kwargs(messages), stream=True
@ -133,6 +124,10 @@ class OpenAIGPTAPI(BaseGPTAPI, RateLimiter):
"temperature": 0.3,
}
kwargs["timeout"] = 3
kwargs["api_base"] = CONFIG.openai_api_base
kwargs["api_key"] = CONFIG.openai_api_key
kwargs["api_type"] = CONFIG.openai_api_type
kwargs["api_version"] = CONFIG.openai_api_version
return kwargs
async def _achat_completion(self, messages: list[dict]) -> dict: