-
Notifications
You must be signed in to change notification settings - Fork 2.8k
feat: Vllm url support v1 #4010
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 |
|---|---|---|
|
|
@@ -28,10 +28,11 @@ def is_cache_model(): | |
|
|
||
| @staticmethod | ||
| def new_instance(model_type, model_name, model_credential: Dict[str, object], **model_kwargs): | ||
| r_url = model_credential.get('api_url')[:-3] if model_credential.get('api_url').endswith('/v1') else model_credential.get('api_url') | ||
| return VllmBgeReranker( | ||
| model=model_name, | ||
| api_key=model_credential.get('api_key'), | ||
| api_url=model_credential.get('api_url'), | ||
| api_url=r_url, | ||
| params=model_kwargs, | ||
| **model_kwargs | ||
| ) | ||
|
Contributor
Author
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 provided code for
Here's an optimized version of the code with these suggestions: def is_cache_model():
# Implement logic if needed
@staticmethod
def new_instance(model_type, model_name, model_credential: Dict[str, object], **model_kwargs):
_processed_api_url = (
model_credential.get('api_url')[:-4]
if model_credential.get('api_url').endswith('/v1/')
else model_credential.get('api_url', "")
)
try:
return VllmBgeReranker(
model=model_name,
api_key=model_credential.get('api_key'),
api_url=_processed_api_url,
params=model_kwargs,
**model_kwargs
)
except AttributeError as e:
print(f"Error while setting up the model: {e}")These improvements make the function more robust and easier to understand. |
||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -44,7 +44,9 @@ def check_auth(self): | |
| self.speech_to_text(audio_file) | ||
|
|
||
| def speech_to_text(self, audio_file): | ||
| base_url = f"{self.api_url}/v1" | ||
|
|
||
| base_url = self.api_url if self.api_url.endswith('v1') else f"{self.api_url}/v1" | ||
|
|
||
| try: | ||
| client = OpenAI( | ||
| api_key=self.api_key, | ||
|
Contributor
Author
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 provided code snippet appears to be part of a class that checks authentication and performs speech-to-text conversion using the OpenAI API. Here are some observations, potential issues, and recommendations: Observations
Additional Recommendations
Additionally, you can write logs using Python's built-in
By addressing these points, you can enhance the robustness, maintainability, and debuggability of your code. |
||
|
|
||
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.
This code snippet contains some minor issues and can be optimized:
Issues/Improvements:
ifcondition checks both existence of the model in the database (QuerySet(Model).filter(...).exists()) and its type (model.model_type == "LLM"). However, it should only check if the model exists before checking its type. This reduces unnecessary computations.Optimization Suggestions:
2. Use a more efficient way to filter queries using dictionary unpacking where appropriate.
3. If you decide to keep the dual check (both existence and type), ensure that they are done sequentially. Checking the type after already knowing there's one could potentially lead to slower execution time because it still involves retrieving a record from the database even if it doesn't match the desired conditions.
Modified Code:
In the modified version, I removed the unnecessary check for model type after assuming the model exists based on its ID existence. Make sure to adjust logic according to your application requirements regarding handling such cases differently.