fix lora fetch#67
Conversation
Summary of ChangesHello @tastelikefeet, 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 addresses a bug in the LoRA adapter fetching logic by implementing robust error handling. Previously, attempting to retrieve a non-existent LoRA adapter would result in an 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 correctly fixes a potential IndexError in find_lora_by_tenant and find_lora by checking if a matching lora exists before trying to access it. The change is good and improves robustness. I've added a couple of suggestions to refactor the implementation for better efficiency and readability by avoiding the creation of intermediate lists.
| _loras = [_lora for _lora in self.loras if _lora.tenant_adapter_name == tenant_adapter_name] | ||
| if len(_loras) > 0: | ||
| return _loras[0] | ||
| else: | ||
| raise ValueError(f'No lora found for tenant {tenant_adapter_name}') |
There was a problem hiding this comment.
While this correctly fixes the potential IndexError, it can be made more efficient. Instead of creating a new list of all matching loras just to get the first one, you can iterate through self.loras and return the first match found. This avoids creating an intermediate list and stops iteration as soon as a match is found.
for _lora in self.loras:
if _lora.tenant_adapter_name == tenant_adapter_name:
return _lora
raise ValueError(f'No lora found for tenant {tenant_adapter_name}')| _loras = [_lora for _lora in self.loras if _lora.adapter_name == adapter_name] | ||
| if len(_loras) > 0: | ||
| return _loras[0] | ||
| else: | ||
| raise ValueError(f'No lora found for real adapter_name {adapter_name}') |
There was a problem hiding this comment.
Similar to my previous comment, this implementation can be made more efficient. Iterating to find the first match is preferable to building a list of all matches, especially since only the first element is used.
for _lora in self.loras:
if _lora.adapter_name == adapter_name:
return _lora
raise ValueError(f'No lora found for real adapter_name {adapter_name}')
PR type
PR information
Write the detail information belongs to this PR.
Experiment results
Paste your experiment result here(if needed).