Spaces:
Sleeping
Sleeping
anhdt-dsai-02
commited on
Commit
•
b229e20
1
Parent(s):
6737b1f
Update gemini.py
Browse files
gemini.py
CHANGED
@@ -1,13 +1,17 @@
|
|
1 |
-
|
2 |
-
import os
|
3 |
-
import httpx
|
4 |
-
import asyncio
|
5 |
|
6 |
-
|
7 |
-
|
8 |
-
async def complete_gemini_async(chat, key, params={}):
|
9 |
data = {
|
10 |
-
"contents":
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
11 |
"generationConfig": {
|
12 |
"stopSequences": ["Title"],
|
13 |
"temperature": 1.0 if "temp" not in params else params["temp"],
|
@@ -19,18 +23,25 @@ async def complete_gemini_async(chat, key, params={}):
|
|
19 |
params = {'key': key}
|
20 |
headers = {"Content-Type": "application/json"}
|
21 |
result = None
|
|
|
|
|
|
|
|
|
|
|
22 |
try:
|
23 |
async with httpx.AsyncClient() as client:
|
24 |
-
|
25 |
-
|
26 |
-
result
|
27 |
-
return
|
|
|
28 |
except requests.RequestException as e:
|
29 |
if e.status_code == 429:
|
30 |
-
await asyncio.sleep(
|
31 |
-
|
|
|
32 |
async with httpx.AsyncClient() as client:
|
33 |
-
|
34 |
-
|
35 |
-
result
|
36 |
-
return
|
|
|
1 |
+
async def complete_gemini_async(infor, key, params={}):
|
|
|
|
|
|
|
2 |
|
3 |
+
question, sample = infor
|
4 |
+
prompt = f"Based on language and the answer of the following sample : {sample} \n Answer this the question : {question}"
|
|
|
5 |
data = {
|
6 |
+
"contents": [
|
7 |
+
{
|
8 |
+
"parts": [
|
9 |
+
{
|
10 |
+
"text":prompt
|
11 |
+
}
|
12 |
+
]
|
13 |
+
}
|
14 |
+
],
|
15 |
"generationConfig": {
|
16 |
"stopSequences": ["Title"],
|
17 |
"temperature": 1.0 if "temp" not in params else params["temp"],
|
|
|
23 |
params = {'key': key}
|
24 |
headers = {"Content-Type": "application/json"}
|
25 |
result = None
|
26 |
+
pass_data = {
|
27 |
+
"chat": prompt,
|
28 |
+
"key": key,
|
29 |
+
"params": params
|
30 |
+
}
|
31 |
try:
|
32 |
async with httpx.AsyncClient() as client:
|
33 |
+
url = rd.choice(gate_geminis)
|
34 |
+
result = await client.post(url, json=pass_data, timeout=120)
|
35 |
+
result.raise_for_status()
|
36 |
+
return result.json()
|
37 |
+
|
38 |
except requests.RequestException as e:
|
39 |
if e.status_code == 429:
|
40 |
+
await asyncio.sleep(10)
|
41 |
+
|
42 |
+
print(f"Error making Gemini API request: {e}")
|
43 |
async with httpx.AsyncClient() as client:
|
44 |
+
url = rd.choice(gate_geminis)
|
45 |
+
result = await client.post(url, json=data, timeout=120)
|
46 |
+
result.raise_for_status()
|
47 |
+
return result.json()
|