Skip to content

Python: Bug: fail to add plugin from file with "utf-8" encoding (UnicodeDecodeError: 'charmap' codec) #12440

@BinarywoodB

Description

@BinarywoodB

Describe the bug
When I add plugin to kernel via kelnel.add_plugin(), the loading of prompt files from skprompt.txt file will fail with UnicodeDecodeError error

To Reproduce
Steps to reproduce the behavior:

  1. in plugins/attachment/asr_test_analysis/ folder, I have 2 files. One is the prompt file skprompt.txt, the other is the config.json file indicating the function configuration like input variables, etc.
  2. In my program, add this attachment plugin via:
        prompt_dir = os.path.join(os.path.dirname(os.path.abspath(__file__)), "plugins")
        kernel.add_plugin(
            parent_directory=prompt_dir,
            plugin_name="attachment",
        )
  1. See error:
----
 File "C:\Users\dilin\Documents\workspace\SPEECH\car_agent\speech_car\agent_for_car\venv\Lib\site-packages\semantic_kernel\functions\kernel_function_from_prompt.py", line 395, in from_directory
    prompt_template_config.template = prompt_file.read()
                                      ^^^^^^^^^^^^^^^^^^
  File "C:\Users\dilin\AppData\Local\anaconda3\Lib\encodings\cp1252.py", line 23, in decode
    return codecs.charmap_decode(input,self.errors,decoding_table)[0]
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
UnicodeDecodeError: 'charmap' codec can't decode byte 0x9d in position 1938: character maps to <undefined>
  1. We use a workaround to set PYTHONUTF8 to bypass this issue. But we are hoping that the issue can be resolved from the semantic kernel side.

Expected behavior
When semantic kernel loads the prompt file, it should open it with encoding setting utf-8.

Platform

  • Language: Python
  • Source: pip package version 1.29.0
  • AI model: gpt-4o
  • IDE: VS Code
  • OS: Windows

Metadata

Metadata

Assignees

Labels

bugSomething isn't workingcore pluginAnything related to core pluginspythonPull requests for the Python Semantic Kernel

Type

Projects

Status

No status

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions