-
Notifications
You must be signed in to change notification settings - Fork 305
openai api add AudioURL and support chat_template.json #1225
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||
|---|---|---|---|---|---|---|
|
|
@@ -174,7 +174,7 @@ async def chat_completions_impl(request: ChatCompletionRequest, raw_request: Req | |||||
|
|
||||||
| created_time = int(time.time()) | ||||||
|
|
||||||
| multimodal_params_dict = {"images": []} | ||||||
| multimodal_params_dict = {"images": [], "audios": []} | ||||||
| for message in request.messages: | ||||||
| if isinstance(message.content, list): | ||||||
| texts = [] | ||||||
|
|
@@ -197,6 +197,19 @@ async def chat_completions_impl(request: ChatCompletionRequest, raw_request: Req | |||||
| raise ValueError( | ||||||
| "Unrecognized image input. Supports local path, http url, base64, and PIL.Image." | ||||||
| ) | ||||||
| elif content.type == "audio_url" and content.audio_url is not None: | ||||||
| audio = content.audio_url.url | ||||||
| if audio.startswith("http://") or audio.startswith("https://"): | ||||||
| multimodal_params_dict["audios"].append({"type": "url", "data": audio}) | ||||||
| elif audio.startswith("data:audio"): | ||||||
| data_str = audio.split(";", 1)[1] | ||||||
| if data_str.startswith("base64,"): | ||||||
| data = data_str[7:] | ||||||
| multimodal_params_dict["audios"].append({"type": "base64", "data": data}) | ||||||
| else: | ||||||
| raise ValueError("Unrecognized audio input.") | ||||||
| else: | ||||||
| raise ValueError("Unrecognized audio input. Supports local path, http url, base64.") | ||||||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The error message "Unrecognized audio input. Supports local path, http url, base64." is misleading because the current implementation does not handle local file paths for audio inputs. It only supports URLs and base64-encoded data. To avoid confusion, the error message should be updated to reflect the actual supported formats.
Suggested change
|
||||||
|
|
||||||
| tools = None | ||||||
| if request.tools and request.tool_choice != "none": | ||||||
|
|
||||||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The application introduces a new feature to handle
audio_urlin chat completions. When anaudio_urlstarting withhttp://orhttps://is provided, the server subsequently fetches the resource using thefetch_resourceutility function without any validation of the target host. This allows an attacker to perform Server-Side Request Forgery (SSRF) attacks, potentially accessing internal network resources such as cloud metadata services (e.g.,http://169.254.169.254/latest/meta-data/) or internal APIs.To remediate this, implement strict validation for the
audio_url. This should include maintaining an allow-list of trusted domains and ensuring that the resolved IP address is not a private or reserved IP address.