Mbonea commited on
Commit
e9b2bc1
·
1 Parent(s): 15fc111

ballyregan

Browse files
Files changed (2) hide show
  1. App/Chat/PoeChatrouter.py +30 -4
  2. requirements.txt +1 -0
App/Chat/PoeChatrouter.py CHANGED
@@ -4,7 +4,20 @@ from .Schemas import BotRequest
4
  from aiohttp import ClientSession
5
  from pydantic import BaseModel
6
 
 
 
 
 
 
 
 
 
 
 
 
 
7
  chat_router = APIRouter(tags=["Chat"])
 
8
 
9
 
10
  class InputData(BaseModel):
@@ -14,10 +27,23 @@ class InputData(BaseModel):
14
 
15
  async def fetch_predictions(data):
16
  async with ClientSession() as session:
17
- async with session.post(
18
- "https://replicate.com/api/predictions", json=data
19
- ) as response:
20
- return await response.json(), response.status
 
 
 
 
 
 
 
 
 
 
 
 
 
21
 
22
 
23
  async def fetch_result(id):
 
4
  from aiohttp import ClientSession
5
  from pydantic import BaseModel
6
 
7
+ from ballyregan.models import Protocols, Anonymities
8
+ from ballyregan import ProxyFetcher
9
+
10
+ # Setting the debug mode to True, defaults to False
11
+ fetcher = ProxyFetcher()
12
+ proxies = fetcher.get(
13
+ limit=10,
14
+ protocols=[Protocols.HTTP],
15
+ anonymities=[Anonymities.ELITE],
16
+ )
17
+
18
+
19
  chat_router = APIRouter(tags=["Chat"])
20
+ proxy = ""
21
 
22
 
23
  class InputData(BaseModel):
 
27
 
28
  async def fetch_predictions(data):
29
  async with ClientSession() as session:
30
+ for p in proxies:
31
+ if proxy != "":
32
+ if p != proxy:
33
+ continue
34
+ try:
35
+ async with session.post(
36
+ "https://replicate.com/api/predictions",
37
+ json=data,
38
+ timeout=5,
39
+ proxy=str(p),
40
+ ) as response:
41
+ if response.status == 403:
42
+ continue
43
+ proxy = str(p)
44
+ return await response.json(), response.status
45
+ except:
46
+ pass
47
 
48
 
49
  async def fetch_result(id):
requirements.txt CHANGED
@@ -9,3 +9,4 @@ requests
9
  redis
10
  fastapi-cache2[memcache]
11
  git+https://github.com/snowby666/poe-api-wrapper.git
 
 
9
  redis
10
  fastapi-cache2[memcache]
11
  git+https://github.com/snowby666/poe-api-wrapper.git
12
+ ballyregan