Spaces:
Running
Running
Update flashcard_util.py
Browse files- flashcard_util.py +17 -15
flashcard_util.py
CHANGED
@@ -1,5 +1,5 @@
|
|
1 |
import lang
|
2 |
-
import requests
|
3 |
import json
|
4 |
import httpx
|
5 |
#import aiofiles
|
@@ -33,8 +33,8 @@ async def tldr(content, l=lang.VI_VN):
|
|
33 |
],
|
34 |
"presence_penalty":0.3,
|
35 |
"temperature":0.55
|
36 |
-
},
|
37 |
-
timeout=None
|
38 |
)
|
39 |
_summary = _r.json()
|
40 |
# print(_summary)
|
@@ -66,18 +66,20 @@ async def fetch_img_for_words(words: list[str], __url_prefix=None):
|
|
66 |
|
67 |
async def get_definitions_from_words(words: list[str], summary: str = "", lang: str = lang.VI_VN):
|
68 |
print("running inferrence")
|
69 |
-
|
70 |
-
|
71 |
-
|
72 |
-
|
73 |
-
|
74 |
-
|
75 |
-
|
76 |
-
|
77 |
-
|
78 |
-
|
79 |
-
|
80 |
-
|
|
|
|
|
81 |
|
82 |
# print(_r.json()['choices'][0]['message']['content'].split('\n'))
|
83 |
print(_r.json()['choices'][0]['message']['content'].split('\n'))
|
|
|
1 |
import lang
|
2 |
+
# import requests
|
3 |
import json
|
4 |
import httpx
|
5 |
#import aiofiles
|
|
|
33 |
],
|
34 |
"presence_penalty":0.3,
|
35 |
"temperature":0.55
|
36 |
+
}),
|
37 |
+
timeout=None,
|
38 |
)
|
39 |
_summary = _r.json()
|
40 |
# print(_summary)
|
|
|
66 |
|
67 |
async def get_definitions_from_words(words: list[str], summary: str = "", lang: str = lang.VI_VN):
|
68 |
print("running inferrence")
|
69 |
+
async with httpx.AsyncClient() as client:
|
70 |
+
_r = await client.post(
|
71 |
+
url="https://api.awanllm.com/v1/chat/completions",
|
72 |
+
headers={'Content-Type': 'application/json', 'Authorization': f'Bearer {LLM_API_KEY}'},
|
73 |
+
data=json.dumps({
|
74 |
+
"model": "Meta-Llama-3-8B-Instruct",
|
75 |
+
"messages": [
|
76 |
+
{"role": "user", "content": f"{summary}. Give concise, easy-to-understand definitions for the following keywords: {'; '.join(words)}. DO NOT include the keywords inside their respective definition. Use {lang}."}
|
77 |
+
],
|
78 |
+
"presence_penalty":0.3,
|
79 |
+
"temperature":0.55
|
80 |
+
}),
|
81 |
+
timeout=None
|
82 |
+
)
|
83 |
|
84 |
# print(_r.json()['choices'][0]['message']['content'].split('\n'))
|
85 |
print(_r.json()['choices'][0]['message']['content'].split('\n'))
|