A convenience class that wraps around EdgeGPT.Chatbot to encapsulate input, config, and output all together. Relies on Cookie class for authentication unless ignore_cookies=True
| 93 | |
| 94 | |
| 95 | class Query: |
| 96 | """ |
| 97 | A convenience class that wraps around EdgeGPT.Chatbot to encapsulate input, |
| 98 | config, and output all together. Relies on Cookie class for authentication |
| 99 | unless ignore_cookies=True |
| 100 | """ |
| 101 | |
| 102 | index = [] |
| 103 | image_dir_path = Path.cwd().resolve() / "bing_images" |
| 104 | |
| 105 | def __init__( |
| 106 | self, |
| 107 | prompt: str, |
| 108 | style: ConversationStyle = "precise", |
| 109 | content_type: str = "text", |
| 110 | cookie_files: set[Path] = None, |
| 111 | ignore_cookies: bool = False, |
| 112 | echo: bool = True, |
| 113 | echo_prompt: bool = False, |
| 114 | locale: str = "en-GB", |
| 115 | simplify_response: bool = True, |
| 116 | ) -> None: |
| 117 | """ |
| 118 | Arguments: |
| 119 | |
| 120 | prompt: Text to enter into Bing Chat |
| 121 | style: creative, balanced, or precise |
| 122 | content_type: "text" for Bing Chat; "image" for Dall-e |
| 123 | ignore_cookies (bool): Ignore cookie data altogether |
| 124 | echo: Print something to confirm request made |
| 125 | echo_prompt: Print confirmation of the evaluated prompt |
| 126 | simplify_response: True -> single simplified prompt/response exchange |
| 127 | cookie_files: iterable of Paths or strings of cookie files (json) |
| 128 | |
| 129 | Files in Cookie.dir_path will also be used if they exist. This defaults |
| 130 | to the current working directory, so set Cookie.dir_path before |
| 131 | creating a Query if your cookie files are elsewhere. |
| 132 | """ |
| 133 | self.__class__.index += [self] |
| 134 | self.prompt = prompt |
| 135 | self.locale = locale |
| 136 | self.simplify_response = simplify_response |
| 137 | self.ignore_cookies = ignore_cookies |
| 138 | if not ignore_cookies: |
| 139 | if cookie_files: |
| 140 | # Convert singular argument to an iterable: |
| 141 | if isinstance(cookie_files, (str, Path)): |
| 142 | cookie_files = {cookie_files} |
| 143 | # Check all elements exist and are Paths: |
| 144 | cookie_files = { |
| 145 | Path(x).resolve() |
| 146 | for x in cookie_files |
| 147 | if isinstance(x, (str, Path)) and x |
| 148 | } |
| 149 | Cookie.supplied_files = cookie_files |
| 150 | files = Cookie.files() # includes .supplied_files |
| 151 | if Cookie.rotate_cookies: |
| 152 | Cookie.import_next() |
no outgoing calls