diff --git a/endpoints/ai.py b/endpoints/ai.py index 0f63a14..fb17aee 100644 --- a/endpoints/ai.py +++ b/endpoints/ai.py @@ -9,27 +9,7 @@ import json from aiohttp import ClientSession, ClientTimeout from fastapi import FastAPI, Request, HTTPException, BackgroundTasks from pydantic import BaseModel - - -class ValidAISongRequest(BaseModel): - """ - - **a**: artist - - **s**: track title - """ - - a: str - s: str - -class ValidHookSongRequest(BaseModel): - """ - - **a**: artist - - **s**: track title - - **hook**: hook to return - """ - - a: str - s: str - hook: str | None = "" +from .constructors import ValidHookSongRequest, ValidAISongRequest # pylint: enable=bad-indentation diff --git a/endpoints/constructors.py b/endpoints/constructors.py new file mode 100644 index 0000000..5b3d169 --- /dev/null +++ b/endpoints/constructors.py @@ -0,0 +1,272 @@ +#!/usr/bin/env python3.12 + +from typing import Optional +from pydantic import BaseModel + +# Constructors +# TODO: REORDER + + +""" +AI +""" + +class ValidAISongRequest(BaseModel): + """ + - **a**: artist + - **s**: track title + """ + + a: str + s: str + +class ValidHookSongRequest(BaseModel): + """ + - **a**: artist + - **s**: track title + - **hook**: hook to return + """ + + a: str + s: str + hook: str | None = "" + +""" +Karma +""" + +class ValidKarmaUpdateRequest(BaseModel): + """ + Requires authentication + - **granter**: who updated the karma + - **keyword**: keyword to update karma for + - **flag**: either 0 (decrement) for --, or 1 (increment) for ++ + """ + + granter: str + keyword: str + flag: int + + +class ValidKarmaRetrievalRequest(BaseModel): + """ + - **keyword**: keyword to retrieve karma value of + """ + + keyword: str + +class ValidTopKarmaRequest(BaseModel): + """ + - **n**: Number of top results to return (default: 10) + """ + n: int | None = 10 + +""" +LastFM +""" + +class ValidArtistSearchRequest(BaseModel): + """ + - **a**: artist name + """ + + a: str + + class Config: # pylint: disable=missing-class-docstring + schema_extra = { + "example": { + "a": "eminem" + } + } + +class ValidAlbumDetailRequest(BaseModel): + """ + - **a**: artist name + - **a2**: album/release name (as sourced from here/LastFM) + """ + + a: str + a2: str + + class Config: # pylint: disable=missing-class-docstring + schema_extra = { + "example": { + "a": "eminem", + "a2": "houdini" + } + } + +class ValidTrackInfoRequest(BaseModel): + """ + - **a**: artist name + - **t**: track + """ + + a: str + t: str + + class Config: # pylint: disable=missing-class-docstring + schema_extra = { + "example": { + "a": "eminem", + "t": "rap god" + } + } + +""" +Rand Msg +""" + +class RandMsgRequest(BaseModel): + """ + - **short**: Short randmsg? + """ + + short: Optional[bool] = False + +""" +YT +""" + +class ValidYTSearchRequest(BaseModel): + """ + - **t**: title to search + """ + + t: str = "rick astley - never gonna give you up" + +""" +XC +""" + +class ValidXCRequest(BaseModel): + """ + - **key**: valid XC API key + - **bid**: bot id + - **cmd**: bot command + - **data**: command data + """ + + key: str + bid: int + cmd: str + data: dict | None = None + +""" +Transcriptions +""" + +class ValidShowEpisodeListRequest(BaseModel): + """ + - **s**: show id + """ + + s: int + +class ValidShowEpisodeLineRequest(BaseModel): + """ + - **s**: show id + - **e**: episode id + """ + + s: int + e: int + +""" +Lyric Search +""" + +class ValidLyricRequest(BaseModel): + """ + - **a**: artist + - **s**: song + - **t**: track (artist and song combined) [used only if a & s are not used] + - **extra**: include extra details in response [optional, default: false] + - **lrc**: Request LRCs? + - **sub**: text to search within lyrics, if found lyrics will begin at found verse [optional] + - **src**: the script/utility which initiated the request + - **excluded_sources**: sources to exclude (new only) + """ + + a: str | None = None + s: str | None = None + t: str | None = None + sub: str | None = None + extra: bool | None = False + lrc: bool | None = False + src: str + excluded_sources: list | None = None + + model_config = { + "json_schema_extra": { + "examples": [ + { + "a": "eminem", + "s": "rap god", + "src": "WEB", + "extra": True, + "lrc": False, + "excluded_sources": [], + }] + } + } + + +class ValidTypeAheadRequest(BaseModel): + """ + - **query**: query string + """ + pre_query: str|None = None + query: str + +""" +Radio +""" + +class RadioException(Exception): + pass + +class ValidRadioSongRequest(BaseModel): + """ + - **key**: API Key + - **artist**: artist to search + - **song**: song to search + - **artistsong**: may be used IN PLACE OF artist/song to perform a combined/string search in the format "artist - song" + - **alsoSkip**: Whether to skip immediately to this track [not implemented] + """ + key: str + artist: str | None = None + song: str | None = None + artistsong: str | None = None + alsoSkip: bool = False + +class ValidRadioNextRequest(BaseModel): + """ + - **key**: API Key + - **skipTo**: UUID to skip to [optional] + """ + key: str + skipTo: str|None = None + +class ValidRadioReshuffleRequest(ValidRadioNextRequest): + """ + - **key**: API Key + """ + +class ValidRadioQueueShiftRequest(BaseModel): + """ + - **key**: API Key + - **uuid**: UUID to shift + - **next**: Play next if true, immediately if false, default False + """ + key: str + uuid: str + next: bool = False + +class ValidRadioQueueRemovalRequest(BaseModel): + """ + - **key**: API Key + - **uuid**: UUID to remove + """ + key: str + uuid: str \ No newline at end of file diff --git a/endpoints/karma.py b/endpoints/karma.py index 4093c62..b770b45 100644 --- a/endpoints/karma.py +++ b/endpoints/karma.py @@ -9,34 +9,10 @@ import traceback import aiosqlite as sqlite3 from fastapi import FastAPI, Request, HTTPException from pydantic import BaseModel +from .constructors import ValidTopKarmaRequest, ValidKarmaRetrievalRequest,\ + ValidKarmaUpdateRequest -class ValidKarmaUpdateRequest(BaseModel): - """ - Requires authentication - - **granter**: who updated the karma - - **keyword**: keyword to update karma for - - **flag**: either 0 (decrement) for --, or 1 (increment) for ++ - """ - - granter: str - keyword: str - flag: int - - -class ValidKarmaRetrievalRequest(BaseModel): - """ - - **keyword**: keyword to retrieve karma value of - """ - - keyword: str - -class ValidTopKarmaRequest(BaseModel): - """ - - **n**: Number of top results to return (default: 10) - """ - n: int | None = 10 - class KarmaDB: """Karma DB Util""" def __init__(self): diff --git a/endpoints/lastfm.py b/endpoints/lastfm.py index b270c9e..e9fd1ce 100644 --- a/endpoints/lastfm.py +++ b/endpoints/lastfm.py @@ -5,54 +5,8 @@ import importlib import traceback from fastapi import FastAPI from pydantic import BaseModel - -class ValidArtistSearchRequest(BaseModel): - """ - - **a**: artist name - """ - - a: str - - class Config: # pylint: disable=missing-class-docstring - schema_extra = { - "example": { - "a": "eminem" - } - } - -class ValidAlbumDetailRequest(BaseModel): - """ - - **a**: artist name - - **a2**: album/release name (as sourced from here/LastFM) - """ - - a: str - a2: str - - class Config: # pylint: disable=missing-class-docstring - schema_extra = { - "example": { - "a": "eminem", - "a2": "houdini" - } - } - -class ValidTrackInfoRequest(BaseModel): - """ - - **a**: artist name - - **t**: track - """ - - a: str - t: str - - class Config: # pylint: disable=missing-class-docstring - schema_extra = { - "example": { - "a": "eminem", - "t": "rap god" - } - } +from .constructors import ValidArtistSearchRequest, ValidAlbumDetailRequest,\ + ValidTrackInfoRequest class LastFM(FastAPI): """Last.FM Endpoints""" diff --git a/endpoints/lyric_search.py b/endpoints/lyric_search.py index 1ee7009..4fa6a5e 100644 --- a/endpoints/lyric_search.py +++ b/endpoints/lyric_search.py @@ -12,52 +12,12 @@ import aiohttp import aiosqlite as sqlite3 from fastapi import FastAPI, HTTPException from pydantic import BaseModel +from .constructors import ValidTypeAheadRequest, ValidLyricRequest from lyric_search.sources import aggregate from lyric_search import notifier -class ValidLyricRequest(BaseModel): - """ - - **a**: artist - - **s**: song - - **t**: track (artist and song combined) [used only if a & s are not used] - - **extra**: include extra details in response [optional, default: false] - - **lrc**: Request LRCs? - - **sub**: text to search within lyrics, if found lyrics will begin at found verse [optional] - - **src**: the script/utility which initiated the request - - **excluded_sources**: sources to exclude (new only) - """ - a: str | None = None - s: str | None = None - t: str | None = None - sub: str | None = None - extra: bool | None = False - lrc: bool | None = False - src: str - excluded_sources: list | None = None - - model_config = { - "json_schema_extra": { - "examples": [ - { - "a": "eminem", - "s": "rap god", - "src": "WEB", - "extra": True, - "lrc": False, - "excluded_sources": [], - }] - } - } - - -class ValidTypeAheadRequest(BaseModel): - """ - - **query**: query string - """ - pre_query: str|None = None - query: str class CacheUtils: """Lyrics Cache DB Utils""" diff --git a/endpoints/radio.py b/endpoints/radio.py index 7fb3ec9..62bda39 100644 --- a/endpoints/radio.py +++ b/endpoints/radio.py @@ -11,6 +11,8 @@ import asyncio import regex import music_tag from . import radio_util +from .constructors import ValidRadioNextRequest, ValidRadioReshuffleRequest, ValidRadioQueueShiftRequest,\ + ValidRadioQueueRemovalRequest, ValidRadioSongRequest, RadioException from uuid import uuid4 as uuid from typing import Optional from pydantic import BaseModel @@ -24,58 +26,7 @@ double_space = regex.compile(r'\s{2,}') TODO: minor refactoring/type annotations/docstrings """ - - -class RadioException(Exception): - pass - - -class ValidRadioSongRequest(BaseModel): - """ - - **key**: API Key - - **artist**: artist to search - - **song**: song to search - - **artistsong**: may be used IN PLACE OF artist/song to perform a combined/string search in the format "artist - song" - - **alsoSkip**: Whether to skip immediately to this track [not implemented] - """ - key: str - artist: str | None = None - song: str | None = None - artistsong: str | None = None - alsoSkip: bool = False - -class ValidRadioNextRequest(BaseModel): - """ - - **key**: API Key - - **skipTo**: UUID to skip to [optional] - """ - key: str - skipTo: str|None = None - -class ValidRadioReshuffleRequest(ValidRadioNextRequest): - """ - - **key**: API Key - """ - -class ValidRadioQueueShiftRequest(BaseModel): - """ - - **key**: API Key - - **uuid**: UUID to shift - - **next**: Play next if true, immediately if false, default False - """ - key: str - uuid: str - next: bool = False - -class ValidRadioQueueRemovalRequest(BaseModel): - """ - - **key**: API Key - - **uuid**: UUID to remove - """ - key: str - uuid: str - - + diff --git a/endpoints/rand_msg.py b/endpoints/rand_msg.py index 2b6541d..2caf20b 100644 --- a/endpoints/rand_msg.py +++ b/endpoints/rand_msg.py @@ -6,13 +6,7 @@ from typing import Optional import aiosqlite as sqlite3 from fastapi import FastAPI from pydantic import BaseModel - -class RandMsgRequest(BaseModel): - """ - - **short**: Short randmsg? - """ - - short: Optional[bool] = False +from .constructors import RandMsgRequest class RandMsg(FastAPI): """Random Message Endpoint""" diff --git a/endpoints/transcriptions.py b/endpoints/transcriptions.py index f376331..7a3cc9d 100644 --- a/endpoints/transcriptions.py +++ b/endpoints/transcriptions.py @@ -4,22 +4,8 @@ import os import aiosqlite as sqlite3 from fastapi import FastAPI from pydantic import BaseModel +from .constructors import ValidShowEpisodeLineRequest, ValidShowEpisodeListRequest -class ValidShowEpisodeListRequest(BaseModel): - """ - - **s**: show id - """ - - s: int - -class ValidShowEpisodeLineRequest(BaseModel): - """ - - **s**: show id - - **e**: episode id - """ - - s: int - e: int class Transcriptions(FastAPI): """Transcription Endpoints""" diff --git a/endpoints/xc.py b/endpoints/xc.py index 96b9155..27d6f01 100644 --- a/endpoints/xc.py +++ b/endpoints/xc.py @@ -4,21 +4,7 @@ from fastapi import FastAPI, Request, HTTPException from pydantic import BaseModel from aiohttp import ClientSession, ClientTimeout - -class ValidXCRequest(BaseModel): - """ - - **key**: valid XC API key - - **bid**: bot id - - **cmd**: bot command - - **data**: command data - """ - - key: str - bid: int - cmd: str - data: dict | None = None - - +from .constructors import ValidXCRequest class XC(FastAPI): """XC (CrossComm) Endpoints""" diff --git a/endpoints/yt.py b/endpoints/yt.py index c254613..93c89c7 100644 --- a/endpoints/yt.py +++ b/endpoints/yt.py @@ -3,14 +3,7 @@ import importlib from fastapi import FastAPI from pydantic import BaseModel - -class ValidYTSearchRequest(BaseModel): - """ - - **t**: title to search - """ - - t: str = "rick astley - never gonna give you up" - +from .constructors import ValidYTSearchRequest class YT(FastAPI): """YT Endpoints""" diff --git a/gpt/__init__.py b/gpt/__init__.py index a14bf86..76d68cb 100644 --- a/gpt/__init__.py +++ b/gpt/__init__.py @@ -12,7 +12,7 @@ class GPT: api_key=self.api_key, timeout=10.0, ) - self.default_system_prompt = "You are a helpful assistant who will provide tidbits of info on songs the user may listen to." + self.default_system_prompt = "You are a helpful assistant who will provide only totally accurate tidbits of info on the specific songs the user may listen to." async def get_completion(self, prompt: str, system_prompt: Optional[str] = None) -> None: if not system_prompt: @@ -29,5 +29,6 @@ class GPT: } ], model="gpt-4o-mini", + temperature=0.35, ) return chat_completion.choices[0].message.content \ No newline at end of file