Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(tool): fal ai wizper ASR built-in tool #10716

Merged
merged 6 commits into from
Nov 15, 2024
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
delete useless code
  • Loading branch information
fdb02983rhy committed Nov 14, 2024
commit 356dd90f2bc46505006604ba43902f4c0272fd91
26 changes: 7 additions & 19 deletions api/core/tools/provider/builtin/fal/tools/wizper.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@

class WizperTool(BuiltinTool):
def _invoke(self, user_id: str, tool_parameters: dict[str, Any]) -> ToolInvokeMessage:
# Get parameters

audio_file = tool_parameters.get("audio_file")
task = tool_parameters.get("task", "transcribe")
language = tool_parameters.get("language", "en")
Expand All @@ -22,27 +22,21 @@ def _invoke(self, user_id: str, tool_parameters: dict[str, Any]) -> ToolInvokeMe
if audio_file.type != FileType.AUDIO:
return [self.create_text_message("Not a valid audio file.")]

# Get the API key from credentials

api_key = self.runtime.credentials["fal_api_key"]
# Set the API key for fal_client

os.environ["FAL_KEY"] = api_key

# Upload the audio file using fal_client
audio_binary = io.BytesIO(download(audio_file))
mime_type = get_attr(file=audio_file, attr=FileAttribute.MIME_TYPE)
file_data = audio_binary.getvalue()

try:
# Download the audio file content
audio_binary = io.BytesIO(download(audio_file))
mime_type = get_attr(file=audio_file, attr=FileAttribute.MIME_TYPE)

# Get the file data
file_data = audio_binary.getvalue()

# Upload the file using fal_client
audio_url = fal_client.upload(file_data, mime_type)

except Exception as e:
return [self.create_text_message(f"Error uploading audio file: {str(e)}")]

# Prepare arguments for the API call
arguments = {
"audio_url": audio_url,
"task": task,
Expand All @@ -51,16 +45,10 @@ def _invoke(self, user_id: str, tool_parameters: dict[str, Any]) -> ToolInvokeMe
"version": version,
}

def on_queue_update(update):
if isinstance(update, fal_client.InProgress):
pass # Handle progress updates if needed

# Use fal_client.subscribe to submit and wait for the result
result = fal_client.subscribe(
"fal-ai/wizper",
arguments=arguments,
with_logs=False,
on_queue_update=on_queue_update,
)

return self.create_json_message(result)
Loading