ggozad / oterm

a text-based terminal client for Ollama
MIT License
962 stars 57 forks source link

Crash when trying to export a chat. #104

Closed mcDandy closed 2 weeks ago

mcDandy commented 2 weeks ago

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 commented 2 weeks ago

I do no see any way to adjust the encoding.

ggozad commented 2 weeks ago

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

ggozad commented 2 weeks ago

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

mcDandy commented 2 weeks ago

I don't know how to check . It has no problem with emojis so I think it should be utf-8...

I am using Windows terminál running PowerShell.

Dne út 27. 8. 2024 21:27 uživatel Yiorgis Gozadinos < @.***> napsal:

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

— Reply to this email directly, view it on GitHub https://github.com/ggozad/oterm/issues/104#issuecomment-2313344949, or unsubscribe https://github.com/notifications/unsubscribe-auth/AEN2KDZ2EKVHNHGRALISVVDZTTHJPAVCNFSM6AAAAABNC2EBGKVHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMZDGMJTGM2DIOJUHE . You are receiving this because you authored the thread.Message ID: @.***>

ggozad commented 2 weeks ago

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 commented 2 weeks ago

‚cp1250‘

From: Yiorgis Gozadinos @.> Sent: Tuesday, August 27, 2024 9:55 PM To: ggozad/oterm @.> Cc: mcDandy @.>; Author @.> Subject: Re: [ggozad/oterm] Crash when trying to export a chat. (Issue #104)

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 https://github.com/ggozad/oterm/pull/105 which should fix it for you?

— Reply to this email directly, view it on GitHub https://github.com/ggozad/oterm/issues/104#issuecomment-2313391508 , or unsubscribe https://github.com/notifications/unsubscribe-auth/AEN2KDZZCLDPACW6RPPBVI3ZTTKSDAVCNFSM6AAAAABNC2EBGKVHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMZDGMJTGM4TCNJQHA . You are receiving this because you authored the thread. https://github.com/notifications/beacon/AEN2KD45PINBYBISNI6YILLZTTKSDA5CNFSM6AAAAABNC2EBGKWGG33NNVSW45C7OR4XAZNMJFZXG5LFINXW23LFNZ2KUY3PNVWWK3TUL5UWJTUJ4OGZI.gif Message ID: @. @.> >

ggozad commented 2 weeks ago

‚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 commented 2 weeks ago

Looks like it is working.

From: Yiorgis Gozadinos @.> Sent: Tuesday, August 27, 2024 9:55 PM To: ggozad/oterm @.> Cc: mcDandy @.>; Author @.> Subject: Re: [ggozad/oterm] Crash when trying to export a chat. (Issue #104)

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 https://github.com/ggozad/oterm/pull/105 which should fix it for you?

— Reply to this email directly, view it on GitHub https://github.com/ggozad/oterm/issues/104#issuecomment-2313391508 , or unsubscribe https://github.com/notifications/unsubscribe-auth/AEN2KDZZCLDPACW6RPPBVI3ZTTKSDAVCNFSM6AAAAABNC2EBGKVHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMZDGMJTGM4TCNJQHA . You are receiving this because you authored the thread. https://github.com/notifications/beacon/AEN2KD45PINBYBISNI6YILLZTTKSDA5CNFSM6AAAAABNC2EBGKWGG33NNVSW45C7OR4XAZNMJFZXG5LFINXW23LFNZ2KUY3PNVWWK3TUL5UWJTUJ4OGZI.gif Message ID: @. @.> >

ggozad commented 2 weeks ago

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

mcDandy commented 2 weeks ago

Just noticed that you gave me a command to do it. I manually edited the offending file 😅.

From: Yiorgis Gozadinos @.> Sent: Tuesday, August 27, 2024 11:00 PM To: ggozad/oterm @.> Cc: mcDandy @.>; Author @.> Subject: Re: [ggozad/oterm] Crash when trying to export a chat. (Issue #104)

‚cp1250‘

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

Are you able to verify that #105 https://github.com/ggozad/oterm/pull/105 solves the problem? You can use

pip install @.***/pull/105/merge

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

— Reply to this email directly, view it on GitHub https://github.com/ggozad/oterm/issues/104#issuecomment-2313531309 , or unsubscribe https://github.com/notifications/unsubscribe-auth/AEN2KD6OBRG7D3UHP2WA6XTZTTSG3AVCNFSM6AAAAABNC2EBGKVHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMZDGMJTGUZTCMZQHE . You are receiving this because you authored the thread. https://github.com/notifications/beacon/AEN2KDZJPD7332CW5YBSKVDZTTSG3A5CNFSM6AAAAABNC2EBGKWGG33NNVSW45C7OR4XAZNMJFZXG5LFINXW23LFNZ2KUY3PNVWWK3TUL5UWJTUJ4WX22.gif Message ID: @. @.> >