-
Notifications
You must be signed in to change notification settings - Fork 1.2k
local llm #357
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
base: main
Are you sure you want to change the base?
local llm #357
Conversation
Signed-off-by: Wang, Xiaotong <[email protected]>
Summary of ChangesHello @xiaoton1, 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 advances the system's ability to leverage local Large Language Models and embedding services by integrating Ollama and reconfiguring the OpenAI client to point to a local endpoint. It also expands the range of supported generative models with the addition of "claude-3.7-sonnet" and enhances API robustness by making model parameters conditional. A minor frontend dependency update is also included. Highlights
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Code Review
This pull request introduces support for local LLMs, primarily by adding configurations for Ollama and adjusting the OpenAI client to point to a local endpoint. The changes are a good step towards local model support, but there are a few critical issues to address. Specifically, a private IP address has been hardcoded in the OpenAIClient
, which is a security and portability risk. Additionally, there's a direct manipulation of sys.path
which is considered bad practice in Python. I've also included a refactoring suggestion to improve code clarity in the WebSocket handler. Addressing these points will make the implementation more robust, secure, and maintainable.
self._env_api_key_name = env_api_key_name | ||
self._env_base_url_name = env_base_url_name | ||
self.base_url = base_url or os.getenv(self._env_base_url_name, "https://api.openai.com/v1") | ||
self.base_url = base_url or os.getenv(self._env_base_url_name, "http://10.239.142.219:8012/") |
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.
Hardcoding a private IP address as a default value is a critical issue. It makes the application non-portable, difficult to configure for other developers or deployment environments, and leaks internal network details. It's much better to use a generic, safe default like localhost
or not provide a default at all, forcing the configuration via the OPENAI_BASE_URL
environment variable. This ensures the application is secure and easy to set up in any environment.
self.base_url = base_url or os.getenv(self._env_base_url_name, "http://10.239.142.219:8012/") | |
self.base_url = base_url or os.getenv(self._env_base_url_name, "http://localhost:8012/") |
import logging | ||
from dotenv import load_dotenv | ||
|
||
sys.path.insert(0, os.path.normpath(os.path.join(os.path.dirname(os.path.abspath(__file__)), ".."))) |
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.
Manipulating sys.path
directly is generally discouraged as it can make dependency management fragile and code harder to understand. It can lead to issues with module resolution, especially in larger projects or when deployed in different environments. A better approach is to structure your project as a proper Python package and use relative imports, or to install it in editable mode (pip install -e .
) for development. This ensures that imports are explicit and reliable.
model_kwargs = { | ||
"model": request.model, | ||
"stream": True, | ||
"temperature": model_config["temperature"] | ||
#"temperature": model_config["temperature"] | ||
} | ||
if "temperature" in model_config: | ||
model_kwargs["temperature"] = model_config["temperature"] |
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.
While the logic to conditionally add temperature
is correct, the implementation leaves a commented-out line of code. This can be confusing for future maintainers. It's cleaner to initialize the dictionary with common parameters and then conditionally add optional ones. This improves readability and maintainability.
model_kwargs = { | |
"model": request.model, | |
"stream": True, | |
"temperature": model_config["temperature"] | |
#"temperature": model_config["temperature"] | |
} | |
if "temperature" in model_config: | |
model_kwargs["temperature"] = model_config["temperature"] | |
model_kwargs = { | |
"model": request.model, | |
"stream": True, | |
} | |
if "temperature" in model_config: | |
model_kwargs["temperature"] = model_config["temperature"] |
Signed-off-by: Wang, Xiaotong [email protected]