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

UnicodeEncodeError with Emoji Output on Windows #659

Open
LSauce opened this issue Dec 31, 2024 · 0 comments
Open

UnicodeEncodeError with Emoji Output on Windows #659

LSauce opened this issue Dec 31, 2024 · 0 comments

Comments

@LSauce
Copy link

LSauce commented Dec 31, 2024

Description:

I'm encountering a UnicodeEncodeError when trying to generate a list of emojis . The error message indicates that the 'gbk' codec can't encode certain emoji characters.

Steps to Reproduce:

  1. Open the command line (PowerShell).
  2. Execute the command:
sgpt emoji1

Error Message:

UnicodeEncodeError: 'gbk' codec can't encode character '\U0001f60a' in position 64: illegal multibyte sequence
Error Detail
PS C:\Project\> sgpt emoji1
                                                                                                                                                                            
Here’s a list of some common emojis you might find useful:                                                                                                                                                                            
                                                                                                                                                                                                                                      
 • 😊 Smiling Face with Smiling Eyes                                                                                                                                                                                                  
 • 😂 Face with Tears of Joy                                                                                                                                                                                                          
 • ❤️ Red Heart                                                                                                                                                                                                                                                                                                                                                                                                                                                             
 • 👍 Thumbs Up                                                                                                                                                                                                                       
 • 🎉 Party Popper                                                                                                                                                                                                                    
 • 🐱 Cat Face                                                                                                                                                                                                                        
 • 🌞 Sun with Face                                                                                                                                                                                                                   
 • 🍕 Pizza                                                                                                                                                                                                                           
 • 🚀 Rocket                                                                                                                                                                                                                          
 • 🌈 Rainbow                                                                                                                                                                                                                         

If you have a specific emoji in mind or need more details, let me know! 😊
╭─────────────────────────────── Traceback (most recent call last) ────────────────────────────────╮
│ C:\Users\XXXX\AppData\Local\Programs\Python\Python311\Lib\site-packages\sgpt\app.py:229 in  │
│ main                                                                                             │
│                                                                                                  │
│   226 │   │   │   functions=function_schemas,                                                    │
│   227 │   │   )                                                                                  │
│   228 │   else:                                                                                  │
│ ❱ 229 │   │   full_completion = DefaultHandler(role_class, md).handle(                           │
│   230 │   │   │   prompt=prompt,                                                                 │
│   231 │   │   │   model=model,                                                                   │
│   232 │   │   │   temperature=temperature,                                                       │
│                                                                                                  │
│ ╭───────────────────────────────── locals ──────────────────────────────────╮                    │
│ │               cache = True                                                │                    │
│ │                chat = None                                                │                    │
│ │                code = False                                               │                    │
│ │         create_role = None                                                │                    │
│ │      describe_shell = False                                               │                    │
│ │              editor = False                                               │                    │
│ │    function_schemas = None                                                │                    │
│ │           functions = True                                                │                    │
│ │   install_functions = None                                                │                    │
│ │ install_integration = None                                                │                    │
│ │         interaction = True                                                │                    │
│ │          list_chats = None                                                │                    │
│ │          list_roles = None                                                │                    │
│ │                  md = True                                                │                    │
│ │               model = 'deepseek-chat'                                     │                    │
│ │              prompt = 'emoji1'                                            │                    │
│ │                repl = None                                                │                    │
│ │                role = None                                                │                    │
│ │          role_class = <sgpt.role.SystemRole object at 0x000001FCED55E750> │                    │
│ │               shell = False                                               │                    │
│ │           show_chat = None                                                │                    │
│ │           show_role = None                                                │                    │
│ │        stdin_passed = False                                               │                    │
│ │         temperature = 0.0                                                 │                    │
│ │               top_p = 1.0                                                 │                    │
│ │             version = None                                                │                    │
│ ╰───────────────────────────────────────────────────────────────────────────╯                    │
│                                                                                                  │
│ C:\Users\XXXX\AppData\Local\Programs\Python\Python311\Lib\site-packages\sgpt\handlers\handl │
│ er.py:165 in handle                                                                              │
│                                                                                                  │
│   162 │   │   │   caching=caching,                                                               │
│   163 │   │   │   **kwargs,                                                                      │
│   164 │   │   )                                                                                  │
│ ❱ 165 │   │   return self.printer(generator, not disable_stream)                                 │
│   166                                                                                            │
│                                                                                                  │
│ ╭─────────────────────────────────────────── locals ───────────────────────────────────────────╮ │
│ │        caching = True                                                                        │ │
│ │ disable_stream = False                                                                       │ │
│ │      functions = None                                                                        │ │
│ │      generator = <generator object Cache.__call__.<locals>.wrapper at 0x000001FCED323760>    │ │
│ │         kwargs = {}                                                                          │ │
│ │       messages = [                                                                           │ │
│ │                  │   {                                                                       │ │
│ │                  │   │   'role': 'system',                                                   │ │
│ │                  │   │   'content': 'You are ShellGPT\nYou are programming and system        │ │
│ │                  administration assistant.\nYou ar'+279                                      │ │
│ │                  │   },                                                                      │ │
│ │                  │   {'role': 'user', 'content': 'emoji1'}                                   │ │
│ │                  ]                                                                           │ │
│ │          model = 'deepseek-chat'                                                             │ │
│ │         prompt = 'emoji1'                                                                    │ │
│ │           self = <sgpt.handlers.default_handler.DefaultHandler object at 0x000001FCED33DC10> │ │
│ │    temperature = 0.0                                                                         │ │
│ │          top_p = 1.0                                                                         │ │
│ ╰──────────────────────────────────────────────────────────────────────────────────────────────╯ │
│                                                                                                  │
│ C:\Users\XXXX\AppData\Local\Programs\Python\Python311\Lib\site-packages\sgpt\printer.py:23  │
│ in __call__                                                                                      │
│                                                                                                  │
│   20 │                                                                                           │
│   21 │   def __call__(self, chunks: Generator[str, None, None], live: bool = True) -> str:       │
│   22 │   │   if live:                                                                            │
│ ❱ 23 │   │   │   return self.live_print(chunks)                                                  │
│   24 │   │   with self.console.status("[bold green]Loading..."):                                 │
│   25 │   │   │   full_completion = "".join(chunks)                                               │
│   26 │   │   self.static_print(full_completion)                                                  │
│                                                                                                  │
│ ╭───────────────────────────────────── locals ──────────────────────────────────────╮            │
│ │ chunks = <generator object Cache.__call__.<locals>.wrapper at 0x000001FCED323760> │            │
│ │   live = True                                                                     │            │
│ │   self = <sgpt.printer.MarkdownPrinter object at 0x000001FCED541E10>              │            │
│ ╰───────────────────────────────────────────────────────────────────────────────────╯            │
│                                                                                                  │
│ C:\Users\XXXX\AppData\Local\Programs\Python\Python311\Lib\site-packages\sgpt\printer.py:38  │
│ in live_print                                                                                    │
│                                                                                                  │
│   35 │   def live_print(self, chunks: Generator[str, None, None]) -> str:                        │
│   36 │   │   full_completion = ""                                                                │
│   37 │   │   with Live(console=self.console) as live:                                            │
│ ❱ 38 │   │   │   for chunk in chunks:                                                            │
│   39 │   │   │   │   full_completion += chunk                                                    │
│   40 │   │   │   │   markdown = Markdown(markup=full_completion, code_theme=self.theme)          │
│   41 │   │   │   │   live.update(markdown, refresh=True)                                         │
│                                                                                                  │
│ ╭─────────────────────────────────────────── locals ───────────────────────────────────────────╮ │
│ │           chunk = ''                                                                         │ │
│ │          chunks = <generator object Cache.__call__.<locals>.wrapper at 0x000001FCED323760>   │ │
│ │ full_completion = 'Here’s a list of some common emojis you might find useful:\n\n- 😊        │ │
│ │                   Smiling Face wit'+226                                                      │ │
│ │            live = <rich.live.Live object at 0x000001FCED12BFD0>                              │ │
│ │        markdown = <rich.markdown.Markdown object at 0x000001FCEC023050>                      │ │
│ │            self = <sgpt.printer.MarkdownPrinter object at 0x000001FCED541E10>                │ │
│ ╰──────────────────────────────────────────────────────────────────────────────────────────────╯ │
│                                                                                                  │
│ C:\Users\XXXX\AppData\Local\Programs\Python\Python311\Lib\site-packages\sgpt\cache.py:41 in │
│ wrapper                                                                                          │
│                                                                                                  │
│   38 │   │   │   │   result += i                                                                 │
│   39 │   │   │   │   yield i                                                                     │
│   40 │   │   │   if "@FunctionCall" not in result:                                               │
│ ❱ 41 │   │   │   │   file.write_text(result)                                                     │
│   42 │   │   │   self._delete_oldest_files(self.length)  # type: ignore                          │
│   43 │   │                                                                                       │
│   44 │   │   return wrapper                                                                      │
│                                                                                                  │
│ ╭─────────────────────────────────────────── locals ───────────────────────────────────────────╮ │
│ │   args = (<sgpt.handlers.default_handler.DefaultHandler object at 0x000001FCED33DC10>,)      │ │
│ │   file = WindowsPath('C:/Users/XXXXX~1/AppData/Local/Temp/cache/c2fe06915beeab45fc2f3c9c02… │ │
│ │      i = ''                                                                                  │ │
│ │    key = 'c2fe06915beeab45fc2f3c9c02db0a3c'                                                  │ │
│ │ kwargs = {                                                                                   │ │
│ │          │   'model': 'deepseek-chat',                                                       │ │
│ │          │   'temperature': 0.0,                                                             │ │
│ │          │   'top_p': 1.0,                                                                   │ │
│ │          │   'messages': [                                                                   │ │
│ │          │   │   {                                                                           │ │
│ │          │   │   │   'role': 'system',                                                       │ │
│ │          │   │   │   'content': 'You are ShellGPT\nYou are programming and system            │ │
│ │          administration assistant.\nYou ar'+279                                              │ │
│ │          │   │   },                                                                          │ │
│ │          │   │   {'role': 'user', 'content': 'emoji1'}                                       │ │
│ │          │   ],                                                                              │ │
│ │          │   'functions': None                                                               │ │
│ │          }                                                                                   │ │
│ │ result = 'Here’s a list of some common emojis you might find useful:\n\n- 😊 Smiling Face    │ │
│ │          wit'+226                                                                            │ │
│ │   self = <sgpt.cache.Cache object at 0x000001FCED549590>                                     │ │
│ ╰──────────────────────────────────────────────────────────────────────────────────────────────╯ │
│                                                                                                  │
│ C:\Users\XXXX\AppData\Local\Programs\Python\Python311\Lib\pathlib.py:1079 in write_text     │
│                                                                                                  │
│   1076 │   │   │   │   │   │   │   data.__class__.__name__)                                      │
│   1077 │   │   encoding = io.text_encoding(encoding)                                             │
│   1078 │   │   with self.open(mode='w', encoding=encoding, errors=errors, newline=newline) as f  │
│ ❱ 1079 │   │   │   return f.write(data)                                                          │
│   1080 │                                                                                         │
│   1081 │   def readlink(self):                                                                   │
│   1082 │   │   """                                                                               │
│                                                                                                  │
│ ╭─────────────────────────────────────────── locals ───────────────────────────────────────────╮ │
│ │     data = 'Here’s a list of some common emojis you might find useful:\n\n- 😊 Smiling Face  │ │
│ │            wit'+226                                                                          │ │
│ │ encoding = 'locale'                                                                          │ │
│ │   errors = None                                                                              │ │
│ │        f = <_io.TextIOWrapper                                                                │ │
│ │            name='C:\\Users\\XXXXX~1\\AppData\\Local\\Temp\\cache\\c2fe06915beeab45fc2f3c9c… │ │
│ │            mode='w' encoding='cp936'>                                                        │ │
│ │  newline = None                                                                              │ │
│ │     self = WindowsPath('C:/Users/XXXXX~1/AppData/Local/Temp/cache/c2fe06915beeab45fc2f3c9c… │ │
│ ╰──────────────────────────────────────────────────────────────────────────────────────────────╯ │
╰──────────────────────────────────────────────────────────────────────────────────────────────────╯
UnicodeEncodeError: 'gbk' codec can't encode character '\U0001f60a' in position 64: illegal multibyte sequence
@LSauce LSauce changed the title UnicodeEncodeError with Emoji Output UnicodeEncodeError with Emoji Output on Windows Dec 31, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant