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

Support setting of OpenAI reverse proxy on chat_paper.py #190

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all 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
1 change: 1 addition & 0 deletions apikey.ini
Original file line number Diff line number Diff line change
@@ -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
Expand Down
4 changes: 4 additions & 0 deletions chat_paper.py
Original file line number Diff line number Diff line change
Expand Up @@ -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]
Expand Down Expand Up @@ -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))
Expand Down Expand Up @@ -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))
Expand Down Expand Up @@ -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))
Expand Down