Skip to content

Commit

Permalink
Corrected model names for the Azure ChatGPT. fixed yihong0618#62
Browse files Browse the repository at this point in the history
  • Loading branch information
bookfere committed Jun 15, 2023
1 parent 3ae6a9a commit 11080fe
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 5 deletions.
21 changes: 19 additions & 2 deletions config.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
from calibre.utils.config import JSONConfig

from .engines import ChatgptTranslate
from . import EbookTranslator
from .engines import ChatgptTranslate, AzureChatgptTranslate


defaults = {
Expand Down Expand Up @@ -86,8 +87,14 @@ def get_config():


def upgrade_config():
"""Upgrade to 1.4.0"""
config = get_config()
version = EbookTranslator.version
version >= (2, 0, 0) and ver200_upgrade(config)
version >= (2, 0, 3) and ver203_upgrade(config)


def ver200_upgrade(config):
"""Upgrade to 2.0.0"""
if config.get('engine_preferences'):
return

Expand Down Expand Up @@ -124,3 +131,13 @@ def get_engine_preference(engine_name):
if len(engine_preferences) > 0:
config.update(engine_preferences=engine_preferences)
config.commit()

def ver203_upgrade(config):
"""Upgrade to 2.0.3"""
engine_config = config.get('engine_preferences')
azure_chatgpt = engine_config.get('ChatGPT(Azure)')
if azure_chatgpt and 'model' in azure_chatgpt:
model = azure_chatgpt.get('model')
if model not in AzureChatgptTranslate.models:
del azure_chatgpt['model']
config.commit()
7 changes: 5 additions & 2 deletions engines/chatgpt.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,9 @@ class ChatgptTranslate(Base):
prompt = (
'You are a meticulous translator who translates any given content. '
'Translate the content from <slang> to <tlang>.')
models = ['gpt-3.5-turbo', 'gpt-3.5-turbo-0301', 'gpt-4', 'gpt-4-0314',
'gpt-4-32k', 'gpt-4-32k-0314']
models = ['gpt-3.5-turbo', 'gpt-3.5-turbo-0613', 'gpt-3.5-turbo-16k',
'gpt-4', 'gpt-4-0613', 'gpt-4-32k', 'gpt-4-32k-0613',
'gpt-3.5-turbo-16k-0613']
model = 'gpt-3.5-turbo'
samplings = ['temperature', 'top_p']
sampling = 'temperature'
Expand Down Expand Up @@ -113,6 +114,8 @@ class AzureChatgptTranslate(ChatgptTranslate):
endpoint = ('https://{your-resource-name}.openai.azure.com/openai/'
'deployments/{deployment-id}/chat/completions'
'?api-version={api-version}')
models = ['gpt-35-turbo', 'gpt-4', 'gpt-4-32k']
model = 'gpt-35-turbo'

def get_headers(self):
return {
Expand Down
2 changes: 1 addition & 1 deletion ui.py
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ def genesis(self):
if not getattr(self.gui, 'bookfere_ebook_translator', None):
self.gui.bookfere_ebook_translator = self.Status()

EbookTranslator.version >= (2, 0, 0) and upgrade_config()
upgrade_config()

def show_advanced_translation(self):
ebooks = self.get_selected_ebooks()
Expand Down

0 comments on commit 11080fe

Please sign in to comment.