Skip to content

Commit

Permalink
ai: fix crash when openai package is not installed (#912)
Browse files Browse the repository at this point in the history
* ai: fix crash when openai package is not installed

* set ENABLE_AI_STANDBY_MATCHER to false by default
  • Loading branch information
cosven authored Feb 20, 2025
1 parent a36d576 commit 8d45b61
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 3 deletions.
4 changes: 3 additions & 1 deletion feeluown/app/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,9 @@ def create_config() -> Config:
)
config.deffield('OPENAI_API_KEY', type_=str, default='', desc='OpenAI API key')
config.deffield('OPENAI_MODEL', type_=str, default='', desc='OpenAI model name')
config.deffield('ENABLE_AI_STANDBY_MATCHER', type_=bool, default=True, desc='')
# Not sure if AI_STANDBY_MATCHER may be activated unexpectedly.
# And it may burn some money, let user enable it manually.
config.deffield('ENABLE_AI_STANDBY_MATCHER', type_=bool, default=False, desc='')
config.deffield(
'AI_RADIO_PROMPT',
type_=str,
Expand Down
3 changes: 2 additions & 1 deletion feeluown/gui/uimain/sidebar.py
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,6 @@ def __init__(self, app: 'GuiApp', parent=None):
lambda: self._app.browser.goto(page='/homepage'))
else:
self.home_btn.clicked.connect(self.show_library)
self.ai_btn.clicked.connect(self._app.ui.ai_chat_overlay.show)
if self._app.ai is None:
self.ai_btn.setDisabled(True)
self.ai_btn.setToolTip(
Expand All @@ -116,6 +115,8 @@ def __init__(self, app: 'GuiApp', parent=None):
'config.OPENAI_API_BASEURL = "http://xxx"\n'
'config.OPENAI_API_MODEL = "model name"\n'
)
else:
self.ai_btn.clicked.connect(self._app.ui.ai_chat_overlay.show)

def _toggle_top_layout(self, checked):
widgets = [self._top_separator, self.collections_con, self.home_btn, self.ai_btn]
Expand Down
3 changes: 2 additions & 1 deletion feeluown/library/library.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
from feeluown.media import Media
from feeluown.utils.aio import run_fn, as_completed
from feeluown.utils.dispatch import Signal
from feeluown.library.ai_standby import AIStandbyMatcher
from feeluown.library.base import SearchType, ModelType
from feeluown.library.provider import Provider
from feeluown.library.excs import (
Expand Down Expand Up @@ -267,6 +266,8 @@ async def a_list_song_standby_v2(
if song_media_list:
return song_media_list
if self.enable_ai_standby_matcher and self.ai and top2_standby:
from feeluown.library.ai_standby import AIStandbyMatcher # noqa

logger.info(f'Try to use AI to match standby for song {song}')
matcher = AIStandbyMatcher(
self.ai, self.a_song_prepare_media_no_exc, 60, audio_select_policy)
Expand Down

0 comments on commit 8d45b61

Please # to comment.