Spaces:
Running
Running
Experimental async requests
Browse files
main.py
CHANGED
@@ -26,6 +26,8 @@ import os
|
|
26 |
import pytesseract
|
27 |
import lang
|
28 |
|
|
|
|
|
29 |
from secrets import SystemRandom
|
30 |
|
31 |
from random import randint, sample
|
@@ -184,19 +186,20 @@ async def __query_ml_predict(qtype: QType, content: str, header: str, token_limi
|
|
184 |
case QType.WH:
|
185 |
|
186 |
# Make request to Awan LLM endpoint
|
187 |
-
|
188 |
-
|
189 |
-
|
190 |
-
|
191 |
-
|
192 |
-
|
193 |
-
|
194 |
-
|
195 |
-
|
196 |
-
|
197 |
-
|
198 |
-
|
199 |
-
|
|
|
200 |
|
201 |
print(time() - stopwatch)
|
202 |
return {"content": _r.json()['choices'][0]['message']['content'], "style": QType.WH}
|
@@ -204,32 +207,33 @@ async def __query_ml_predict(qtype: QType, content: str, header: str, token_limi
|
|
204 |
case QType.STMT:
|
205 |
|
206 |
# Make request to Awan LLM endpoint
|
207 |
-
|
208 |
-
|
209 |
-
|
210 |
-
|
211 |
-
|
212 |
-
|
213 |
-
|
214 |
-
|
215 |
-
|
216 |
-
|
217 |
-
|
218 |
-
|
|
|
219 |
|
220 |
_r_content = _r.json()['choices'][0]['message']['content'].split('\n\n',1)[1]
|
221 |
-
|
222 |
-
|
223 |
-
|
224 |
-
|
225 |
-
|
226 |
-
|
227 |
-
|
228 |
-
|
229 |
-
|
230 |
-
|
231 |
-
|
232 |
-
|
233 |
)
|
234 |
|
235 |
_w_content = _w.json()['choices'][0]['message']['content'].split('\n\n',1)[1]
|
|
|
26 |
import pytesseract
|
27 |
import lang
|
28 |
|
29 |
+
import httpx
|
30 |
+
|
31 |
from secrets import SystemRandom
|
32 |
|
33 |
from random import randint, sample
|
|
|
186 |
case QType.WH:
|
187 |
|
188 |
# Make request to Awan LLM endpoint
|
189 |
+
async with httpx.AsyncClient() as client:
|
190 |
+
_r = await client.post(
|
191 |
+
url="https://api.awanllm.com/v1/chat/completions",
|
192 |
+
headers={'Content-Type': 'application/json', 'Authorization': f'Bearer {LLM_API_KEY}'},
|
193 |
+
data=json.dumps({
|
194 |
+
"model": "Meta-Llama-3-8B-Instruct",
|
195 |
+
"messages": [
|
196 |
+
{"role": "user", "content": prompt.gen_prompt_wh(content=content, header=header, num_qs=num_qs, lang=l)}
|
197 |
+
],
|
198 |
+
"max_tokens": max(token_limit, 4096),
|
199 |
+
"presence_penalty":0.3,
|
200 |
+
"temperature":0.55
|
201 |
+
})
|
202 |
+
)
|
203 |
|
204 |
print(time() - stopwatch)
|
205 |
return {"content": _r.json()['choices'][0]['message']['content'], "style": QType.WH}
|
|
|
207 |
case QType.STMT:
|
208 |
|
209 |
# Make request to Awan LLM endpoint
|
210 |
+
async with httpx.AsyncClient() as client:
|
211 |
+
_r = await client.post(
|
212 |
+
url="https://api.awanllm.com/v1/chat/completions",
|
213 |
+
headers={'Content-Type': 'application/json', 'Authorization': f'Bearer {LLM_API_KEY}'},
|
214 |
+
data=json.dumps({
|
215 |
+
"model": "Meta-Llama-3-8B-Instruct",
|
216 |
+
"messages": [
|
217 |
+
{"role": "user", "content": prompt.gen_prompt_statements(content=content, header=header, num_qs=num_qs, lang=l)}
|
218 |
+
],
|
219 |
+
"max_tokens": max(token_limit, 4096),
|
220 |
+
|
221 |
+
})
|
222 |
+
)
|
223 |
|
224 |
_r_content = _r.json()['choices'][0]['message']['content'].split('\n\n',1)[1]
|
225 |
+
async with httpx.AsyncClient() as client:
|
226 |
+
_w = await client.post(
|
227 |
+
url="https://api.awanllm.com/v1/chat/completions",
|
228 |
+
headers={'Content-Type': 'application/json', 'Authorization': f'Bearer {LLM_API_KEY}'},
|
229 |
+
data=json.dumps({
|
230 |
+
"model": "Meta-Llama-3-8B-Instruct",
|
231 |
+
"messages": [
|
232 |
+
{"role": "user", "content": prompt.gen_prompt_statements_false(content=_r_content, lang=l)}
|
233 |
+
],
|
234 |
+
"max_tokens": max(token_limit, 4096),
|
235 |
+
|
236 |
+
})
|
237 |
)
|
238 |
|
239 |
_w_content = _w.json()['choices'][0]['message']['content'].split('\n\n',1)[1]
|