joytou commited on
Commit
88af923
·
1 Parent(s): 65f66d6

Add optional param headers

Browse files
Files changed (1) hide show
  1. horde.py +7 -8
horde.py CHANGED
@@ -3,16 +3,15 @@ import httpx
3
 
4
  hordeApiKey = os.environ.get("HORDE_API_KEY")
5
  baseUrl = "https://aihorde.net/api/v2/"
 
 
 
 
6
 
7
  class HordeAPI:
8
  # 省去类初始化,直接在每个方法里创建客户端
9
 
10
- async def _fetch(self, url, method="GET"):
11
- headers = {
12
- "Content-Type": "application/json",
13
- "apikey": f"{hordeApiKey}"
14
- }
15
-
16
  async with httpx.AsyncClient() as client:
17
  if method == "GET":
18
  response = await client.get(url, headers=headers)
@@ -51,12 +50,12 @@ class HordeAPI:
51
  def generateCheck(id):
52
  async def api_call():
53
  url = f"{baseUrl}generate/check/{id}"
54
- return await HordeAPI()._fetch(url)
55
  return HordeAPI.APIContextManager(api_call)
56
 
57
  @staticmethod
58
  def generateStatus(id):
59
  async def api_call():
60
  url = f"{baseUrl}generate/status/{id}"
61
- return await HordeAPI()._fetch(url)
62
  return HordeAPI.APIContextManager(api_call)
 
3
 
4
  hordeApiKey = os.environ.get("HORDE_API_KEY")
5
  baseUrl = "https://aihorde.net/api/v2/"
6
+ headers = {
7
+ "Content-Type": "application/json",
8
+ "apikey": f"{hordeApiKey}"
9
+ }
10
 
11
  class HordeAPI:
12
  # 省去类初始化,直接在每个方法里创建客户端
13
 
14
+ async def _fetch(self, url, method="GET", headers=headers):
 
 
 
 
 
15
  async with httpx.AsyncClient() as client:
16
  if method == "GET":
17
  response = await client.get(url, headers=headers)
 
50
  def generateCheck(id):
51
  async def api_call():
52
  url = f"{baseUrl}generate/check/{id}"
53
+ return await HordeAPI()._fetch(url, headers={"Content-Type": "application/json"})
54
  return HordeAPI.APIContextManager(api_call)
55
 
56
  @staticmethod
57
  def generateStatus(id):
58
  async def api_call():
59
  url = f"{baseUrl}generate/status/{id}"
60
+ return await HordeAPI()._fetch(url, headers={"Content-Type": "application/json"})
61
  return HordeAPI.APIContextManager(api_call)