Skip to content

Fix loading latest history for file names with dots#5162

Merged
oobabooga merged 1 commit into
oobabooga:devfrom
TheLounger:chat_logs_file_name_fix
Jan 4, 2024
Merged

Fix loading latest history for file names with dots#5162
oobabooga merged 1 commit into
oobabooga:devfrom
TheLounger:chat_logs_file_name_fix

Conversation

@TheLounger
Copy link
Copy Markdown
Contributor

Problem

When the most recent chat or instruct log is loaded, it fails when the file name has a dot in it. This seems to happen because .stem is being used twice:
https://github.com/oobabooga/text-generation-webui/blob/894e1a070067a7d9f22b032b53cdd3a3528dce53/modules/chat.py#L496 https://github.com/oobabooga/text-generation-webui/blob/894e1a070067a7d9f22b032b53cdd3a3528dce53/modules/chat.py#L513

The fix

Remove the extra .stem and use the "unique id" that comes from find_all_histories as is.
I've tested the fix in several ways, including crazy file names and directory junctions, but I'd love to hear if I missed some important reason for why the Path(...).stem was there.

Error logs

Starting up Webui, most recent history is named This.File.Name.Has.Several.Dots.json.

Traceback (most recent call last):
  File "E:\webui\installer_files\env\Lib\site-packages\gradio\queueing.py", line 407, in call_prediction
    output = await route_utils.call_process_api(
             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "E:\webui\installer_files\env\Lib\site-packages\gradio\route_utils.py", line 226, in call_process_api
    output = await app.get_blocks().process_api(
             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "E:\webui\installer_files\env\Lib\site-packages\gradio\blocks.py", line 1550, in process_api
    result = await self.call_function(
             ^^^^^^^^^^^^^^^^^^^^^^^^^
  File "E:\webui\installer_files\env\Lib\site-packages\gradio\blocks.py", line 1185, in call_function
    prediction = await anyio.to_thread.run_sync(
                 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "E:\webui\installer_files\env\Lib\site-packages\anyio\to_thread.py", line 33, in run_sync
    return await get_asynclib().run_sync_in_worker_thread(
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "E:\webui\installer_files\env\Lib\site-packages\anyio\_backends\_asyncio.py", line 877, in run_sync_in_worker_thread
    return await future
           ^^^^^^^^^^^^
  File "E:\webui\installer_files\env\Lib\site-packages\anyio\_backends\_asyncio.py", line 807, in run
    result = context.run(func, *args)
             ^^^^^^^^^^^^^^^^^^^^^^^^
  File "E:\webui\installer_files\env\Lib\site-packages\gradio\utils.py", line 661, in wrapper
    response = f(*args, **kwargs)
               ^^^^^^^^^^^^^^^^^^
  File "E:\webui\modules\chat.py", line 514, in load_latest_history
    history = load_history(unique_id, state['character_menu'], state['mode'])
              ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "E:\webui\modules\chat.py", line 524, in load_history
    f = json.loads(open(p, 'rb').read())
                   ^^^^^^^^^^^^^
FileNotFoundError: [Errno 2] No such file or directory: 'logs\\chat\\Ann\\This.File.Name.Has.Several.json'

Checklist

@oobabooga
Copy link
Copy Markdown
Owner

That's correct, I didn't notice that .stem was being used twice. Thanks for the fix!

@oobabooga oobabooga merged commit 7965f60 into oobabooga:dev Jan 4, 2024
@TheLounger TheLounger deleted the chat_logs_file_name_fix branch January 4, 2024 01:40
PoetOnTheRun pushed a commit to PoetOnTheRun/text-generation-webui that referenced this pull request Feb 22, 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

Successfully merging this pull request may close these issues.

2 participants