Skip to content

Commit

Permalink
Also log key index when openai throws
Browse files Browse the repository at this point in the history
  • Loading branch information
polyrabbit committed Dec 25, 2023
1 parent 3ecfd89 commit 9db6d57
Show file tree
Hide file tree
Showing 3 changed files with 4 additions and 3 deletions.
3 changes: 2 additions & 1 deletion config.py
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,8 @@ def int_env(name, default):

openai_keys = os.getenv('OPENAI_API_KEY').split(',') if os.getenv('OPENAI_API_KEY') else [None]
openai.api_key = random.choice(openai_keys) # Round-robin available keys
logger.info(f'Use openai api key #{openai_keys.index(openai.api_key)}')
openai_key_index = openai_keys.index(openai.api_key)
logger.info(f'Use openai api key #{openai_key_index}')
openai_model = os.getenv('OPENAI_MODEL') or 'gpt-3.5-turbo'
openai_score_threshold = int_env('OPENAI_SCORE_THRESHOLD', 20)
logger.info(f'Use openai model {openai_model}')
Expand Down
2 changes: 1 addition & 1 deletion db/summary.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ def from_value(cls, value):
class Summary(Base):
__tablename__ = 'summary'

url = mapped_column(String(1024), primary_key=True)
url = mapped_column(String(4096), primary_key=True)
summary = mapped_column(String(65535))
model = mapped_column(String(16), default=Model.FULL.value)
birth = mapped_column(TIMESTAMP, default=datetime.utcnow)
Expand Down
2 changes: 1 addition & 1 deletion hacker_news/news.py
Original file line number Diff line number Diff line change
Expand Up @@ -155,7 +155,7 @@ def summarize_by_openai(self, content):
f'```{content.strip(".")}.```', False)
return summary
except Exception as e:
logger.exception(f'Failed to summarize using openai, {e}') # Make this error explicit in the log
logger.exception(f'Failed to summarize using openai, key #{config.openai_key_index}, {e}') # Make this error explicit in the log
return ''

def openai_complete(self, prompt, need_json):
Expand Down

0 comments on commit 9db6d57

Please sign in to comment.