From 2c61e152a35f3b68a0a10e608f0faa0e377bb430 Mon Sep 17 00:00:00 2001 From: Pratham Dubey <134331217+prathamdby@users.noreply.github.com> Date: Mon, 18 Mar 2024 22:24:43 +0530 Subject: [PATCH 1/4] Specify the author as the GitHub Actions bot for automated commits --- .github/workflows/add-license.yml | 2 ++ 1 file changed, 2 insertions(+) diff --git a/.github/workflows/add-license.yml b/.github/workflows/add-license.yml index 8747cb9..d603140 100644 --- a/.github/workflows/add-license.yml +++ b/.github/workflows/add-license.yml @@ -26,5 +26,7 @@ jobs: - uses: GuillaumeFalourd/git-commit-push@v1.3 with: + email: "actions@github.com" + name: "GitHub Actions Bot" commit_message: "Add license to files" target_branch: main From 1562b89a1c9763eee402bb4689f873d4facf18de Mon Sep 17 00:00:00 2001 From: Pratham Dubey <134331217+prathamdby@users.noreply.github.com> Date: Mon, 18 Mar 2024 22:51:29 +0530 Subject: [PATCH 2/4] tests: Implement a test for the FreeChatgpt provider --- tests/test_freechatgpt.py | 31 +++++++++++++++++++++++++++++++ 1 file changed, 31 insertions(+) create mode 100644 tests/test_freechatgpt.py diff --git a/tests/test_freechatgpt.py b/tests/test_freechatgpt.py new file mode 100644 index 0000000..685c90a --- /dev/null +++ b/tests/test_freechatgpt.py @@ -0,0 +1,31 @@ +from g4f.client import Client +from g4f.Provider import FreeChatgpt +from g4f.models import default + + +def generate_response() -> str: + client = Client(provider=FreeChatgpt) + + try: + response = client.chat.completions.create( + model=default, + messages=[ + {"role": "user", "content": "Say hi, with your response starting with START and ending with END"} + ], + ) + except: + print("ERROR: Could not create a prompt!") + + return response.choices[0].message.content + + +class TestOutput: + def test_output(self): + response = generate_response() + + if len(response) > 0: + print("✅ FreeChatgpt is up!") + else: + print("❌ FreeChatgpt is down...") + + assert response.startswith("START") and response.endswith("END") From b9103a456576c100195da060df8c9a32eaf9fe74 Mon Sep 17 00:00:00 2001 From: Pratham Dubey <134331217+prathamdby@users.noreply.github.com> Date: Mon, 18 Mar 2024 22:52:45 +0530 Subject: [PATCH 3/4] tests: Switch to the default model for the Bing test --- tests/test_bing.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/tests/test_bing.py b/tests/test_bing.py index 64aec6d..38d488c 100644 --- a/tests/test_bing.py +++ b/tests/test_bing.py @@ -16,6 +16,7 @@ from g4f.client import Client from g4f.Provider import Bing +from g4f.models import default def generate_response() -> str: @@ -23,7 +24,7 @@ def generate_response() -> str: try: response = client.chat.completions.create( - model="gpt-4.0-turbo", + model=default, messages=[ {"role": "user", "content": "Say hi, with your response starting with START and ending with END"} ], From 33e39d2236f99f36111217b6e4f5d24164ec0aab Mon Sep 17 00:00:00 2001 From: Pratham Dubey <134331217+prathamdby@users.noreply.github.com> Date: Tue, 19 Mar 2024 00:38:54 +0530 Subject: [PATCH 4/4] tests: Raise an exception if the response comes back empty --- tests/test_bing.py | 1 + tests/test_freechatgpt.py | 1 + 2 files changed, 2 insertions(+) diff --git a/tests/test_bing.py b/tests/test_bing.py index 38d488c..9ae1c6c 100644 --- a/tests/test_bing.py +++ b/tests/test_bing.py @@ -31,6 +31,7 @@ def generate_response() -> str: ) except: print("ERROR: Could not create a prompt!") + raise Exception("ERROR: Could not create a prompt!") return response.choices[0].message.content diff --git a/tests/test_freechatgpt.py b/tests/test_freechatgpt.py index 685c90a..a294142 100644 --- a/tests/test_freechatgpt.py +++ b/tests/test_freechatgpt.py @@ -15,6 +15,7 @@ def generate_response() -> str: ) except: print("ERROR: Could not create a prompt!") + raise Exception("ERROR: Could not create a prompt!") return response.choices[0].message.content