microsoft / TaskWeaver

A code-first agent framework for seamlessly planning and executing data analytics tasks.
https://microsoft.github.io/TaskWeaver/
MIT License
5.38k stars 689 forks source link

Failed loading plugin, 'gbk' codec can't decode? #330

Closed uebhh closed 7 months ago

uebhh commented 7 months ago

Describe the bug The plugin code and comments I developed contain Chinese characters, and Taskweaver reports the following error when loading the plugin and before executing the code: what is the reason for this?

Plugin MultLn_Analysis failed to load: 'gbk' codec can't decode byte 0xb4 in position 786: illegal multibyte sequence

Environment Information (please complete the following information):

Additional context

Plugin MultLn_Analysis failed to load: 'gbk' codec can't decode byte 0xb4 in position 786: illegal multibyte sequence 2024-05-03 16:18:21 - CodeInterpreter talk to CodeInterpreter: The following python code has been executed:

df, description = MultLn_Analysis("Please perform budget performance multiple linear regression analysis")
df, description

The execution of the generated python code above has failed

During execution, the following messages were logged: Traceback (most recent call last):

Cell In[1], line 1 df, description = MultLn_Analysis("Please perform budget performance multiple linear regression analysis")

NameError: name 'MultLn_Analysis' is not defined

uebhh commented 7 months ago

I added a test variable with Chinese characters on line 20 of the example code in ‘ascii_render.py’. The plugin fails to load. Please refer to the attachment and confirm.

from taskweaver.plugin import Plugin, register_plugin

@register_plugin
class AsciiRenderPlugin(Plugin):
    def __call__(self, text: str):
        try:
            import pyfiglet
        except ImportError:
            raise ImportError("Please install pyfiglet first.")

        ASCII_art_1 = pyfiglet.figlet_format(text, font="isometric1")
        result = ASCII_art_1

        return result

if __name__ == "__main__":
    from taskweaver.plugin.context import temp_context
    test = "汉字"

    with temp_context() as temp_ctx:
        render = AsciiRenderPlugin(name="ascii_render", ctx=temp_ctx, config={})
        print(render(text="hello world!"))
uebhh commented 7 months ago

Code modification to match UTF-8 encoding. Please note when using UTF-8 encoding here.

code_executor.py The load_plugin function, open(src_file, "r") -> open(src_file, "r", encoding="utf-8") executor.py The load_impl(self) function, open(module_path, "w") -> open(module_path, "w", encoding="utf-8")

pilipala5 commented 2 months ago

帅哥你好,我最近也在学习taskweaver的使用,能分享一下联系方式吗?