Update AI.py
Browse files
AI.py
CHANGED
@@ -4,13 +4,11 @@ from uuid import uuid4
|
|
4 |
import io
|
5 |
import re
|
6 |
import json
|
7 |
-
from webscout.AIutel import Conversation
|
8 |
from typing import Any
|
9 |
import logging
|
10 |
class OPENGPT:
|
11 |
def __init__(
|
12 |
self,
|
13 |
-
is_conversation: bool = True,
|
14 |
max_tokens: int = 600,
|
15 |
timeout: int = 30,
|
16 |
intro: str = None,
|
@@ -35,7 +33,6 @@ class OPENGPT:
|
|
35 |
"""
|
36 |
self.session = requests.Session()
|
37 |
self.max_tokens_to_sample = max_tokens
|
38 |
-
self.is_conversation = is_conversation
|
39 |
self.chat_endpoint = (
|
40 |
"https://opengpts-example-vz4y4ooboq-uc.a.run.app/runs/stream"
|
41 |
)
|
@@ -59,19 +56,6 @@ class OPENGPT:
|
|
59 |
"user-agent": "Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/120.0.0.0 Safari/537.36",
|
60 |
}
|
61 |
|
62 |
-
self.session.headers.update(self.headers)
|
63 |
-
Conversation.intro = (
|
64 |
-
AwesomePrompts().get_act(
|
65 |
-
act, raise_not_found=True, default=None, case_insensitive=True
|
66 |
-
)
|
67 |
-
if act
|
68 |
-
else intro or Conversation.intro
|
69 |
-
)
|
70 |
-
self.conversation = Conversation(
|
71 |
-
is_conversation, self.max_tokens_to_sample, filepath, update_file
|
72 |
-
)
|
73 |
-
self.conversation.history_offset = history_offset
|
74 |
-
self.session.proxies = proxies
|
75 |
|
76 |
def ask(
|
77 |
self,
|
@@ -79,7 +63,6 @@ class OPENGPT:
|
|
79 |
stream: bool = False,
|
80 |
raw: bool = False,
|
81 |
optimizer: str = None,
|
82 |
-
conversationally: bool = False,
|
83 |
) -> dict:
|
84 |
"""Chat with AI
|
85 |
|
@@ -127,7 +110,6 @@ class OPENGPT:
|
|
127 |
payload = {
|
128 |
"input": [
|
129 |
{
|
130 |
-
"content": conversation_prompt,
|
131 |
"additional_kwargs": {},
|
132 |
"type": "human",
|
133 |
"example": False,
|
@@ -163,8 +145,6 @@ class OPENGPT:
|
|
163 |
yield value if raw else resp[1]
|
164 |
except json.decoder.JSONDecodeError:
|
165 |
pass
|
166 |
-
self.conversation.update_chat_history(
|
167 |
-
prompt, self.get_message(self.last_response)
|
168 |
)
|
169 |
|
170 |
def for_non_stream():
|
@@ -179,7 +159,6 @@ class OPENGPT:
|
|
179 |
prompt: str,
|
180 |
stream: bool = False,
|
181 |
optimizer: str = None,
|
182 |
-
conversationally: bool = False,
|
183 |
) -> str:
|
184 |
"""Generate response `str`
|
185 |
Args:
|
@@ -193,7 +172,7 @@ class OPENGPT:
|
|
193 |
|
194 |
def for_stream():
|
195 |
for response in self.ask(
|
196 |
-
prompt, True
|
197 |
):
|
198 |
yield self.get_message(response)
|
199 |
|
@@ -203,7 +182,6 @@ class OPENGPT:
|
|
203 |
prompt,
|
204 |
False,
|
205 |
optimizer=optimizer,
|
206 |
-
conversationally=conversationally,
|
207 |
)
|
208 |
)
|
209 |
|
|
|
4 |
import io
|
5 |
import re
|
6 |
import json
|
|
|
7 |
from typing import Any
|
8 |
import logging
|
9 |
class OPENGPT:
|
10 |
def __init__(
|
11 |
self,
|
|
|
12 |
max_tokens: int = 600,
|
13 |
timeout: int = 30,
|
14 |
intro: str = None,
|
|
|
33 |
"""
|
34 |
self.session = requests.Session()
|
35 |
self.max_tokens_to_sample = max_tokens
|
|
|
36 |
self.chat_endpoint = (
|
37 |
"https://opengpts-example-vz4y4ooboq-uc.a.run.app/runs/stream"
|
38 |
)
|
|
|
56 |
"user-agent": "Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/120.0.0.0 Safari/537.36",
|
57 |
}
|
58 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
59 |
|
60 |
def ask(
|
61 |
self,
|
|
|
63 |
stream: bool = False,
|
64 |
raw: bool = False,
|
65 |
optimizer: str = None,
|
|
|
66 |
) -> dict:
|
67 |
"""Chat with AI
|
68 |
|
|
|
110 |
payload = {
|
111 |
"input": [
|
112 |
{
|
|
|
113 |
"additional_kwargs": {},
|
114 |
"type": "human",
|
115 |
"example": False,
|
|
|
145 |
yield value if raw else resp[1]
|
146 |
except json.decoder.JSONDecodeError:
|
147 |
pass
|
|
|
|
|
148 |
)
|
149 |
|
150 |
def for_non_stream():
|
|
|
159 |
prompt: str,
|
160 |
stream: bool = False,
|
161 |
optimizer: str = None,
|
|
|
162 |
) -> str:
|
163 |
"""Generate response `str`
|
164 |
Args:
|
|
|
172 |
|
173 |
def for_stream():
|
174 |
for response in self.ask(
|
175 |
+
prompt, True
|
176 |
):
|
177 |
yield self.get_message(response)
|
178 |
|
|
|
182 |
prompt,
|
183 |
False,
|
184 |
optimizer=optimizer,
|
|
|
185 |
)
|
186 |
)
|
187 |
|