2
2
title: Usage Monitor
3
3
author: VariantConst & OVINC CN
4
4
git_url: https://github.com/VariantConst/OpenWebUI-Monitor.git
5
- version: 0.3.5
5
+ version: 0.3.6
6
6
requirements: httpx
7
7
license: MIT
8
8
"""
12
12
13
13
from httpx import AsyncClient
14
14
from pydantic import BaseModel , Field
15
+ import json
16
+
15
17
16
18
logger = logging .getLogger (__name__ )
17
19
logger .setLevel (logging .INFO )
@@ -31,9 +33,11 @@ def __init__(self):
31
33
self .type = "filter"
32
34
self .valves = self .Valves ()
33
35
self .outage_map : Dict [str , bool ] = {}
36
+
37
+ async def request (self , client : AsyncClient , url : str , headers : dict , json_data : dict ):
38
+ json_data = json .loads (json .dumps (json_data , default = lambda o : o .dict () if hasattr (o , "dict" ) else str (o )))
34
39
35
- async def request (self , client : AsyncClient , url : str , headers : dict , json : dict ):
36
- response = await client .post (url = url , headers = headers , json = json )
40
+ response = await client .post (url = url , headers = headers , json = json_data )
37
41
response .raise_for_status ()
38
42
response_data = response .json ()
39
43
if not response_data .get ("success" ):
@@ -53,7 +57,7 @@ async def inlet(self, body: dict, __metadata__: Optional[dict] = None, __user__:
53
57
client = client ,
54
58
url = f"{ self .valves .api_endpoint } /api/v1/inlet" ,
55
59
headers = {"Authorization" : f"Bearer { self .valves .api_key } " },
56
- json = {"user" : __user__ , "body" : body },
60
+ json_data = {"user" : __user__ , "body" : body },
57
61
)
58
62
self .outage_map [user_id ] = response_data .get ("balance" , 0 ) <= 0
59
63
if self .outage_map [user_id ]:
@@ -92,7 +96,7 @@ async def outlet(
92
96
client = client ,
93
97
url = f"{ self .valves .api_endpoint } /api/v1/outlet" ,
94
98
headers = {"Authorization" : f"Bearer { self .valves .api_key } " },
95
- json = {"user" : __user__ , "body" : body },
99
+ json_data = {"user" : __user__ , "body" : body },
96
100
)
97
101
98
102
# pylint: disable=C0209
0 commit comments