From a7c856592213c8a8c7a6ef3b30cccf2ede6a9636 Mon Sep 17 00:00:00 2001 From: Heiner Lohaus Date: Fri, 12 Jan 2024 02:14:35 +0100 Subject: Add publish-to-pypi workflow Improve gui frontend Fix web search in bing --- .github/workflows/auto-comments.yml | 51 --------------------------------- .github/workflows/publish-to-pypi.yml | 54 +++++++++++++++++++++++++++++++++++ g4f/Provider/Bing.py | 6 +++- g4f/gui/client/css/style.css | 1 + g4f/gui/client/html/index.html | 2 +- g4f/gui/client/js/chat.v1.js | 15 +++++----- setup.py | 39 +++++++++++++++++++++---- 7 files changed, 102 insertions(+), 66 deletions(-) delete mode 100644 .github/workflows/auto-comments.yml create mode 100644 .github/workflows/publish-to-pypi.yml diff --git a/.github/workflows/auto-comments.yml b/.github/workflows/auto-comments.yml deleted file mode 100644 index 98335275..00000000 --- a/.github/workflows/auto-comments.yml +++ /dev/null @@ -1,51 +0,0 @@ -name: Auto Comment -on: - issues: - types: - - opened - - closed - - assigned - pull_request: - types: - - opened - - closed - -jobs: - run: - runs-on: ubuntu-latest - steps: - - name: Auto Comment on Issues Opened - uses: wow-actions/auto-comment@v1 - with: - GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} - issuesOpened: | - πŸ‘‹ @{{ author }} - Thank you for raising an issue. We will investigate into the matter and get back to you as soon as possible. - Please make sure you have given us as much context as possible. - - name: Auto Comment on Issues Closed - uses: wow-actions/auto-comment@v1 - with: - GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} - issuesClosed: | - πŸ‘‹ @{{ author }} This issue is closed. - - name: Auto Comment on Pull Request Merged - uses: wow-actions/auto-comment@v1 - with: - GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} - pullRequestMerged: | - πŸ‘‹ @{{ author }} πŸŽ‰ Congrats on your merged pull request! Thanks for the valuable contribution! πŸ‘πŸŽ‰ Congrats on your merged pull request! Thanks for the valuable contribution! πŸ‘ - - name: Auto Comment on Pull Request Opened - uses: wow-actions/auto-comment@v1 - with: - GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} - pullRequestOpened: | - HelloπŸ‘‹ @{{ author }}, I hope you are doing well! -
- Thank you for raising your pull request and contributing to our Community πŸŽ‰ - Please make sure you have followed our contributing guidelines. We will review it as soon as possible. - - name: Auto Comment on Issues Assigned - uses: wow-actions/auto-comment@v1 - with: - GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} - issuesAssigned: | - Hello @{{ author }}, thank you for raising an issue. πŸ™Œ I have assigned the issue to you. You can now start working on it. If you encounter any problems, please feel free to connect with us. πŸ‘ diff --git a/.github/workflows/publish-to-pypi.yml b/.github/workflows/publish-to-pypi.yml new file mode 100644 index 00000000..d0bc4d99 --- /dev/null +++ b/.github/workflows/publish-to-pypi.yml @@ -0,0 +1,54 @@ +name: Publish Python 🐍 distribution πŸ“¦ to PyPI + +on: push + +env: + G4F_VERSION: ${{ github.ref_name }} + +jobs: + build: + name: Build distribution πŸ“¦ + if: startsWith(github.ref, 'refs/tags/') + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v4 + - name: Set up Python + uses: actions/setup-python@v4 + with: + python-version: "3.x" + - name: Install pypa/build + run: >- + python3 -m + pip install + build + --user + - name: Build a binary wheel and a source tarball + run: python3 -m build + - name: Store the distribution packages + uses: actions/upload-artifact@v3 + with: + name: python-package-distributions + path: dist/ + + publish-to-pypi: + name: >- + Publish distribution on PyPI 🐍 + if: startsWith(github.ref, 'refs/tags/') + needs: + - build + runs-on: ubuntu-latest + environment: + name: testpypi + url: https://test.pypi.org/p/g4f + permissions: + id-token: write + steps: + - name: Download all the dists + uses: actions/download-artifact@v3 + with: + name: python-package-distributions + path: dist/ + - name: Publish distribution πŸ“¦ to PyPI + uses: pypa/gh-action-pypi-publish@release/v1 + with: + repository-url: https://test.pypi.org/legacy/ \ No newline at end of file diff --git a/g4f/Provider/Bing.py b/g4f/Provider/Bing.py index 18a6040b..b0949397 100644 --- a/g4f/Provider/Bing.py +++ b/g4f/Provider/Bing.py @@ -33,7 +33,7 @@ class Bing(AsyncGeneratorProvider): proxy: str = None, timeout: int = 900, cookies: dict = None, - tone: str = Tones.creative, + tone: str = Tones.balanced, image: str = None, web_search: bool = False, **kwargs @@ -212,7 +212,11 @@ def create_message( 'requestId': request_id, 'messageId': request_id, }}, + "verbosity": "verbose", "scenario": "SERP", + "plugins":[ + {"id":"c310c353-b9f0-4d76-ab0d-1dd5e979cf68", "category": 1} + ] if web_search else [], 'tone': tone, 'spokenTextMode': 'None', 'conversationId': conversation.conversationId, diff --git a/g4f/gui/client/css/style.css b/g4f/gui/client/css/style.css index e619b409..3e2d6d6f 100644 --- a/g4f/gui/client/css/style.css +++ b/g4f/gui/client/css/style.css @@ -485,6 +485,7 @@ select { padding: 8px 16px; appearance: none; + width: 250px; } .input-box { diff --git a/g4f/gui/client/html/index.html b/g4f/gui/client/html/index.html index b47f2a37..bc41bd45 100644 --- a/g4f/gui/client/html/index.html +++ b/g4f/gui/client/html/index.html @@ -168,7 +168,7 @@
- diff --git a/g4f/gui/client/js/chat.v1.js b/g4f/gui/client/js/chat.v1.js index 9d49d24e..fffe9fe9 100644 --- a/g4f/gui/client/js/chat.v1.js +++ b/g4f/gui/client/js/chat.v1.js @@ -73,8 +73,8 @@ const ask_gpt = async () => { // Remove generated images from history for (i in messages) { - messages[i]["content"] = messages[i]["content"].replace( - /[\s\S]+/m, + messages[i]["content"] = messages[i]["content"].replaceAll( + /[\s\S]+/gm, "" ) delete messages[i]["provider"]; @@ -318,7 +318,7 @@ const get_conversation = async (conversation_id) => { const get_messages = async (conversation_id) => { let conversation = await get_conversation(conversation_id); - return conversation.items; + return conversation?.items || []; }; const add_conversation = async (conversation_id, content) => { @@ -463,9 +463,8 @@ const register_settings_localstorage = async () => { }; const load_settings_localstorage = async () => { - settings_ids = ["switch", "model", "jailbreak", "patch", "provider"]; - settings_elements = settings_ids.map((id) => document.getElementById(id)); - settings_elements.map((element) => { + for (id of ["switch", "model", "jailbreak", "patch", "provider"]) { + element = document.getElementById(id); if (localStorage.getItem(element.id)) { switch (element.type) { case "checkbox": @@ -478,8 +477,8 @@ const load_settings_localstorage = async () => { console.warn("Unresolved element type"); } } - }); -}; + } +} const say_hello = async () => { tokens = [`Hello`, `!`, ` How`,` can`, ` I`,` assist`,` you`,` today`,`?`] diff --git a/setup.py b/setup.py index 0bb683e4..dc59597b 100644 --- a/setup.py +++ b/setup.py @@ -8,10 +8,39 @@ here = os.path.abspath(os.path.dirname(__file__)) with codecs.open(os.path.join(here, 'README.md'), encoding='utf-8') as fh: long_description = '\n' + fh.read() -with open('requirements.txt') as f: - required = f.read().splitlines() +install_requires = [ + "requests", + "pycryptodome", + "curl_cffi>=0.5.10", + "aiohttp", + "certifi", + "browser_cookie3", + "websockets", + "js2py", + "typing-extensions", + "PyExecJS", + "duckduckgo-search", + "nest_asyncio", + "waitress", + "werkzeug", + "loguru", + "pillow", + "platformdirs", + "numpy", + "asgiref", + "fastapi", + "uvicorn", + "flask", + "py-arkose-generator", + "asyncstdlib", + "async-property", + "undetected-chromedriver", + "asyncstdlib", + "async_property", + "brotli", + "beautifulsoup4", +] -VERSION = '0.1.9.9' DESCRIPTION = ( 'The official gpt4free repository | various collection of powerful language models' ) @@ -19,7 +48,7 @@ DESCRIPTION = ( # Setting up setup( name='g4f', - version=VERSION, + version=os.environ.get("G4F_VERSION"), author='Tekky', author_email='', description=DESCRIPTION, @@ -30,7 +59,7 @@ setup( 'g4f': ['g4f/interference/*', 'g4f/gui/client/*', 'g4f/gui/server/*', 'g4f/Provider/npm/*'] }, include_package_data=True, - install_requires=required, + install_requires=install_requires, entry_points={ 'console_scripts': ['g4f=g4f.cli:main'], }, -- cgit v1.2.3 From 7075cd4ba15072c395f1635dee98fa03b956a051 Mon Sep 17 00:00:00 2001 From: Heiner Lohaus Date: Fri, 12 Jan 2024 02:15:41 +0100 Subject: Change pypi to live --- .github/workflows/publish-to-pypi.yml | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/.github/workflows/publish-to-pypi.yml b/.github/workflows/publish-to-pypi.yml index d0bc4d99..d5481fd4 100644 --- a/.github/workflows/publish-to-pypi.yml +++ b/.github/workflows/publish-to-pypi.yml @@ -38,8 +38,8 @@ jobs: - build runs-on: ubuntu-latest environment: - name: testpypi - url: https://test.pypi.org/p/g4f + name: pypi + url: https://pypi.org/p/g4f permissions: id-token: write steps: @@ -49,6 +49,4 @@ jobs: name: python-package-distributions path: dist/ - name: Publish distribution πŸ“¦ to PyPI - uses: pypa/gh-action-pypi-publish@release/v1 - with: - repository-url: https://test.pypi.org/legacy/ \ No newline at end of file + uses: pypa/gh-action-pypi-publish@release/v1 \ No newline at end of file -- cgit v1.2.3