nhathuy07 commited on
Commit
7076d7a
·
verified ·
1 Parent(s): ca2193d

Update flashcard_util.py

Browse files
Files changed (1) hide show
  1. flashcard_util.py +15 -13
flashcard_util.py CHANGED
@@ -2,7 +2,7 @@ import lang
2
  import requests
3
  import json
4
  import httpx
5
- import aiofiles
6
  from imgsearch import search_img
7
  from re import match, sub
8
  from env import HOST_URL
@@ -22,18 +22,20 @@ def remove_numbering(text):
22
  return sub(pattern, "", text)
23
 
24
  async def tldr(content, l=lang.VI_VN):
25
- _r = requests.post(
26
- url="https://api.awanllm.com/v1/chat/completions",
27
- headers={'Content-Type': 'application/json', 'Authorization': f'Bearer {LLM_API_KEY}'},
28
- data=json.dumps({
29
- "model": "Meta-Llama-3-8B-Instruct",
30
- "messages": [
31
- {"role": "user", "content": f"tl;dr in {l}: {content}"}
32
- ],
33
- "presence_penalty":0.3,
34
- "temperature":0.55
35
- })
36
- )
 
 
37
  _summary = _r.json()
38
  # print(_summary)
39
  return _summary['choices'][0]['message']['content'].split('\n',1)[-1].strip()
 
2
  import requests
3
  import json
4
  import httpx
5
+ #import aiofiles
6
  from imgsearch import search_img
7
  from re import match, sub
8
  from env import HOST_URL
 
22
  return sub(pattern, "", text)
23
 
24
  async def tldr(content, l=lang.VI_VN):
25
+ async with httpx.AsyncClient() as client:
26
+ _r = await client.post(
27
+ url="https://api.awanllm.com/v1/chat/completions",
28
+ headers={'Content-Type': 'application/json', 'Authorization': f'Bearer {LLM_API_KEY}'},
29
+ data=json.dumps({
30
+ "model": "Meta-Llama-3-8B-Instruct",
31
+ "messages": [
32
+ {"role": "user", "content": f"tl;dr in {l}: {content}"}
33
+ ],
34
+ "presence_penalty":0.3,
35
+ "temperature":0.55
36
+ },
37
+ timeout=None)
38
+ )
39
  _summary = _r.json()
40
  # print(_summary)
41
  return _summary['choices'][0]['message']['content'].split('\n',1)[-1].strip()