Skip to content

Commit

Permalink
use class to handle apis
Browse files Browse the repository at this point in the history
  • Loading branch information
RexWzh committed Aug 9, 2024
1 parent 481b579 commit 57c87c4
Showing 1 changed file with 28 additions and 2 deletions.
30 changes: 28 additions & 2 deletions src/one_api_cli/channel.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,32 @@
from .constant import base_url, headers
from loguru import logger

class Channel():
id: int
"""The ID of the channel."""

type: int
"""The type of the channel. Default to OpenAI, i.e. channel type 1."""

key: str
"""The api key of the channel."""

name: str
"""The display name of the channel."""

base_url: str
"""The base URL of the channel."""

models: str
"""The models of the channel, separated by commas."""

def __init__(self, **kwargs):
self.__dict__.update(kwargs)

def update(self, **kwargs):
self.__dict__.update(kwargs)


channel_url = f"{base_url}/api/channel"

def get_channels():
Expand All @@ -18,7 +44,7 @@ def get_channels():
if not msg['success']:
logger.error(msg['message'])
return {}
return msg['data']
return Channel(**msg['data'])
except requests.RequestException as e:
logger.error(f"Error fetching channels: {e}")
return []
Expand All @@ -38,7 +64,7 @@ def get_channel(channel_id:int)->dict:
if not msg['success']:
logger.error(msg['message'])
return {}
return msg['data']
return Channel(**msg['data'])
except requests.RequestException as e:
logger.error(f"Error fetching channel: {e}")
return {}
Expand Down

0 comments on commit 57c87c4

Please sign in to comment.