Skip to content

Commit d34ad26

Browse files
夏一飞夏一飞
authored andcommitted
chore: update version to 0.3.6 and fix json serialize
1 parent a9af8e1 commit d34ad26

File tree

2 files changed

+10
-6
lines changed

2 files changed

+10
-6
lines changed

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"$schema": "https://json.schemastore.org/package.json",
33
"name": "openwebui-usage-monitor",
4-
"version": "0.3.5",
4+
"version": "0.3.6",
55
"private": true,
66
"scripts": {
77
"dev": "next dev",

resources/functions/openwebui_monitor.py

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
title: Usage Monitor
33
author: VariantConst & OVINC CN
44
git_url: https://github.com/VariantConst/OpenWebUI-Monitor.git
5-
version: 0.3.5
5+
version: 0.3.6
66
requirements: httpx
77
license: MIT
88
"""
@@ -12,6 +12,8 @@
1212

1313
from httpx import AsyncClient
1414
from pydantic import BaseModel, Field
15+
import json
16+
1517

1618
logger = logging.getLogger(__name__)
1719
logger.setLevel(logging.INFO)
@@ -31,9 +33,11 @@ def __init__(self):
3133
self.type = "filter"
3234
self.valves = self.Valves()
3335
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)))
3439

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)
3741
response.raise_for_status()
3842
response_data = response.json()
3943
if not response_data.get("success"):
@@ -53,7 +57,7 @@ async def inlet(self, body: dict, __metadata__: Optional[dict] = None, __user__:
5357
client=client,
5458
url=f"{self.valves.api_endpoint}/api/v1/inlet",
5559
headers={"Authorization": f"Bearer {self.valves.api_key}"},
56-
json={"user": __user__, "body": body},
60+
json_data={"user": __user__, "body": body},
5761
)
5862
self.outage_map[user_id] = response_data.get("balance", 0) <= 0
5963
if self.outage_map[user_id]:
@@ -92,7 +96,7 @@ async def outlet(
9296
client=client,
9397
url=f"{self.valves.api_endpoint}/api/v1/outlet",
9498
headers={"Authorization": f"Bearer {self.valves.api_key}"},
95-
json={"user": __user__, "body": body},
99+
json_data={"user": __user__, "body": body},
96100
)
97101

98102
# pylint: disable=C0209

0 commit comments

Comments
 (0)