From 8f14c422a73142a2cd11894b75443a7590f3a3cf Mon Sep 17 00:00:00 2001 From: -LAN- Date: Fri, 1 Nov 2024 17:17:27 +0800 Subject: [PATCH] refactor(tools): Avoid warnings. (#10161) --- api/core/tools/provider/builtin/chart/chart.py | 9 +++++---- .../podcast_generator/tools/podcast_audio_generator.py | 5 ++++- 2 files changed, 9 insertions(+), 5 deletions(-) diff --git a/api/core/tools/provider/builtin/chart/chart.py b/api/core/tools/provider/builtin/chart/chart.py index 209d6ecba4..dfa3fbea6a 100644 --- a/api/core/tools/provider/builtin/chart/chart.py +++ b/api/core/tools/provider/builtin/chart/chart.py @@ -1,5 +1,5 @@ import matplotlib.pyplot as plt -from matplotlib.font_manager import FontProperties +from matplotlib.font_manager import FontProperties, fontManager from core.tools.provider.builtin_tool_provider import BuiltinToolProviderController @@ -17,9 +17,10 @@ def set_chinese_font(): ] for font in font_list: - chinese_font = FontProperties(font) - if chinese_font.get_name() == font: - return chinese_font + if font in fontManager.ttflist: + chinese_font = FontProperties(font) + if chinese_font.get_name() == font: + return chinese_font return FontProperties() diff --git a/api/core/tools/provider/builtin/podcast_generator/tools/podcast_audio_generator.py b/api/core/tools/provider/builtin/podcast_generator/tools/podcast_audio_generator.py index 8c8dd9bf68..2300b69e49 100644 --- a/api/core/tools/provider/builtin/podcast_generator/tools/podcast_audio_generator.py +++ b/api/core/tools/provider/builtin/podcast_generator/tools/podcast_audio_generator.py @@ -2,14 +2,17 @@ import concurrent.futures import io import random from typing import Any, Literal, Optional, Union +from warnings import catch_warnings import openai -from pydub import AudioSegment from core.tools.entities.tool_entities import ToolInvokeMessage from core.tools.errors import ToolParameterValidationError, ToolProviderCredentialValidationError from core.tools.tool.builtin_tool import BuiltinTool +with catch_warnings(action="ignore", category=RuntimeWarning): + from pydub import AudioSegment + class PodcastAudioGeneratorTool(BuiltinTool): @staticmethod