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

Crash when trying to export a chat. #104

Closed
mcDandy opened this issue Aug 25, 2024 · 10 comments
Closed

Crash when trying to export a chat. #104

mcDandy opened this issue Aug 25, 2024 · 10 comments
Assignees
Labels
bug Something isn't working

Comments

@mcDandy
Copy link

mcDandy commented Aug 25, 2024

I made a story (a wierd one) but when trying to export it oterm crashed.

╭───────────────────────────────────────── Traceback (most recent call last) ──────────────────────────────────────────╮
│ F:\Program Files\Python312\Lib\site-packages\oterm\app\chat_export.py:48 in on_submit                                │
│                                                                                                                      │
│   45 │   │   │   for message in messages:                                                                            │
│   46 │   │   │   │   author, text = message                                                                          │
│   47 │   │   │   │   file.write(f"*{author.value}*\n")                                                               │
│ ❱ 48 │   │   │   │   file.write(f"{text}\n")                                                                         │
│   49 │   │   │   │   file.write("\n---\n")                                                                           │
│   50 │   │                                                                                                           │
│   51 │   │   self.dismiss()                                                                                          │
│                                                                                                                      │
│ ╭────────────────────────────────────────────────── locals ──────────────────────────────────────────────────╮       │
│ │   Author = <enum 'Author'>                                                                                 │       │
│ │   author = <Author.OLLAMA: 'ollama'>                                                                       │       │
│ │    event = Submitted()                                                                                     │       │
│ │     file = <_io.TextIOWrapper name='story-sensory.md' mode='w' encoding='cp1250'>                          │       │
│ │  message = (                                                                                               │       │
│ │            │   <Author.OLLAMA: 'ollama'>,                                                                  │       │
│ │            │   'As Elara lay on the soft bed of moss, a sense of déjà vu washed over her.  The s'+1096     │       │
│ │            )                                                                                               │       │
│ │ messages = [                                                                                               │       │
│ │            │   (                                                                                           │       │
│ │            │   │   <Author.USER: 'me'>,                                                                    │       │
│ │            │   │   'Can you write me a beginning of a story about a female who decided to go on a jo'+36   │       │
│ │            │   ),                                                                                          │       │
│ │            │   (                                                                                           │       │
│ │            │   │   <Author.OLLAMA: 'ollama'>,                                                              │       │
│ │            │   │   "Elara wasn't content with the mundane symphony of touch her life offered. The ro"+1598 │       │
│ │            │   ),                                                                                          │       │
│ │            │   (                                                                                           │       │
│ │            │   │   <Author.USER: 'me'>,                                                                    │       │
│ │            │   │   'It was warm so she removed her clothes. She was far away from any civilisation. '+90   │       │
│ │            │   ),                                                                                          │       │
│ │            │   (                                                                                           │       │
│ │            │   │   <Author.OLLAMA: 'ollama'>,                                                              │       │
│ │            │   │   'The warmth emanating from the trees pulsed invitingly, coaxing Elara out of her '+1388 │       │
│ │            │   ),                                                                                          │       │
│ │            │   (                                                                                           │       │
│ │            │   │   <Author.USER: 'me'>,                                                                    │       │
│ │            │   │   'It was magical. The moss felt like clouds. She was giant among miniature twigs.'       │       │
│ │            │   ),                                                                                          │       │
│ │            │   (                                                                                           │       │
│ │            │   │   <Author.OLLAMA: 'ollama'>,                                                              │       │
│ │            │   │   'Opening her eyes, Elara gasped. The familiar world had been transformed. Towerin'+1059 │       │
│ │            │   ),                                                                                          │       │
│ │            │   (                                                                                           │       │
│ │            │   │   <Author.USER: 'me'>,                                                                    │       │
│ │            │   │   'Leaves started falling, covering her naked body. Fully in a few minutes. She did'+41   │       │
│ │            │   ),                                                                                          │       │
│ │            │   (                                                                                           │       │
│ │            │   │   <Author.OLLAMA: 'ollama'>,                                                              │       │
│ │            │   │   "As if responding to Elara's delight, the trees above began shedding their leaves"+1192 │       │
│ │            │   ),                                                                                          │       │
│ │            │   (<Author.USER: 'me'>, 'This is how having a partner must feel. She was in heaven.'),        │       │
│ │            │   (                                                                                           │       │
│ │            │   │   <Author.OLLAMA: 'ollama'>,                                                              │       │
│ │            │   │   'The thought struck Elara with unexpected force: this feeling of complete surrend'+968  │       │
│ │            │   ),                                                                                          │       │
│ │            │   ... +158                                                                                    │       │
│ │            ]                                                                                               │       │
│ │     self = ChatExport()                                                                                    │       │
│ │     text = 'As Elara lay on the soft bed of moss, a sense of déjà vu washed over her.  The s'+1096         │       │
│ ╰────────────────────────────────────────────────────────────────────────────────────────────────────────────╯       │
│                                                                                                                      │
│ F:\Program Files\Python312\Lib\encodings\cp1250.py:19 in encode                                                      │
│                                                                                                                      │
│    16                                                                                                                │
│    17 class IncrementalEncoder(codecs.IncrementalEncoder):                                                           │
│    18 │   def encode(self, input, final=False):                                                                      │
│ ❱  19 │   │   return codecs.charmap_encode(input,self.errors,encoding_table)[0]                                      │
│    20                                                                                                                │
│    21 class IncrementalDecoder(codecs.IncrementalDecoder):                                                           │
│    22 │   def decode(self, input, final=False):                                                                      │
│                                                                                                                      │
│ ╭──────────────────────────────────────────── locals ─────────────────────────────────────────────╮                  │
│ │ final = False                                                                                   │                  │
│ │ input = 'As Elara lay on the soft bed of moss, a sense of déjà vu washed over her.  The s'+1112 │                  │
│ │  self = <encodings.cp1250.IncrementalEncoder object at 0x000002335AD4B470>                      │                  │
│ ╰─────────────────────────────────────────────────────────────────────────────────────────────────╯                  │
╰──────────────────────────────────────────────────────────────────────────────────────────────────────────────────────╯
UnicodeEncodeError: 'charmap' codec can't encode character '\xe0' in position 52: character maps to <undefined>
unhandled exception during asyncio.run() shutdown
task: <Task finished name='Task-213573' coro=<ChatContainer.on_submit.<locals>.response_task() done, defined at F:\Program Files\Python312\Lib\site-packages\oterm\app\widgets\chat.py:126> exception=NoMatches("No nodes match <DOMQuery query='#promptInput'> on FlexibleInput(id='prompt')")>
Traceback (most recent call last):
  File "F:\Program Files\Python312\Lib\site-packages\oterm\app\widgets\chat.py", line 170, in response_task
    input.focus()
  File "F:\Program Files\Python312\Lib\site-packages\oterm\app\widgets\prompt.py", line 124, in focus
    self.query_one("#promptInput", PastableInput).focus()
    ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "F:\Program Files\Python312\Lib\site-packages\textual\dom.py", line 1392, in query_one
    return query.only_one() if expect_type is None else query.only_one(expect_type)
                                                        ^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "F:\Program Files\Python312\Lib\site-packages\textual\css\query.py", line 280, in only_one
    self.first(expect_type) if expect_type is not None else self.first()
    ^^^^^^^^^^^^^^^^^^^^^^^
  File "F:\Program Files\Python312\Lib\site-packages\textual\css\query.py", line 249, in first
    raise NoMatches(f"No nodes match {self!r} on {self.node!r}")
textual.css.query.NoMatches: No nodes match <DOMQuery query='#promptInput'> on FlexibleInput(id='prompt')
@mcDandy
Copy link
Author

mcDandy commented Aug 25, 2024

I do no see any way to adjust the encoding.

@ggozad ggozad added the bug Something isn't working label Aug 27, 2024
@ggozad
Copy link
Owner

ggozad commented Aug 27, 2024

That's a funny one, will look into it asap.

@ggozad
Copy link
Owner

ggozad commented Aug 27, 2024

Is it possible that your terminal operates in Windows-1250 encoding?

@mcDandy
Copy link
Author

mcDandy commented Aug 27, 2024 via email

@ggozad
Copy link
Owner

ggozad commented Aug 27, 2024

Would you be so kind and tell me what the following reports in your python?

import locale
locale.getencoding()

If it is not UTF-8 would you be able to run from PR #105 which should fix it for you?

@mcDandy
Copy link
Author

mcDandy commented Aug 27, 2024 via email

@ggozad
Copy link
Owner

ggozad commented Aug 27, 2024

‚cp1250‘

Right, so like I said your environment is configured with windows1250. I didn't know windows does that in certain countries...

Are you able to verify that #105 solves the problem? You can use

pip install git+https://github.com/ggozad/oterm@refs/pull/105/merge

to install it in a virtual env and try it out.

@mcDandy
Copy link
Author

mcDandy commented Aug 27, 2024 via email

@ggozad
Copy link
Owner

ggozad commented Aug 27, 2024

Excellent, thank you for the bug submission and the testing! Will release asap.

@ggozad ggozad self-assigned this Aug 27, 2024
@mcDandy
Copy link
Author

mcDandy commented Aug 27, 2024 via email

@ggozad ggozad closed this as completed in 5e75312 Aug 28, 2024
ggozad added a commit that referenced this issue Aug 28, 2024
Force utf-8 when exporting messages to a file. Closes #104.
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

2 participants