From 670b2b664ef5c3149de97e08b5c14bd015e74aff Mon Sep 17 00:00:00 2001 From: Johannes Date: Wed, 26 Apr 2023 08:00:06 +0200 Subject: fixes #143 missing cf_clearance raises error Phind Search.create now raises ValueError if missing cf_clearance. --- phind/__init__.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/phind/__init__.py b/phind/__init__.py index 9b1650e0..b4e518bc 100644 --- a/phind/__init__.py +++ b/phind/__init__.py @@ -53,7 +53,7 @@ class PhindResponse: class Search: def create(prompt: str, actualSearch: bool = True, language: str = 'en') -> dict: # None = no search - if user_agent == '': + if user_agent == '' or cf_clearance == '': raise ValueError('user_agent must be set, refer to documentation') if not actualSearch: @@ -281,4 +281,4 @@ class StreamingCompletion: @staticmethod def handle_stream_response(response): - StreamingCompletion.message_queue.put(response) \ No newline at end of file + StreamingCompletion.message_queue.put(response) -- cgit v1.2.3 From 89cbaf7b616f5520442d67fc0816d94cdcfcfa4c Mon Sep 17 00:00:00 2001 From: Johannes Date: Wed, 26 Apr 2023 08:07:23 +0200 Subject: corrected error message --- phind/__init__.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/phind/__init__.py b/phind/__init__.py index b4e518bc..bd54d82a 100644 --- a/phind/__init__.py +++ b/phind/__init__.py @@ -54,7 +54,7 @@ class PhindResponse: class Search: def create(prompt: str, actualSearch: bool = True, language: str = 'en') -> dict: # None = no search if user_agent == '' or cf_clearance == '': - raise ValueError('user_agent must be set, refer to documentation') + raise ValueError('user_agent and cf_clearance must be set, refer to documentation') if not actualSearch: return { -- cgit v1.2.3 From 592bbaab8696785b4f58094becd83b716b09fea5 Mon Sep 17 00:00:00 2001 From: Johannes Date: Wed, 26 Apr 2023 08:12:10 +0200 Subject: added error checking to the remaining methods all the methods within Phind should now raise a value error if cf_clearance is missing --- phind/__init__.py | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/phind/__init__.py b/phind/__init__.py index bd54d82a..9f000c6f 100644 --- a/phind/__init__.py +++ b/phind/__init__.py @@ -53,8 +53,10 @@ class PhindResponse: class Search: def create(prompt: str, actualSearch: bool = True, language: str = 'en') -> dict: # None = no search - if user_agent == '' or cf_clearance == '': - raise ValueError('user_agent and cf_clearance must be set, refer to documentation') + if user_agent == '': + raise ValueError('user_agent must be set, refer to documentation') + if cf_clearance == '' : + raise ValueError('cf_clearance must be set, refer to documentation') if not actualSearch: return { @@ -106,8 +108,11 @@ class Completion: codeContext: str = '', language: str = 'en') -> PhindResponse: - if user_agent == '': + if user_agent == '' : raise ValueError('user_agent must be set, refer to documentation') + + if cf_clearance == '' : + raise ValueError('cf_clearance must be set, refer to documentation') if results is None: results = Search.create(prompt, actualSearch = True) @@ -235,6 +240,8 @@ class StreamingCompletion: if user_agent == '': raise ValueError('user_agent must be set, refer to documentation') + if cf_clearance == '' : + raise ValueError('cf_clearance must be set, refer to documentation') if results is None: results = Search.create(prompt, actualSearch = True) -- cgit v1.2.3