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

I'm using Azure OpenAI, but The OpenAI model ID is required. always shown. #81

Open
1 of 2 tasks
doggy8088 opened this issue Feb 15, 2025 · 3 comments
Open
1 of 2 tasks
Labels
bug Something isn't working

Comments

@doggy8088
Copy link

Describe the bug

I already configured .env file. Only the following settings are configured.

AZURE_OPENAI_API_KEY="xxx"
AZURE_OPENAI_ENDPOINT="https://xxx.openai.azure.com"
AZURE_OPENAI_MODEL_NAME="gpt-4o-mini"
AZURE_OPENAI_CHAT_DEPLOYMENT_NAME="gpt-4o-mini"
AZURE_OPENAI_API_VERSION="2024-08-01-preview"

Everytime I run the translate command the following error shown.

semantic_kernel.exceptions.service_exceptions.ServiceInitializationError: The OpenAI model ID is required.

Steps to reproduce

  1. Set up the Azure environment.

  2. Run co-op-translator with specific settings.

    translate -l "tw" -d
  3. See the error.

    Computer Vision is not configured: Automatically switching to markdown-only mode.
    To enable image translation, please add Computer Vision credentials to your environment variables.
    See the .env.template file for required variables.
    DEBUG:root:Debug mode enabled.
    DEBUG:httpx:load_ssl_context verify=True cert=None trust_env=True http2=False
    DEBUG:httpx:load_verify_locations cafile='C:\\Users\\user\\AppData\\Roaming\\Python\\Python312\\site-packages\\certifi\\cacert.pem'
    INFO:co_op_translator.core.project.project_translator:Skipping image translator initialization in markdown-only mode
    Traceback (most recent call last):
      File "<frozen runpy>", line 198, in _run_module_as_main
      File "<frozen runpy>", line 88, in _run_code
      File "C:\Users\user\AppData\Roaming\Python\PYTHON~1\Scripts\translate.exe\__main__.py", line 7, in <module>
      File "C:\Python312\Lib\site-packages\click\core.py", line 1161, in __call__
        return self.main(*args, **kwargs)
               ^^^^^^^^^^^^^^^^^^^^^^^^^^
      File "C:\Python312\Lib\site-packages\click\core.py", line 1082, in main
        rv = self.invoke(ctx)
             ^^^^^^^^^^^^^^^^
      File "C:\Python312\Lib\site-packages\click\core.py", line 1443, in invoke
        return ctx.invoke(self.callback, **ctx.params)
               ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
      File "C:\Python312\Lib\site-packages\click\core.py", line 788, in invoke
        return __callback(*args, **kwargs)
               ^^^^^^^^^^^^^^^^^^^^^^^^^^^
      File "C:\Users\user\AppData\Roaming\Python\Python312\site-packages\co_op_translator\__main__.py", line 165, in main
        translator = ProjectTranslator(language_codes, root_dir, markdown_only=markdown)
                     ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
      File "C:\Users\user\AppData\Roaming\Python\Python312\site-packages\co_op_translator\core\project\project_translator.py", line 60, in __init__  
        self.markdown_translator = markdown_translator.MarkdownTranslator.create(
                                   ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
      File "C:\Users\user\AppData\Roaming\Python\Python312\site-packages\co_op_translator\core\llm\markdown_translator.py", line 193, in create      
        return OpenAIMarkdownTranslator(root_dir)
               ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
      File "C:\Users\user\AppData\Roaming\Python\Python312\site-packages\co_op_translator\core\llm\providers\openai\markdown_translator.py", line 26, in __init__
        self.kernel = self._initialize_kernel()
                      ^^^^^^^^^^^^^^^^^^^^^^^^^
      File "C:\Users\user\AppData\Roaming\Python\Python312\site-packages\co_op_translator\core\llm\providers\openai\markdown_translator.py", line 39, in _initialize_kernel
        OpenAIChatCompletion(
      File "C:\Users\user\AppData\Roaming\Python\Python312\site-packages\semantic_kernel\connectors\ai\open_ai\services\open_ai_chat_completion.py", 
    line 67, in __init__
        raise ServiceInitializationError("The OpenAI model ID is required.")
    semantic_kernel.exceptions.service_exceptions.ServiceInitializationError: The OpenAI model ID is required.

Expected behavior

I expected the translate command use Azure OpenAI Service settings.

Logs and additional context

Computer Vision is not configured: Automatically switching to markdown-only mode.
To enable image translation, please add Computer Vision credentials to your environment variables.
See the .env.template file for required variables.
DEBUG:root:Debug mode enabled.
DEBUG:httpx:load_ssl_context verify=True cert=None trust_env=True http2=False
DEBUG:httpx:load_verify_locations cafile='C:\\Users\\user\\AppData\\Roaming\\Python\\Python312\\site-packages\\certifi\\cacert.pem'
INFO:co_op_translator.core.project.project_translator:Skipping image translator initialization in markdown-only mode
Traceback (most recent call last):
  File "<frozen runpy>", line 198, in _run_module_as_main
  File "<frozen runpy>", line 88, in _run_code
  File "C:\Users\user\AppData\Roaming\Python\PYTHON~1\Scripts\translate.exe\__main__.py", line 7, in <module>
  File "C:\Python312\Lib\site-packages\click\core.py", line 1161, in __call__
    return self.main(*args, **kwargs)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "C:\Python312\Lib\site-packages\click\core.py", line 1082, in main
    rv = self.invoke(ctx)
         ^^^^^^^^^^^^^^^^
  File "C:\Python312\Lib\site-packages\click\core.py", line 1443, in invoke
    return ctx.invoke(self.callback, **ctx.params)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "C:\Python312\Lib\site-packages\click\core.py", line 788, in invoke
    return __callback(*args, **kwargs)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "C:\Users\user\AppData\Roaming\Python\Python312\site-packages\co_op_translator\__main__.py", line 165, in main
    translator = ProjectTranslator(language_codes, root_dir, markdown_only=markdown)
                 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "C:\Users\user\AppData\Roaming\Python\Python312\site-packages\co_op_translator\core\project\project_translator.py", line 60, in __init__  
    self.markdown_translator = markdown_translator.MarkdownTranslator.create(
                               ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "C:\Users\user\AppData\Roaming\Python\Python312\site-packages\co_op_translator\core\llm\markdown_translator.py", line 193, in create      
    return OpenAIMarkdownTranslator(root_dir)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "C:\Users\user\AppData\Roaming\Python\Python312\site-packages\co_op_translator\core\llm\providers\openai\markdown_translator.py", line 26, in __init__
    self.kernel = self._initialize_kernel()
                  ^^^^^^^^^^^^^^^^^^^^^^^^^
  File "C:\Users\user\AppData\Roaming\Python\Python312\site-packages\co_op_translator\core\llm\providers\openai\markdown_translator.py", line 39, in _initialize_kernel
    OpenAIChatCompletion(
  File "C:\Users\user\AppData\Roaming\Python\Python312\site-packages\semantic_kernel\connectors\ai\open_ai\services\open_ai_chat_completion.py", 
line 67, in __init__
    raise ServiceInitializationError("The OpenAI model ID is required.")
semantic_kernel.exceptions.service_exceptions.ServiceInitializationError: The OpenAI model ID is required.

Are you willing to submit a pull request to resolve the issue?

  • I am willing to submit a pull request

Code of Conduct

  • I agree to follow this project's Code of Conduct
@doggy8088 doggy8088 added the bug Something isn't working label Feb 15, 2025
@leestott
Copy link
Member

leestott commented Feb 17, 2025

Hi @doggy8088 did you install this from PyPi? there was a issue with #77 which was fixed in the latest build for PYPI.

https://github.com/Azure/co-op-translator/releases/tag/v0.6.4

To fix this see #77

If using Azure Open AI Services

Simply modify: [src/co_op_translator/config/llm_config/azure_openai.py]

Ensure the following is present

import os
from dotenv import load_dotenv

# Load environment variables from .env file
load_dotenv()

class AzureOpenAIConfig:

For OpenAI services

Modify [src/co_op_translator/config/llm_config/openai.py]

Ensure the following is present

import os
from dotenv import load_dotenv

# Load environment variables from .env file
load_dotenv()

class OpenAIConfig:

@skytin1004
Copy link
Collaborator

skytin1004 commented Feb 18, 2025

Hi @doggy8088, Thanks for reporting this issue!

It looks like AZURE_OPENAI_MODEL_NAME is not being recognized as the required model ID in Semantic Kernel.

Before troubleshooting further, please check if you're using Co-op Translator v0.6.4. As @leestott mentioned earlier, versions below 0.6.4 may have issues with LLM-related configurations. If you're on an older version, try updating it first.

If you're already on v0.6.4, could you try the following steps and let me know what happens?

Check if the environment variables are loaded correctly.

Run the following command to confirm that AZURE_OPENAI_MODEL_NAME is set:

python -c "import os; from dotenv import load_dotenv; load_dotenv(); print(os.environ)"

If the correct value appears, try running the translation command again, as this process also ensures the environment variables are loaded.

Ensure you're using the latest version of Semantic Kernel.

Run pip show semantic-kernel to check the version. I’m currently using 1.21.1. If you're on an older version, try updating with pip install --upgrade semantic-kernel.

Double-check the model name in Azure AI Foundry.

Make sure the model deployment name in your Azure AI Foundry matches exactly with what you've set in your .env file.

I also recreated my environment and tested it again, and everything is working fine on my end. Let me know what you find, and we’ll troubleshoot further if needed!

@leestott
Copy link
Member

@doggy8088 Did the troubleshooting steps we provided help?

Ensure you log into Azure using the az login command from a terminal within your IDE.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

3 participants