xtekky / gpt4free

The official gpt4free repository | various collection of powerful language models
https://g4f.ai
GNU General Public License v3.0
60.56k stars 13.27k forks source link

Text is not copied when the Copy button is pressed #2287

Open Vasabiko opened 5 days ago

Vasabiko commented 5 days ago

Steps to playback Send a request to the chatbot to output the response in block code, click on the Copy copied copied and try to paste the text into any text field (e.g. notepad).

foxfire52 commented 4 days ago

Your OS and Browser version?

Vasabiko commented 4 days ago

Ваша версия ОС и браузера?

Win 11 23H3 22635.4300, Tried it in 3 different browsers, Chrom, Vivaldi, Edge. My friend also has the same problem.

foxfire52 commented 2 days ago

I can't replicate the bug.

Try these steps (Google Chrome):

  1. Clear Browser cache and history.
  2. Open Developer Tools >> "Console" (Instructions)
  3. Go to http://localhost:8080
  4. Open chat and click Copy button.
  5. Inside Console window, right-click on text >> Save As >> Save.
  6. Attach saved .log file here
foxfire52 commented 2 days ago

Tried it in 3 different browsers, Chrom, Vivaldi, Edge.

Try Firefox

Vasabiko commented 2 days ago

I can't replicate the bug.

Try these steps (Google Chrome):

  1. Clear Browser cache and history.
  2. Open Developer Tools >> "Console" (Instructions)
  3. Go to http://localhost:8080
  4. Open chat and click Copy button.
  5. Inside Console window, right-click on text >> Save As >> Save.
  6. Attach saved .log file here Log.log
Vasabiko commented 2 days ago

Tried it in 3 different browsers, Chrom, Vivaldi, Edge.

Try Firefox

unchanged

foxfire52 commented 1 day ago

I suspect the bug is line 97 the writeText call is not awaited and can throw exceptions. https://github.com/xtekky/gpt4free/blob/04386f7b4b70db6b0fbc5747f530e58c2638d4b6/g4f/gui/client/static/js/chat.v1.js#L90-L99

I pushed a fix and added a fallback function using document.exec("copy")

This is my repository: https://github.com/foxfire52/gpt4free/tree/copy-patch repository zip

Would you please download, run it and repeat steps 1-6?

Vasabiko commented 1 day ago

Would you please download, run it and repeat steps 1-6?

Log1.log

foxfire52 commented 1 day ago

Are you sure you ran my repository?

Do this

If you need help with Docker, you can ask.

When server is running follow step 1-6

Vasabiko commented 1 day ago

Are you sure you ran my repository?

Do this

  • Install Docker Desktop Docker Instruction
  • Extract zip file
  • Open Command Line
  • change directory to extracted folder path cd "C://path..."
  • run docker compose up --build

If you need help with Docker, you can ask.

When server is running follow step 1-6

No, not in the docker, in Windows itself via the command line

foxfire52 commented 1 day ago

No, not in the docker, in Windows itself via the command line

Are you using python?

Vasabiko commented 1 day ago

No, not in the docker, in Windows itself via the command line

Are you using python?

yes, Python 3.12.5

foxfire52 commented 1 day ago

Do you use these instructions to run the server? https://github.com/xtekky/gpt4free/blob/main/docs/git.md#installation-steps

in command line, inside extracted gpt4free/ folder run git switch copy-patch

Vasabiko commented 1 day ago

Do you use these instructions to run the server? https://github.com/xtekky/gpt4free/blob/main/docs/git.md#installation-steps

in command line, inside extracted gpt4free/ folder run git switch copy-patch

almost, downloaded the archive and ran the .bat file. git is not installed

@echo off
chcp 65001
REM Переход в нужную директорию
cd /d d:\gpt4free

REM Проверка наличия Python
where python >nul 2>nul
if errorlevel 1 (
    echo Python не найден. Пожалуйста, установите Python и добавьте его в PATH.
    exit /b
)

REM Проверка на существование виртуального окружения
if exist venv (
    echo Виртуальное окружение уже существует. Активируем его...
) else (
    echo Создаем новое виртуальное окружение...
    python.exe -m venv venv
)

REM Активация виртуального окружения
call venv\Scripts\activate

REM Установка зависимостей
pip install -r requirements.txt
pip install -U g4f[webdriver]

REM Запуск скрипта
python -m g4f.gui.run

REM Деактивация виртуального окружения
deactivate

pause
Mr4Mike4 commented 1 day ago

What button are their talking about?

Promt example: Write image generation promts for Midjorney about gemstones, different minerals, close-up, in English and each promt in its own block code

This button doesn't work: 2024-10-24 213728

Vasabiko commented 1 day ago

What button are their talking about?

Promt example: Write image generation promts for Midjorney about gemstones, different minerals, close-up, in English and each promt in its own block code

This button doesn't work: 2024-10-24 213728

Yeah, that's exactly what I meant.

Mr4Mike4 commented 21 hours ago
  1. Enter chrome://flags in your browser's address bar.
  2. Search for Insecure origins treated as secure.
  3. Enable the setting by clicking on the button to the right.
  4. Type the origins that you want to enable the setting for, e.g. http://localhost:3000 or http://example.com. image
http://localhost:3000,http://example.com
  1. NOTE: After you enable the setting, you have to relaunch Chrome for the changes to take effect.

Сopied from the site

It solves the copying problem

Vasabiko commented 13 hours ago

It solves the copying problem

Yes, that's it, thank you very much

foxfire52 commented 11 hours ago

What button are their talking about?

Promt example: Write image generation promts for Midjorney about gemstones, different minerals, close-up, in English and each promt in its own block code

This button doesn't work: 2024-10-24 213728

I forgot to fix this one. Thank you for reporting It. Relevant code is in https://github.com/xtekky/gpt4free/blob/main/g4f/gui/client/static/js/highlightjs-copy.min.js

  1. Enter chrome://flags in your browser's address bar.
  2. Search for Insecure origins treated as secure.
  3. Enable the setting by clicking on the button to the right.
  4. Type the origins that you want to enable the setting for, e.g. ...
  5. NOTE: After you enable the setting, you have to relaunch Chrome for the changes to take effect.

Сopied from the site

It solves the copying problem

This confirms the cause of this issue. Clipboard.writeText() fails if context is not Secure.

foxfire52 commented 11 hours ago

Tomorrow I will send a Pull Request to add fallback copy function. If you use Docker you can already download my repository and use it https://github.com/foxfire52/gpt4free/tree/copy-patch

Since the problem code is part of highlight.js copy plugin, I may open a PR there too.