openai api add AudioURL and support chat_template.json#1225
openai api add AudioURL and support chat_template.json#1225
Conversation
Summary of ChangesHello, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed! This pull request significantly expands the LightLLM server's multimodal capabilities by integrating audio input processing into its OpenAI API endpoint. It also refines the tokenizer setup process, making it more robust by allowing chat templates to be loaded from a default configuration file within the model's directory. These changes collectively enable the server to handle a broader range of multimodal interactions and simplify model deployment. Highlights
🧠 New Feature in Public Preview: You can now enable Memory to help Gemini Code Assist learn from your team's feedback. This makes future code reviews more consistent and personalized to your project's style. Click here to enable Memory in your admin console. Changelog
Activity
Using Gemini Code AssistThe full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips. Invoking Gemini You can request assistance from Gemini at any point by creating a comment using either
Customization To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a Limitations & Feedback Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for GitHub and other Google products, sign up here. You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension. Footnotes
|
There was a problem hiding this comment.
Code Review
This pull request introduces support for audio inputs via AudioURL in the OpenAI API compatibility layer and adds a fallback mechanism to load chat_template.json from the model directory. A critical security concern has been identified: a high-severity Server-Side Request Forgery (SSRF) vulnerability exists in the handling of audio_url, as the server fetches user-provided URLs without proper validation. Addressing this vulnerability is paramount. Additionally, I have provided specific suggestions to enhance the robustness and clarity of the audio processing error messages and the exception handling for loading the chat template.
| 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}) |
There was a problem hiding this comment.
The application introduces a new feature to handle audio_url in chat completions. When an audio_url starting with http:// or https:// is provided, the server subsequently fetches the resource using the fetch_resource utility 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.
| else: | ||
| raise ValueError("Unrecognized audio input.") | ||
| else: | ||
| raise ValueError("Unrecognized audio input. Supports local path, http url, base64.") |
There was a problem hiding this comment.
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.
| raise ValueError("Unrecognized audio input. Supports local path, http url, base64.") | |
| raise ValueError("Unrecognized audio input. Supports http url and base64.") |
| except Exception as e: | ||
| logger.warning(f"Failed to load chat_template from {default_chat_template_path}: {e}") |
There was a problem hiding this comment.
It's generally better to catch more specific exceptions rather than a broad Exception. This prevents catching unexpected errors like KeyboardInterrupt or SystemExit. For loading and parsing the chat template, catching IOError and json.JSONDecodeError would be more appropriate.
| except Exception as e: | |
| logger.warning(f"Failed to load chat_template from {default_chat_template_path}: {e}") | |
| except (IOError, json.JSONDecodeError) as e: | |
| logger.warning(f"Failed to load chat_template from {default_chat_template_path}: {e}") |
No description provided.