Ufoptg commited on
Commit
9ae9fc9
1 Parent(s): a22a4b6

Update functions.py

Browse files
Files changed (1) hide show
  1. functions.py +34 -0
functions.py CHANGED
@@ -22,6 +22,11 @@ import os
22
  import requests
23
  from dotenv import load_dotenv
24
 
 
 
 
 
 
25
  load_dotenv()
26
  HUGGING_TOKEN = os.environ["HUGGING_TOKEN"]
27
  SOURCE_ALPHA_URL = os.environ["SOURCE_ALPHA_URL"]
@@ -32,3 +37,32 @@ def ryuzaki_ai_text(text):
32
  headers = {"Authorization": f"Bearer {HUGGING_TOKEN}"}
33
  response = requests.post(API_URL, headers=headers, json={"inputs": text})
34
  return response.json()
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
22
  import requests
23
  from dotenv import load_dotenv
24
 
25
+ try:
26
+ from aiohttp import ClientSession as aiohttp_client
27
+ except ImportError:
28
+ aiohttp_client = None
29
+
30
  load_dotenv()
31
  HUGGING_TOKEN = os.environ["HUGGING_TOKEN"]
32
  SOURCE_ALPHA_URL = os.environ["SOURCE_ALPHA_URL"]
 
37
  headers = {"Authorization": f"Bearer {HUGGING_TOKEN}"}
38
  response = requests.post(API_URL, headers=headers, json={"inputs": text})
39
  return response.json()
40
+
41
+
42
+ async def async_searcher(
43
+ url: str,
44
+ post: bool = False,
45
+ head: bool = False,
46
+ headers: dict = None,
47
+ evaluate=None,
48
+ object: bool = False,
49
+ re_json: bool = False,
50
+ re_content: bool = False,
51
+ *args,
52
+ **kwargs,
53
+ ):
54
+ if aiohttp_client:
55
+ async with aiohttp_client(headers=headers) as client:
56
+ method = client.head if head else (client.post if post else client.get)
57
+ data = await method(url, *args, **kwargs)
58
+ if evaluate:
59
+ return await evaluate(data)
60
+ if re_json:
61
+ return await data.json()
62
+ if re_content:
63
+ return await data.read()
64
+ if head or object:
65
+ return data
66
+ return await data.text()
67
+ else:
68
+ return "Error"