mirror of
https://github.com/yihong0618/bilingual_book_maker.git
synced 2025-06-05 19:15:34 +00:00
Fixed Azure openai bug (#368)
fix(chatgptapi_translator): when use azure openai something wrong 1. when I use azure openai will get "api_base" not have this arribute error. So I add self.api_base = api_base 2. In line 84 when the message content type is None will get typeError. So I add a if else to avoid this error. * style: format code style * style: format code style * fix: lint
This commit is contained in:
parent
78e7e711b9
commit
ecf86a2747
@ -46,6 +46,7 @@ class ChatGPTAPI(Base):
|
||||
super().__init__(key, language)
|
||||
self.key_len = len(key.split(","))
|
||||
self.openai_client = OpenAI(api_key=key, base_url=api_base)
|
||||
self.api_base = api_base
|
||||
|
||||
self.prompt_template = (
|
||||
prompt_template
|
||||
@ -97,7 +98,11 @@ class ChatGPTAPI(Base):
|
||||
completion = self.create_chat_completion(text)
|
||||
|
||||
# TODO work well or exception finish by length limit
|
||||
# Check if content is not None before encoding
|
||||
if completion.choices[0].message.content is not None:
|
||||
t_text = completion.choices[0].message.content.encode("utf8").decode() or ""
|
||||
else:
|
||||
t_text = ""
|
||||
|
||||
return t_text
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user