🐫 CAMEL: The first and the best multi-agent framework. Finding the Scaling Law of Agents. https://www.camel-ai.org
Python agentai-societiesartificial-intelligencecommunicative-aicooperative-aideep-learninglarge-language-modelsmulti-agent-systemsnatural-language-processing
feat: Integrate fish audio (#1287)
Wendong-Fand779a0603e5f
diff --git a/camel/agents/chat_agent.py b/camel/agents/chat_agent.pyindex ddbf0233a..bfc975b9b 100644--- a/camel/agents/chat_agent.py+++ b/camel/agents/chat_agent.py@@ -1042,7 +1042,7 @@ class ChatAgent(BaseAgent):num_tokens (int): The number of tokens used in this step.external_tool_request (Optional[ChatCompletionMessageToolCall]):Any external tool request made during this step.- (default::obj:`None`)+ (default: :obj:`None`)Returns:Dict[str, Any]: A dictionary containing information about the chatdiff --git a/camel/messages/base.py b/camel/messages/base.pyindex c9b11f4af..2dc754012 100644--- a/camel/messages/base.py+++ b/camel/messages/base.py@@ -52,15 +52,15 @@ class BaseMessage:for the message.content (str): The content of the message.video_bytes (Optional[bytes]): Optional bytes of a video associated- with the message. (default::obj:`None`)+ with the message. (default: :obj:`None`)image_list (Optional[List[Image.Image]]): Optional list of PIL Image- objects associated with the message. (default::obj:`None`)+ objects associated with the message. (default: :obj:`None`)image_detail (Literal["auto", "low", "high"]): Detail level of the- images associated with the message. (default::obj:`auto`)+ images associated with the message. (default: :obj:`auto`)video_detail (Literal["auto", "low", "high"]): Detail level of the- videos associated with the message. (default::obj:`low`)+ videos associated with the message. (default: :obj:`low`)parsed: Optional[Union[Type[BaseModel], dict]]: Optional object which- is parsed from the content. (default::obj:`None`)+ is parsed from the content. (default: :obj:`None`)"""role_name: strdiff --git a/camel/models/__init__.py b/camel/models/__init__.pyindex 94fc012bf..a80a80d92 100644--- a/camel/models/__init__.py+++ b/camel/models/__init__.py@@ -16,6 +16,7 @@ from .azure_openai_model import AzureOpenAIModelfrom .base_model import BaseModelBackendfrom .cohere_model import CohereModelfrom .deepseek_model import DeepSeekModel+from .fish_audio_model import FishAudioModelfrom .gemini_model import GeminiModelfrom .groq_model import GroqModelfrom .litellm_model import LiteLLMModel@@ -66,4 +67,5 @@ __all__ = ['QwenModel','ModelProcessingError','DeepSeekModel',+ 'FishAudioModel',]diff --git a/camel/models/anthropic_model.py b/camel/models/anthropic_model.pyindex 970093999..0b1e1827e 100644--- a/camel/models/anthropic_model.py+++ b/camel/models/anthropic_model.py@@ -35,7 +35,7 @@ class AnthropicModel(BaseModelBackend):model_config_dict (Optional[Dict[str, Any]], optional): A dictionarythat will be fed into Anthropic.messages.create(). If:obj:`None`, :obj:`AnthropicConfig().as_dict()` will be used.- (default::obj:`None`)+ (default: :obj:`None`)api_key (Optional[str], optional): The API key for authenticating withthe Anthropic service. (default: :obj:`None`)url (Optional[str], optional): The url to the Anthropic service.diff --git a/camel/models/fish_audio_model.py b/camel/models/fish_audio_model.pynew file mode 100644index 000000000..8c550dc43--- /dev/null+++ b/camel/models/fish_audio_model.py@@ -0,0 +1,146 @@+# ========= Copyright 2023-2024 @ CAMEL-AI.org. All Rights Reserved. =========+# Licensed under the Apache License, Version 2.0 (the "License");+# you may not use this file except in compliance with the License.+# You may obtain a copy of the License at+#+# http://www.apache.org/licenses/LICENSE-2.0+#+# Unless required by applicable law or agreed to in writing, software+# distributed under the License is distributed on an "AS IS" BASIS,+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.+# See the License for the specific language governing permissions and+# limitations under the License.+# ========= Copyright 2023-2024 @ CAMEL-AI.org. All Rights Reserved. =========++import os+from typing import Any, Optional+++class FishAudioModel:+ r"""Provides access to FishAudio's Text-to-Speech (TTS) and Speech_to_Text+ (STT) models.+ """++ def __init__(+ self,+ api_key: Optional[str] = None,+ url: Optional[str] = None,+ ) -> None:+ r"""Initialize an instance of FishAudioModel.++ Args:+ api_key (Optional[str]): API key for FishAudio service. If not+ provided, the environment variable `FISHAUDIO_API_KEY` will be+ used.+ url (Optional[str]): Base URL for FishAudio API. If not provided,+ the environment variable `FISHAUDIO_API_BASE_URL` will be used.+ """+ from fish_audio_sdk import Session++ self._api_key = api_key or os.environ.get("FISHAUDIO_API_KEY")+ self._url = url or os.environ.get(+ "FISHAUDIO_API_BASE_URL", "https://api.fish.audio"+ )+ self.session = Session(apikey=self._api_key, base_url=self._url)++ def text_to_speech(+ self,+ input: str,+ storage_path: str,+ reference_id: Optional[str] = None,+ reference_audio: Optional[str] = None,+ reference_audio_text: Optional[str] = None,+ **kwargs: Any,+ ) -> Any:+ r"""Convert text to speech and save the output to a file.++ Args:+ input_text (str): The text to convert to speech.+ storage_path (str): The file path where the resulting speech will+ be saved.+ reference_id (Optional[str]): An optional reference ID to+ associate with the request. (default: :obj:`None`)+ reference_audio (Optional[str]): Path to an audio file for+ reference speech. (default: :obj:`None`)+ reference_audio_text (Optional[str]): Text for the reference audio.+ (default: :obj:`None`)+ **kwargs (Any): Additional parameters to pass to the TTS request.++ Raises:+ FileNotFoundError: If the reference audio file cannot be found.+ """+ from fish_audio_sdk import ReferenceAudio, TTSRequest++ directory = os.path.dirname(storage_path)+ if directory and not os.path.exists(directory):+ os.makedirs(directory)++ if not reference_audio:+ with open(f"{storage_path}", "wb") as f:+ for chunk in self.session.tts(+ TTSRequest(reference_id=reference_id, text=input, **kwargs)+ ):+ f.write(chunk)+ else:+ if not os.path.exists(reference_audio):+ raise FileNotFoundError(+ f"Reference audio file not found: {reference_audio}"+ )+ if not reference_audio_text:+ raise ValueError("reference_audio_text should be provided")+ with open(f"{reference_audio}", "rb") as audio_file:+ with open(f"{storage_path}", "wb") as f:+ for chunk in self.session.tts(+ TTSRequest(+ text=input,+ references=[+ ReferenceAudio(+ audio=audio_file.read(),+ text=reference_audio_text,+ )+ ],+ **kwargs,+ )+ ):+ f.write(chunk)++ def speech_to_text(+ self,+ audio_file_path: str,+ language: Optional[str] = None,+ ignore_timestamps: Optional[bool] = None,+ **kwargs: Any,+ ) -> str:+ r"""Convert speech to text from an audio file.++ Args:+ audio_file_path (str): The path to the audio file to transcribe.+ language (Optional[str]): The language of the audio. (default:+ :obj:`None`)+ ignore_timestamps (Optional[bool]): Whether to ignore timestamps.+ (default: :obj:`None`)+ **kwargs (Any): Additional parameters to pass to the STT request.++ Returns:+ str: The transcribed text from the audio.++ Raises:+ FileNotFoundError: If the audio file cannot be found.+ """+ from fish_audio_sdk import ASRRequest++ if not os.path.exists(audio_file_path):+ raise FileNotFoundError(f"Audio file not found: {audio_file_path}")++ with open(f"{audio_file_path}", "rb") as audio_file:+ audio_data = audio_file.read()++ response = self.session.asr(+ ASRRequest(+ audio=audio_data,+ language=language,+ ignore_timestamps=ignore_timestamps,+ **kwargs,+ )+ )+ return response.textdiff --git a/camel/runtime/configs.py b/camel/runtime/configs.pyindex 2ff694389..c286011b1 100644--- a/camel/runtime/configs.py+++ b/camel/runtime/configs.py@@ -21,23 +21,23 @@ class TaskConfig(BaseModel):Arttributes:cmd (str or list): Command to be executed- stdout (bool): Attach to stdout. (default::obj: `True`)- stderr (bool): Attach to stderr. (default::obj: `True`)- stdin (bool): Attach to stdin. (default::obj: `False`)- tty (bool): Allocate a pseudo-TTY. (default::obj: `False`)- privileged (bool): Run as privileged. (default::obj: `False`)- user (str): User to execute command as. (default::obj: `""`)+ stdout (bool): Attach to stdout. (default: :obj: `True`)+ stderr (bool): Attach to stderr. (default: :obj: `True`)+ stdin (bool): Attach to stdin. (default: :obj: `False`)+ tty (bool): Allocate a pseudo-TTY. (default: :obj: `False`)+ privileged (bool): Run as privileged. (default: :obj: `False`)+ user (str): User to execute command as. (default: :obj: `""`)detach (bool): If true, detach from the exec command.- (default::obj: `False`)- stream (bool): Stream response data. (default::obj: `False`)+ (default: :obj: `False`)+ stream (bool): Stream response data. (default: :obj: `False`)socket (bool): Return the connection socket to allow custom- read/write operations. (default::obj: `False`)+ read/write operations. (default: :obj: `False`)environment (dict or list): A dictionary or a list of strings inthe following format ``["PASSWORD=xxx"]`` or- ``{"PASSWORD": "xxx"}``. (default::obj: `None`)+ ``{"PASSWORD": "xxx"}``. (default: :obj: `None`)workdir (str): Path to working directory for this exec session.- (default::obj: `None`)- demux (bool): Return stdout and stderr separately. (default::obj:+ (default: :obj: `None`)+ demux (bool): Return stdout and stderr separately. (default: :obj:`False`)"""diff --git a/camel/runtime/docker_runtime.py b/camel/runtime/docker_runtime.pyindex 370899cf6..c0a38a269 100644--- a/camel/runtime/docker_runtime.py+++ b/camel/runtime/docker_runtime.py@@ -42,10 +42,10 @@ class DockerRuntime(BaseRuntime):Args:image (str): The name of the Docker image to use for the runtime.- port (int): The port number to use for the runtime API. (default::obj:+ port (int): The port number to use for the runtime API. (default: :obj:`8000`)remove (bool): Whether to remove the container after stopping it. '- (default::obj: `True`)+ (default: :obj: `True`)kwargs (dict): Additional keyword arguments to pass to theDocker client."""@@ -170,7 +170,7 @@ class DockerRuntime(BaseRuntime):Args:time_out (int): The number of seconds to wait for the container to- start. (default::obj: `15`)+ start. (default: :obj: `15`)Returns:DockerRuntime: The DockerRuntime instance.@@ -259,9 +259,9 @@ class DockerRuntime(BaseRuntime):list of functions to add.entrypoint (str): The entrypoint for the function.redirect_stdout (bool): Whether to return the stdout of- the function. (default::obj: `False`)+ the function. (default: :obj: `False`)arguments (Optional[Dict[str, Any]]): The arguments for the- function. (default::obj: `None`)+ function. (default: :obj: `None`)Returns:DockerRuntime: The DockerRuntime instance.@@ -330,7 +330,7 @@ class DockerRuntime(BaseRuntime):Args:remove (Optional[bool]): Whether to remove the container- after stopping it. (default::obj: `None`)+ after stopping it. (default: :obj: `None`)Returns:DockerRuntime: The DockerRuntime instance.@@ -366,7 +366,7 @@ class DockerRuntime(BaseRuntime):r"""Wait for the API Server to be ready.Args:- timeout (int): The number of seconds to wait. (default::obj: `10`)+ timeout (int): The number of seconds to wait. (default: :obj: `10`)Returns:bool: Whether the API Server is ready.diff --git a/camel/runtime/llm_guard_runtime.py b/camel/runtime/llm_guard_runtime.pyindex 20b136fa1..a6d672fda 100644--- a/camel/runtime/llm_guard_runtime.py+++ b/camel/runtime/llm_guard_runtime.py@@ -68,9 +68,9 @@ class LLMGuardRuntime(BaseRuntime):Arguments:prompt (str): The prompt to use for the language model. (default::obj:`GUARDPROMPT`)- model (BaseModelBackend): The language model to use. (default::obj:+ model (BaseModelBackend): The language model to use. (default: :obj:`None`)- verbose (bool): Whether to print verbose output. (default::obj:+ verbose (bool): Whether to print verbose output. (default: :obj:`False`)"""@@ -114,7 +114,7 @@ class LLMGuardRuntime(BaseRuntime):funcs (FunctionTool or List[FunctionTool]): The function orlist of functions to add.threshold (int): The risk threshold for functions.- (default::obj:`2`)+ (default: :obj:`2`)Returns:LLMGuardRuntime: The current runtime.diff --git a/camel/runtime/remote_http_runtime.py b/camel/runtime/remote_http_runtime.pyindex ef34773aa..d3fff2c5e 100644--- a/camel/runtime/remote_http_runtime.py+++ b/camel/runtime/remote_http_runtime.py@@ -36,9 +36,9 @@ class RemoteHttpRuntime(BaseRuntime):Args:host (str): The host of the remote server.- port (int): The port of the remote server. (default::obj: `8000`)+ port (int): The port of the remote server. (default: :obj: `8000`)python_exec (str): The python executable to run the API server.- (default::obj: `python3`)+ (default: :obj: `python3`)"""def __init__(@@ -90,9 +90,9 @@ class RemoteHttpRuntime(BaseRuntime):list of functions to add.entrypoint (str): The entrypoint for the function.redirect_stdout (bool): Whether to return the stdout of- the function. (default::obj: `False`)+ the function. (default: :obj: `False`)arguments (Optional[Dict[str, Any]]): The arguments for the- function. (default::obj: `None`)+ function. (default: :obj: `None`)Returns:RemoteHttpRuntime: The current runtime.@@ -162,7 +162,7 @@ class RemoteHttpRuntime(BaseRuntime):r"""Wait for the API Server to be ready.Args:- timeout (int): The number of seconds to wait. (default::obj: `10`)+ timeout (int): The number of seconds to wait. (default: :obj: `10`)Returns:bool: Whether the API Server is ready.diff --git a/camel/runtime/utils/function_risk_toolkit.py b/camel/runtime/utils/function_risk_toolkit.pyindex 3ea7300d2..f00ef2dd2 100644--- a/camel/runtime/utils/function_risk_toolkit.py+++ b/camel/runtime/utils/function_risk_toolkit.py@@ -22,7 +22,7 @@ class FunctionRiskToolkit(BaseToolkit):Args:verbose (Optional[bool]): Whether to print verbose output.- (default::obj:`False`)+ (default: :obj:`False`)"""def __init__(self, verbose: Optional[bool] = False):diff --git a/camel/runtime/utils/ignore_risk_toolkit.py b/camel/runtime/utils/ignore_risk_toolkit.pyindex f195ed617..e21c2d274 100644--- a/camel/runtime/utils/ignore_risk_toolkit.py+++ b/camel/runtime/utils/ignore_risk_toolkit.py@@ -22,9 +22,9 @@ class IgnoreRiskToolkit(BaseToolkit):Args:function_names (Optional[List[str]]): A list of function names to- ignore risks for. (default::obj:`None`)+ ignore risks for. (default: :obj:`None`)verbose (Optional[bool]): Whether to print verbose output.- (default::obj:`False`)+ (default: :obj:`False`)"""def __init__(diff --git a/camel/toolkits/arxiv_toolkit.py b/camel/toolkits/arxiv_toolkit.pyindex 2ff96eedf..7912aea8f 100644--- a/camel/toolkits/arxiv_toolkit.py+++ b/camel/toolkits/arxiv_toolkit.py@@ -44,9 +44,9 @@ class ArxivToolkit(BaseToolkit):query (str): The search query string used to search for papers onarXiv.paper_ids (List[str], optional): A list of specific arXiv paper- IDs to search for. (default::obj: `None`)+ IDs to search for. (default: :obj: `None`)max_results (int, optional): The maximum number of search results- to retrieve. (default::obj: `5`)+ to retrieve. (default: :obj: `5`)Returns:Generator: A generator that yields results from the arXiv search@@ -75,9 +75,9 @@ class ArxivToolkit(BaseToolkit):Args:query (str): The search query string.paper_ids (List[str], optional): A list of specific arXiv paper- IDs to search for. (default::obj: `None`)+ IDs to search for. (default: :obj: `None`)max_results (int, optional): The maximum number of search results- to return. (default::obj: `5`)+ to return. (default: :obj: `5`)Returns:List[Dict[str, str]]: A list of dictionaries, each containing@@ -119,9 +119,9 @@ class ArxivToolkit(BaseToolkit):Args:query (str): The search query string.paper_ids (List[str], optional): A list of specific arXiv paper- IDs to download. (default::obj: `None`)+ IDs to download. (default: :obj: `None`)max_results (int, optional): The maximum number of search results- to download. (default::obj: `5`)+ to download. (default: :obj: `5`)output_dir (str, optional): The directory to save the downloadedPDFs. Defaults to the current directory.diff --git a/camel/toolkits/ask_news_toolkit.py b/camel/toolkits/ask_news_toolkit.pyindex a5c7bc6b2..c0aff1bff 100644--- a/camel/toolkits/ask_news_toolkit.py+++ b/camel/toolkits/ask_news_toolkit.py@@ -228,7 +228,7 @@ class AskNewsToolkit(BaseToolkit):return value. (default: :obj:`"string"`)method (Literal["nl", "kw"]): The search method, either "nl" fornatural language or "kw" for keyword search.- (default::obj:`"kw"`)+ (default: :obj:`"kw"`)Returns:Union[str, dict, Tuple[str, dict]]: The Reddit search@@ -523,7 +523,7 @@ class AsyncAskNewsToolkit(BaseToolkit):return value. (default: :obj:"string")method (Literal["nl", "kw"]): The search method, either "nl" fornatural language or "kw" for keyword search.- (default::obj:"kw")+ (default: :obj:"kw")Returns:Union[str, dict, Tuple[str, dict]]: The Reddit searchdiff --git a/camel/toolkits/github_toolkit.py b/camel/toolkits/github_toolkit.pyindex 316e911d5..2ebfb6d72 100644--- a/camel/toolkits/github_toolkit.py+++ b/camel/toolkits/github_toolkit.py@@ -139,7 +139,7 @@ class GithubToolkit(BaseToolkit):Args:state (Literal["open", "closed", "all"]): The state of pull- requests to retrieve. (default::obj: `all`)+ requests to retrieve. (default: :obj: `all`)Options are:- "open": Retrieve only open pull requests.- "closed": Retrieve only closed pull requests.@@ -179,7 +179,7 @@ class GithubToolkit(BaseToolkit):Args:state (Literal["open", "closed", "all"]): The state of pull- requests to retrieve. (default::obj: `all`)+ requests to retrieve. (default: :obj: `all`)Options are:- "open": Retrieve only open pull requests.- "closed": Retrieve only closed pull requests.@@ -254,7 +254,7 @@ class GithubToolkit(BaseToolkit):Args:path (str): The repository path to start the traversal from.empty string means starts from the root directory.- (default::obj: `""`)+ (default: :obj: `""`)Returns:List[str]: A list of file paths within the specified directorydiff --git a/camel/toolkits/meshy_toolkit.py b/camel/toolkits/meshy_toolkit.pyindex cf49e01f9..3987b2dbd 100644--- a/camel/toolkits/meshy_toolkit.py+++ b/camel/toolkits/meshy_toolkit.py@@ -117,9 +117,9 @@ class MeshyToolkit(BaseToolkit):Args:task_id (str): The ID of the task to monitor.polling_interval (int): Seconds to wait between status checks.- (default::obj:`10`)+ (default: :obj:`10`)timeout (int): Maximum seconds to wait before timing out.- (default::obj:`3600`)+ (default: :obj:`3600`)Returns:Dict[str, Any]: Final response from the API when task completes.diff --git a/camel/toolkits/search_toolkit.py b/camel/toolkits/search_toolkit.pyindex ef40f7023..3e6f62cd1 100644--- a/camel/toolkits/search_toolkit.py+++ b/camel/toolkits/search_toolkit.py@@ -181,7 +181,7 @@ class SearchToolkit(BaseToolkit):country (str): The search query country where results come from.The country string is limited to 2 character country codes ofsupported countries. For a list of supported values, see- Country Codes. (default::obj:`US `)+ Country Codes. (default: :obj:`US `)search_lang (str): The search language preference. The 2 or morecharacter language code for which search results are provided.For a list of possible values, see Language Codes.@@ -416,7 +416,7 @@ class SearchToolkit(BaseToolkit):query (str): The query to send to Wolfram Alpha.is_detailed (bool): Whether to include additional detailsincluding step by step information in the result.- (default::obj:`False`)+ (default: :obj:`False`)Returns:Union[str, Dict[str, Any]]: The result from Wolfram Alpha.diff --git a/examples/models/fish_audio_model_example.py b/examples/models/fish_audio_model_example.pynew file mode 100644index 000000000..0d68d8488--- /dev/null+++ b/examples/models/fish_audio_model_example.py@@ -0,0 +1,51 @@+# ========= Copyright 2023-2024 @ CAMEL-AI.org. All Rights Reserved. =========+# Licensed under the Apache License, Version 2.0 (the "License");+# you may not use this file except in compliance with the License.+# You may obtain a copy of the License at+#+# http://www.apache.org/licenses/LICENSE-2.0+#+# Unless required by applicable law or agreed to in writing, software+# distributed under the License is distributed on an "AS IS" BASIS,+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.+# See the License for the specific language governing permissions and+# limitations under the License.+# ========= Copyright 2023-2024 @ CAMEL-AI.org. All Rights Reserved. =========++from camel.models import FishAudioModel++audio_models = FishAudioModel()++# Set example input+input = """CAMEL-AI.org is an open-source community dedicated to the study of+autonomous and communicative agents. We believe that studying these agents on+a large scale offers valuable insights into their behaviors, capabilities, and+potential risks. To facilitate research in this field, we provide, implement,+and support various types of agents, tasks, prompts, models, datasets, and+simulated environments.++Join us via Slack, Discord, or WeChat in pushing the boundaries of building AI+Society."""++# Set example local path to store the file+storage_path = "examples/fish_audio_models/example_audio.mp3"++# Convert the example input into audio and store it locally+audio_models.text_to_speech(input=input, storage_path=storage_path)++# Convert the saved audio back to text+converted_text = audio_models.speech_to_text(audio_file_path=storage_path)++# Print the converted text+print(converted_text)+'''+===============================================================================+CammelaiI.org is an open source community dedicated to the study of autonomous+and communicative agents. We believe that studying these agents on a large+scale offers valuable insights into their behaviors, capabilities and+potential risks to facilitate research in this field, we provide implement and+support various types of agents, tasks, prompts, models, datas and simulated+environments. Jo us via Slack Discord or Wechat in pushing the boundaries of+building AI society.+===============================================================================+'''diff --git a/poetry.lock b/poetry.lockindex 205989446..75b596216 100644--- a/poetry.lock+++ b/poetry.lock@@ -1891,6 +1891,23 @@ python-dotenv = "*"requests = "*"websockets = "*"+[[package]]+name = "fish-audio-sdk"+version = "2024.12.5"+description = "fish.audio platform api sdk"+optional = true+python-versions = ">=3.10"+files = [+ {file = "fish_audio_sdk-2024.12.5-py3-none-any.whl", hash = "sha256:a4ce81c6609c239d5518cc1d78c7a0699da50797e0af4d6b3758a8fb5c12384e"},+ {file = "fish_audio_sdk-2024.12.5.tar.gz", hash = "sha256:d7d2b5be0da323ca9c7b8f0d5ce3450f190a112af985c3283cb7ce330fd51e70"},+]++[package.dependencies]+httpx = ">=0.27.2"+httpx-ws = ">=0.6.2"+ormsgpack = ">=1.5.0"+pydantic = ">=2.9.1"+[[package]]name = "flatbuffers"version = "24.3.25"@@ -2740,6 +2757,23 @@ files = [{file = "httpx_sse-0.4.0-py3-none-any.whl", hash = "sha256:f329af6eae57eaa2bdfd962b42524764af68075ea87370a2de920af5341e318f"},]+[[package]]+name = "httpx-ws"+version = "0.7.0"+description = "WebSockets support for HTTPX"+optional = true+python-versions = ">=3.9"+files = [+ {file = "httpx_ws-0.7.0-py3-none-any.whl", hash = "sha256:4e888b8f662862cfafc3bbcf7d851105da4a6d50088d3168909c209762b6ea32"},+ {file = "httpx_ws-0.7.0.tar.gz", hash = "sha256:352843c3a37bd7d807bb3fd63130d30f8f7d533bfc921a409bd25edd00d26029"},+]++[package.dependencies]+anyio = ">=4"+httpcore = ">=1.0.4"+httpx = ">=0.23.1"+wsproto = "*"+[[package]]name = "huggingface-hub"version = "0.27.0"@@ -5110,6 +5144,41 @@ files = [{file = "orjson-3.10.12.tar.gz", hash = "sha256:0a78bbda3aea0f9f079057ee1ee8a1ecf790d4f1af88dd67493c6b8ee52506ff"},]+[[package]]+name = "ormsgpack"+version = "1.7.0"+description = "Fast, correct Python msgpack library supporting dataclasses, datetimes, and numpy"+optional = true+python-versions = ">=3.9"+files = [+ {file = "ormsgpack-1.7.0-cp310-cp310-macosx_10_12_x86_64.macosx_11_0_arm64.macosx_10_12_universal2.whl", hash = "sha256:a0ca6a64d47073f22ecc1dd96b384e44f98796d3f88ee383e92dfbcdf18c2efd"},+ {file = "ormsgpack-1.7.0-cp310-cp310-manylinux_2_17_aarch64.manylinux2014_aarch64.whl", hash = "sha256:e8385181bf195af80fc270e64fd477f1c414ffb05837320382e2ec9ca34be0ec"},+ {file = "ormsgpack-1.7.0-cp310-cp310-manylinux_2_17_armv7l.manylinux2014_armv7l.whl", hash = "sha256:ca4d35b694f32112eb33ac0b733cb903dbbc59f019d05ca3d74f6ad2f587b0bf"},+ {file = "ormsgpack-1.7.0-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl", hash = "sha256:e86124cdbc8ed249806347c2fba96843e8941122b161b429139a0c973d270de4"},+ {file = "ormsgpack-1.7.0-cp310-cp310-win_amd64.whl", hash = "sha256:6d114652dadd81802b8a35a49e07a3e9ef2a47aed6123fb5031f2220d1c8e434"},+ {file = "ormsgpack-1.7.0-cp311-cp311-macosx_10_12_x86_64.macosx_11_0_arm64.macosx_10_12_universal2.whl", hash = "sha256:2c22c62a6bc93bcb194b7f91864ca0b39455b2cbbfc1538a3da0f9ec3c11d184"},+ {file = "ormsgpack-1.7.0-cp311-cp311-manylinux_2_17_aarch64.manylinux2014_aarch64.whl", hash = "sha256:f9967a7f3647ad118751abf090f8397fda3e4bca6833340cab95a3f2bec598cd"},+ {file = "ormsgpack-1.7.0-cp311-cp311-manylinux_2_17_armv7l.manylinux2014_armv7l.whl", hash = "sha256:91ebb7d3609db249cdff629ffef83ec3d025b1384749a297cf3b6a8240cf22ac"},+ {file = "ormsgpack-1.7.0-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl", hash = "sha256:c683071bf4527ffa7b6cfcf28f750d1a82eb77846d106743c09261ab1b79b193"},+ {file = "ormsgpack-1.7.0-cp311-cp311-win_amd64.whl", hash = "sha256:90aabfd816db60dadab1100d583d061e0238209015bf684f8170c0fca4eb445a"},+ {file = "ormsgpack-1.7.0-cp312-cp312-macosx_10_12_x86_64.macosx_11_0_arm64.macosx_10_12_universal2.whl", hash = "sha256:77bc2ea387d85cfad045b9bcb8040bae43ad32dafe9363360f732cc19d489bbe"},+ {file = "ormsgpack-1.7.0-cp312-cp312-manylinux_2_17_aarch64.manylinux2014_aarch64.whl", hash = "sha256:5ec763096d978d35eedcef0af13991a10741717c2e236b26f4c2047b0740ea7b"},+ {file = "ormsgpack-1.7.0-cp312-cp312-manylinux_2_17_armv7l.manylinux2014_armv7l.whl", hash = "sha256:22418a4d399027a72fb2e6b873559b1886cf2e63323ca7afc17b222c454413b7"},+ {file = "ormsgpack-1.7.0-cp312-cp312-manylinux_2_17_x86_64.manylinux2014_x86_64.whl", hash = "sha256:97723786755a7df85fcf6e68d7b5359dacea98d5c26b1d9af219a3cc05df4734"},+ {file = "ormsgpack-1.7.0-cp312-cp312-win_amd64.whl", hash = "sha256:7e6ada21f5c7a20ff7cf9b061c44e3814352f819947a12022ad8cb52a9f2a809"},+ {file = "ormsgpack-1.7.0-cp313-cp313-macosx_10_12_x86_64.macosx_11_0_arm64.macosx_10_12_universal2.whl", hash = "sha256:462089a419dbde654915ccb0b859c0dbe3c178b0ac580018e82befea6ccd73f4"},+ {file = "ormsgpack-1.7.0-cp313-cp313-manylinux_2_17_aarch64.manylinux2014_aarch64.whl", hash = "sha256:4b353204e99b56c1d33f1cf4767bd1fe1195596181a1cc789f25aa26c0b50f3d"},+ {file = "ormsgpack-1.7.0-cp313-cp313-manylinux_2_17_armv7l.manylinux2014_armv7l.whl", hash = "sha256:a5e12b51a590be47ccef67907905653e679fc2f920854b456edc216690ecc09c"},+ {file = "ormsgpack-1.7.0-cp313-cp313-manylinux_2_17_x86_64.manylinux2014_x86_64.whl", hash = "sha256:3a6a97937d2cf21496d7689b90a43df83c5062bbe846aaa39197cc9ad73eaa7b"},+ {file = "ormsgpack-1.7.0-cp313-cp313-win_amd64.whl", hash = "sha256:8d301e47565fe0e52a60052e730a9bb7669dfbd2a94643b8be925e3928c64c15"},+ {file = "ormsgpack-1.7.0-cp39-cp39-macosx_10_12_x86_64.macosx_11_0_arm64.macosx_10_12_universal2.whl", hash = "sha256:a8fbe7bb50ee8381df030823d9366984fac718447947c2327969405d1d799b95"},+ {file = "ormsgpack-1.7.0-cp39-cp39-manylinux_2_17_aarch64.manylinux2014_aarch64.whl", hash = "sha256:5fefa1ca842dbba258401ea958113fe62c6b70a7a4d46edac440113f68dc431e"},+ {file = "ormsgpack-1.7.0-cp39-cp39-manylinux_2_17_armv7l.manylinux2014_armv7l.whl", hash = "sha256:9b0945523ccc75aa6907f38f2240d36818618baccb8633923bd7740a5a929e67"},+ {file = "ormsgpack-1.7.0-cp39-cp39-manylinux_2_17_x86_64.manylinux2014_x86_64.whl", hash = "sha256:65525438b4a8b3b64ccfcda25e758ea3db392d1c206b5e09ef70efbbafa6dbf9"},+ {file = "ormsgpack-1.7.0-cp39-cp39-win_amd64.whl", hash = "sha256:0d88307ab45d95416ce4071b1b99326ca31362af01c3d206f15a0551a7a874bd"},+ {file = "ormsgpack-1.7.0.tar.gz", hash = "sha256:6b4c98839cb7fc2a212037d2258f3a22857155249eb293d45c45cb974cfba834"},+]+[[package]]name = "outcome"version = "1.3.0.post0"@@ -10044,12 +10113,12 @@ test = ["big-O", "importlib-resources", "jaraco.functools", "jaraco.itertools",type = ["pytest-mypy"][extras]-all = ["PyMuPDF", "accelerate", "agentops", "anthropic", "apify_client", "arxiv", "arxiv2text", "asknews", "azure-storage-blob", "beautifulsoup4", "botocore", "cohere", "cohere", "datacommons", "datacommons_pandas", "datasets", "diffusers", "discord.py", "docker", "docx2txt", "duckduckgo-search", "e2b-code-interpreter", "ffmpeg-python", "firecrawl-py", "google-cloud-storage", "google-generativeai", "googlemaps", "imageio", "ipykernel", "jupyter_client", "litellm", "mistralai", "nebula3-python", "neo4j", "newspaper3k", "nltk", "notion-client", "openapi-spec-validator", "opencv-python", "pdfplumber", "pillow", "prance", "praw", "pyTelegramBotAPI", "pydub", "pygithub", "pymilvus", "pyowm", "pyyaml", "qdrant-client", "rank-bm25", "redis", "reka-api", "requests_oauthlib", "scholarly", "sentence-transformers", "sentencepiece", "sglang", "slack-bolt", "slack-sdk", "soundfile", "stripe", "tavily-python", "textblob", "torch", "torch", "transformers", "unstructured", "wikipedia", "wolframalpha", "yt-dlp"]+all = ["PyMuPDF", "accelerate", "agentops", "anthropic", "apify_client", "arxiv", "arxiv2text", "asknews", "azure-storage-blob", "beautifulsoup4", "botocore", "cohere", "cohere", "datacommons", "datacommons_pandas", "datasets", "diffusers", "discord.py", "docker", "docx2txt", "duckduckgo-search", "e2b-code-interpreter", "ffmpeg-python", "firecrawl-py", "fish-audio-sdk", "google-cloud-storage", "google-generativeai", "googlemaps", "imageio", "ipykernel", "jupyter_client", "litellm", "mistralai", "nebula3-python", "neo4j", "newspaper3k", "nltk", "notion-client", "openapi-spec-validator", "opencv-python", "pdfplumber", "pillow", "prance", "praw", "pyTelegramBotAPI", "pydub", "pygithub", "pymilvus", "pyowm", "pyyaml", "qdrant-client", "rank-bm25", "redis", "reka-api", "requests_oauthlib", "scholarly", "sentence-transformers", "sentencepiece", "sglang", "slack-bolt", "slack-sdk", "soundfile", "stripe", "tavily-python", "textblob", "torch", "torch", "transformers", "unstructured", "wikipedia", "wolframalpha", "yt-dlp"]encoders = ["sentence-transformers"]graph-storages = ["nebula3-python", "neo4j"]huggingface-agent = ["accelerate", "datasets", "diffusers", "opencv-python", "sentencepiece", "soundfile", "torch", "torch", "transformers"]kv-stroages = ["redis"]-model-platforms = ["anthropic", "cohere", "google-generativeai", "litellm", "mistralai", "reka-api", "sglang"]+model-platforms = ["anthropic", "cohere", "fish-audio-sdk", "google-generativeai", "litellm", "mistralai", "reka-api", "sglang"]object-storages = ["azure-storage-blob", "botocore", "google-cloud-storage"]rag = ["cohere", "nebula3-python", "neo4j", "pymilvus", "qdrant-client", "rank-bm25", "sentence-transformers", "unstructured"]retrievers = ["cohere", "rank-bm25"]@@ -10062,4 +10131,4 @@ vector-databases = ["pymilvus", "qdrant-client"][metadata]lock-version = "2.0"python-versions = ">=3.10,<3.13"-content-hash = "3a8d5ec69ff26fdd80011354e8fb9c46aea056e582b0e4af8a6b500489a7d76c"+content-hash = "f789be494b3da60bc0305c54a92b9bdbeb6ed0f054c559ae10e3f9104af6e7b1"diff --git a/pyproject.toml b/pyproject.tomlindex fb4c6f3f3..a76120775 100644--- a/pyproject.toml+++ b/pyproject.toml@@ -50,6 +50,7 @@ mistralai = { version = "^1.1.0", optional = true }reka-api = { version = "^3.0.8", optional = true }anthropic = { version = "^0.40.0", optional = true }cohere = { version = "^5.11.0", optional = true }+fish-audio-sdk = { version = "^2024.12.5", optional = true }sglang = { version = "^0.4.0", optional = true }# huggingface-agent@@ -164,6 +165,7 @@ model-platforms = ["reka-api","anthropic","cohere",+ "fish-audio-sdk",'sglang',]@@ -332,6 +334,7 @@ all = ["litellm","mistralai","cohere",+ "fish-audio-sdk","google-generativeai","anthropic","reka-api",@@ -463,6 +466,7 @@ module = ["imageio","rank_bm25","cohere",+ "fish_audio_sdk","sentence_transformers.*","pymilvus","pillow",@@ -478,6 +482,7 @@ module = ["google_generativeai","mistralai","cohere",+ "fish-audio-sdk","reka-api","sglang","agentops",diff --git a/test/models/test_fish_audio_model.py b/test/models/test_fish_audio_model.pynew file mode 100644index 000000000..4cb936792--- /dev/null+++ b/test/models/test_fish_audio_model.py@@ -0,0 +1,122 @@+# ========= Copyright 2023-2024 @ CAMEL-AI.org. All Rights Reserved. =========+# Licensed under the Apache License, Version 2.0 (the "License");+# you may not use this file except in compliance with the License.+# You may obtain a copy of the License at+#+# http://www.apache.org/licenses/LICENSE-2.0+#+# Unless required by applicable law or agreed to in writing, software+# distributed under the License is distributed on an "AS IS" BASIS,+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.+# See the License for the specific language governing permissions and+# limitations under the License.+# ========= Copyright 2023-2024 @ CAMEL-AI.org. All Rights Reserved. =========++import os+from unittest.mock import MagicMock, patch++from camel.models import FishAudioModel+++def test_fish_audio_model_init():+ r"""Test initialization of FishAudioModel."""+ # Test with no API key or URL, should use environment variables+ with patch.dict(+ os.environ,+ {+ "FISHAUDIO_API_KEY": "test_api_key",+ "FISHAUDIO_API_BASE_URL": "https://api.fish.audio",+ },+ ):+ model = FishAudioModel()+ assert model._api_key == "test_api_key"+ assert model._url == "https://api.fish.audio"+++def test_fish_audio_model_text_to_speech_no_reference_audio():+ r"""Test text_to_speech with no reference audio."""+ # Mock the session's TTS method to avoid actual API calls+ with patch("fish_audio_sdk.Session") as MockSession:+ mock_session = MagicMock()+ MockSession.return_value = mock_session+ mock_session.tts.return_value = [b"audio_data"]++ model = FishAudioModel(+ api_key="test_api_key", url="https://api.fish.audio"+ )++ with patch("builtins.open") as mock_file:+ mock_file.return_value.__enter__.return_value.write = MagicMock()++ model.text_to_speech("Hello", "output_path.wav")++ mock_session.tts.assert_called_once()+ mock_file.return_value.__enter__.return_value.write.assert_called_once_with(+ b"audio_data"+ )+++def test_fish_audio_model_text_to_speech_with_reference_audio():+ r"""Test text_to_speech with reference audio."""+ with patch("fish_audio_sdk.Session") as MockSession:+ mock_session = MagicMock()+ MockSession.return_value = mock_session+ mock_session.tts.return_value = [b"audio_data"]++ with (+ patch("os.path.exists", return_value=True),+ patch("builtins.open", patch_open := MagicMock()),+ ):+ patch_open.return_value.__enter__.return_value.read = MagicMock(+ return_value=b"reference_audio_data"+ )++ model = FishAudioModel(+ api_key="test_api_key", url="https://api.fish.audio"+ )++ model.text_to_speech(+ "Hello",+ "output_path.wav",+ reference_audio="reference_audio.wav",+ reference_audio_text="Reference text",+ )++ mock_session.tts.assert_called_once()+++def test_fish_audio_model_speech_to_text():+ r"""Test speech_to_text method."""+ with patch("fish_audio_sdk.Session") as MockSession:+ mock_session = MagicMock()+ MockSession.return_value = mock_session+ mock_session.asr.return_value = MagicMock(text="Hello world")++ with patch("builtins.open", patch_open := MagicMock()):+ patch_open.return_value.__enter__.return_value.read = MagicMock(+ return_value=b"audio_data"+ )+ with patch("os.path.exists", return_value=True):+ model = FishAudioModel(+ api_key="test_api_key", url="https://api.fish.audio"+ )++ result = model.speech_to_text("audio_file.wav")++ assert result == "Hello world"+ mock_session.asr.assert_called_once()+++def test_fish_audio_model_speech_to_text_file_not_found():+ r"""Test speech_to_text raises FileNotFoundError."""+ # Create instance of FishAudioModel+ model = FishAudioModel(+ api_key="test_api_key", url="https://api.fish.audio"+ )++ # Test that the method raises FileNotFoundError if file doesn't exist+ with patch("os.path.exists", return_value=False):+ try:+ model.speech_to_text("non_existent_file.wav")+ except FileNotFoundError as e:+ assert str(e) == "Audio file not found: non_existent_file.wav"