diff options
author | noptuno <repollo.marrero@gmail.com> | 2023-04-28 12:33:51 +0200 |
---|---|---|
committer | noptuno <repollo.marrero@gmail.com> | 2023-04-28 12:33:51 +0200 |
commit | 396d7e11b2623cf05c3b0fd4ff9b6cce667835fd (patch) | |
tree | 4d7f4531e082deba4fb6bac7e5b221d887e066d9 /you/__init__.py | |
parent | Remove ignored files from repository (diff) | |
parent | Merge pull request #241 from ethanx40/main (diff) | |
download | gpt4free-396d7e11b2623cf05c3b0fd4ff9b6cce667835fd.tar gpt4free-396d7e11b2623cf05c3b0fd4ff9b6cce667835fd.tar.gz gpt4free-396d7e11b2623cf05c3b0fd4ff9b6cce667835fd.tar.bz2 gpt4free-396d7e11b2623cf05c3b0fd4ff9b6cce667835fd.tar.lz gpt4free-396d7e11b2623cf05c3b0fd4ff9b6cce667835fd.tar.xz gpt4free-396d7e11b2623cf05c3b0fd4ff9b6cce667835fd.tar.zst gpt4free-396d7e11b2623cf05c3b0fd4ff9b6cce667835fd.zip |
Diffstat (limited to '')
-rw-r--r-- | you/__init__.py (renamed from openai_rev/you/__init__.py) | 62 |
1 files changed, 26 insertions, 36 deletions
diff --git a/openai_rev/you/__init__.py b/you/__init__.py index 50d74152..8bf31f0d 100644 --- a/openai_rev/you/__init__.py +++ b/you/__init__.py @@ -1,36 +1,28 @@ -import json import re -from typing import Optional, List, Dict, Any +from json import loads from uuid import uuid4 from fake_useragent import UserAgent -from pydantic import BaseModel from tls_client import Session -class PoeResponse(BaseModel): - text: Optional[str] = None - links: List[str] = [] - extra: Dict[str, Any] = {} - - class Completion: @staticmethod def create( - prompt: str, - page: int = 1, - count: int = 10, - safe_search: str = 'Moderate', - on_shopping_page: bool = False, - mkt: str = '', - response_filter: str = 'WebPages,Translations,TimeZone,Computation,RelatedSearches', - domain: str = 'youchat', - query_trace_id: str = None, - chat: list = None, - include_links: bool = False, - detailed: bool = False, - debug: bool = False, - ) -> PoeResponse: + prompt: str, + page: int = 1, + count: int = 10, + safe_search: str = 'Moderate', + on_shopping_page: bool = False, + mkt: str = '', + response_filter: str = 'WebPages,Translations,TimeZone,Computation,RelatedSearches', + domain: str = 'youchat', + query_trace_id: str = None, + chat: list = None, + include_links: bool = False, + detailed: bool = False, + debug: bool = False, + ) -> dict: if chat is None: chat = [] @@ -65,25 +57,23 @@ class Completion: r'(?<=event: youChatSerpResults\ndata:)(.*\n)*?(?=event: )', response.text ).group() third_party_search_results = re.search( - r'(?<=event: thirdPartySearchResults\ndata:)(.*\n)*?(?=event: )', response.text - ).group() + r'(?<=event: thirdPartySearchResults\ndata:)(.*\n)*?(?=event: )', response.text).group() # slots = findall(r"slots\ndata: (.*)\n\nevent", response.text)[0] text = ''.join(re.findall(r'{\"youChatToken\": \"(.*?)\"}', response.text)) extra = { - 'youChatSerpResults': json.loads(you_chat_serp_results), + 'youChatSerpResults': loads(you_chat_serp_results), # 'slots' : loads(slots) } - response = PoeResponse(text=text.replace('\\n', '\n').replace('\\\\', '\\').replace('\\"', '"')) - if include_links: - response.links = json.loads(third_party_search_results)['search']['third_party_search_results'] - - if detailed: - response.extra = extra - - return response + return { + 'response': text.replace('\\n', '\n').replace('\\\\', '\\').replace('\\"', '"'), + 'links': loads(third_party_search_results)['search']['third_party_search_results'] + if include_links + else None, + 'extra': extra if detailed else None, + } @classmethod def __get_headers(cls) -> dict: @@ -104,5 +94,5 @@ class Completion: } @classmethod - def __get_failure_response(cls) -> PoeResponse: - return PoeResponse(text='Unable to fetch the response, Please try again.') + def __get_failure_response(cls) -> dict: + return dict(response='Unable to fetch the response, Please try again.', links=[], extra={}) |