yihong0618 / bilingual_book_maker

Make bilingual epub books Using AI translate
MIT License
6.91k stars 1k forks source link

Azure OpenAI does not work because of wrong initialization order (getting list of models because it is set to the Azure OpenAI client) #375

Closed imWildCat closed 5 months ago

imWildCat commented 5 months ago
$ bbook_maker --book_name "./xxx.epub" --openai_key xxx --api_base 'https://xxx/' --deployment_id 'gpt-4' -m 'gpt4'
Traceback (most recent call last):
  File "/Users/kitten/Downloads/temp/venv/bin/bbook_maker", line 8, in <module>
    sys.exit(main())
             ^^^^^^
  File "/Users/kitten/Downloads/temp/venv/lib/python3.11/site-packages/book_maker/cli.py", line 362, in main
    e = book_loader(
        ^^^^^^^^^^^^
  File "/Users/kitten/Downloads/temp/venv/lib/python3.11/site-packages/book_maker/loader/epub_loader.py", line 39, in __init__
    self.translate_model = model(
                           ^^^^^^
  File "/Users/kitten/Downloads/temp/venv/lib/python3.11/site-packages/book_maker/translator/chatgptapi_translator.py", line 71, in __init__
    i["id"] for i in self.openai_client.models.list().model_dump()["data"]
                     ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/kitten/Downloads/temp/venv/lib/python3.11/site-packages/openai/resources/models.py", line 79, in list
    return self._get_api_list(
           ^^^^^^^^^^^^^^^^^^^
  File "/Users/kitten/Downloads/temp/venv/lib/python3.11/site-packages/openai/_base_client.py", line 1229, in get_api_list
    return self._request_api_list(model, page, opts)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/kitten/Downloads/temp/venv/lib/python3.11/site-packages/openai/_base_client.py", line 1074, in _request_api_list
    return self.request(page, options, stream=False)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/kitten/Downloads/temp/venv/lib/python3.11/site-packages/openai/_base_client.py", line 869, in request
    return self._request(
           ^^^^^^^^^^^^^^
  File "/Users/kitten/Downloads/temp/venv/lib/python3.11/site-packages/openai/_base_client.py", line 960, in _request
    raise self._make_status_error_from_response(err.response) from None
openai.NotFoundError: Error code: 404 - {'error': {'code': '404', 'message': 'Resource not found'}}
yihong0618 commented 5 months ago

will take a look today thanks

yihong0618 commented 5 months ago

@imWildCat fixed can you take a look? need update to the latest version

imWildCat commented 5 months ago

@yihong0618 thank you so much! it works now!

yihong0618 commented 5 months ago

@yihong0618 thank you so much! it works now!

FYI I did some trick to avoid limit, so OpenAI is faster...you can check this commit to check out why https://github.com/yihong0618/bilingual_book_maker/commit/365d6628bfbed1dd90d1f02674d031def587f053

imWildCat commented 5 months ago

@yihong0618 thanks!

I gave up Azure immediately after their content filter blocked me several times.