diff --git a/apikey.ini b/apikey.ini index 7cda4ef..283d9c5 100644 --- a/apikey.ini +++ b/apikey.ini @@ -1,6 +1,7 @@ [OpenAI] introductioon = the api key does not '' OPENAI_API_KEYS = [your_key_0, ] +OPENAI_API_BASE = 'https://api.openai.com/v1' [Gitee] api = your_gitee_api owner = your_gitee_name diff --git a/chat_paper.py b/chat_paper.py index bf4d3f3..2ec187a 100644 --- a/chat_paper.py +++ b/chat_paper.py @@ -59,6 +59,7 @@ def __init__(self, key_word, query, filter_keys, # 获取某个键对应的值 self.chat_api_list = self.config.get('OpenAI', 'OPENAI_API_KEYS')[1:-1].replace('\'', '').split(',') self.chat_api_list.append(OPENAI_KEY) + self.chat_api_base = os.environ.get("OPENAI_API_BASE", self.config.get('OpenAI', 'OPENAI_API_BASE')[1:-1].replace('\'', '')) # prevent short strings from being incorrectly used as API keys. self.chat_api_list = [api.strip() for api in self.chat_api_list if len(api) > 20] @@ -301,6 +302,7 @@ def summary_with_chat(self, paper_list): reraise=True) def chat_conclusion(self, text, conclusion_prompt_token=800): openai.api_key = self.chat_api_list[self.cur_api] + openai.api_base = self.chat_api_base self.cur_api += 1 self.cur_api = 0 if self.cur_api >= len(self.chat_api_list) - 1 else self.cur_api text_token = len(self.encoding.encode(text)) @@ -347,6 +349,7 @@ def chat_conclusion(self, text, conclusion_prompt_token=800): reraise=True) def chat_method(self, text, method_prompt_token=800): openai.api_key = self.chat_api_list[self.cur_api] + openai.api_base = self.chat_api_base self.cur_api += 1 self.cur_api = 0 if self.cur_api >= len(self.chat_api_list) - 1 else self.cur_api text_token = len(self.encoding.encode(text)) @@ -394,6 +397,7 @@ def chat_method(self, text, method_prompt_token=800): reraise=True) def chat_summary(self, text, summary_prompt_token=1100): openai.api_key = self.chat_api_list[self.cur_api] + openai.api_base = self.chat_api_base self.cur_api += 1 self.cur_api = 0 if self.cur_api >= len(self.chat_api_list) - 1 else self.cur_api text_token = len(self.encoding.encode(text))