-
Notifications
You must be signed in to change notification settings - Fork 22
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
Add Support for Local LLama Models via LlamaCpp Integration #781
base: main
Are you sure you want to change the base?
Add Support for Local LLama Models via LlamaCpp Integration #781
Conversation
No CI runs were found. Sweep can fix CI failures, so we recommend setting it up for your repository to let Sweep run your build and tests. If you think this is an error, check Sweep's permissions at https://github.com/organizations/kyaukyuai/settings/installations/45715441. 📖 For more information on how to use Sweep, please read our documentation. Tracking ID: 27853a050e-ci-0
|
Walkthroughこの変更は、LLamaモデルのローカルサポートを追加するためのものです。新たな環境変数の追加、LLamaモデルの作成と初期化のための関数の更新、そして新たなユニットテストの追加が含まれています。これらの変更は、コードの外部インターフェースや振る舞いに影響を与える可能性があります。 Changes
Uplevel your code reviews with CodeRabbit ProCodeRabbit ProIf you like this project, please support us by purchasing the Pro version. The Pro version has advanced context, superior noise reduction and several proprietary improvements compared to the open source version. Moreover, CodeRabbit Pro is free for open source projects. |
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.
Files selected (3)
- .env.sample (2)
- gpt_all_star/core/llm.py (3)
- tests/core/test_llm.py (3)
Review comments generated (8)
- Review: 5
- LGTM: 3
Tips
Chat with
CodeRabbit Bot (@coderabbitai
)
- Reply on review comments left by this bot to ask follow-up questions. A review comment is a comment on a diff or a file.
- Invite the bot into a review comment chain by tagging
@coderabbitai
in a reply.
Code suggestions
- The bot may make code suggestions, but please review them carefully before committing since the line number ranges may be misaligned.
- You can edit the comment made by the bot and manually tweak the suggestion if it is slightly off.
Pausing incremental reviews
- Add
@coderabbitai: ignore
anywhere in the PR description to pause further reviews from the bot.
from langchain_community.llms import LlamaCpp | ||
from langchain.callbacks.manager import CallbackManager | ||
from langchain.callbacks.streaming_stdout import StreamingStdOutCallbackHandler | ||
|
||
|
||
class LLM_TYPE(str, Enum): | ||
OPENAI = "OPENAI" | ||
AZURE = "AZURE" | ||
ANTHROPIC = "ANTHROPIC" | ||
LLAMA = "LLAMA" |
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.
elif llm_name == LLM_TYPE.LLAMA: | ||
return _create_chat_llama( | ||
model_path=os.getenv("LLAMA_MODEL_PATH"), | ||
temperature=0.1, | ||
n_ctx=int(os.getenv("LLAMA_N_CTX", "2048")), | ||
n_gpu_layers=int(os.getenv("LLAMA_N_GPU_LAYERS", "0")), | ||
) |
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.
def _create_chat_llama( | ||
model_path: str, | ||
temperature: float, | ||
n_ctx: int = 2048, | ||
n_gpu_layers: int = 0, | ||
) -> LlamaCpp: | ||
callback_manager = CallbackManager([StreamingStdOutCallbackHandler()]) | ||
return LlamaCpp( | ||
model_path=model_path, | ||
temperature=temperature, | ||
n_ctx=n_ctx, | ||
n_gpu_layers=n_gpu_layers, | ||
callback_manager=callback_manager, | ||
verbose=True, | ||
) |
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.
@pytest.fixture | ||
def mock_llamacpp(): | ||
with patch("gpt_all_star.core.llm.LlamaCpp") as mock: | ||
yield mock | ||
|
||
|
||
@pytest.fixture | ||
def mock_callback_manager(): | ||
with patch("gpt_all_star.core.llm.CallbackManager") as mock: | ||
yield mock |
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.
def test_create_chat_llama(mock_llamacpp, mock_callback_manager): | ||
model_path = "/path/to/model.gguf" | ||
temperature = 0.1 | ||
n_ctx = 2048 | ||
n_gpu_layers = 0 | ||
|
||
_create_chat_llama( | ||
model_path=model_path, | ||
temperature=temperature, | ||
n_ctx=n_ctx, | ||
n_gpu_layers=n_gpu_layers, | ||
) | ||
|
||
mock_callback_manager.assert_called_once() | ||
mock_llamacpp.assert_called_once_with( | ||
model_path=model_path, | ||
temperature=temperature, | ||
n_ctx=n_ctx, | ||
n_gpu_layers=n_gpu_layers, | ||
callback_manager=mock_callback_manager.return_value, | ||
verbose=True, | ||
) |
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.
Purpose
Extend the GPT All-Star library to support local LLama models using LangChain's LlamaCpp integration, enabling users to run large language models locally without relying on cloud-based API services.
This pull request was created to solve the following GitHub issue:
Add llama3.3 support
Details
Let's add opensource llama model. can you give me a hint so I can try it out
Add Llama 2 LLM Support to Core LLM Module
Description:
Extend the LLM module to support Llama 2 models through LangChain's integration, following the existing pattern for other LLM providers.
Tasks:
In
gpt_all_star/core/llm.py
:LLAMA
toLLM_TYPE
enum_create_chat_llama
helper functioncreate_llm
to handle Llama caseIn
.env.sample
:Test:
tests/core/test_llm.py
:Implementation Notes:
Description
This pull request introduces comprehensive support for local LLama models by:
LLAMA
option to theLLM_TYPE
enum_create_chat_llama()
function to initialize LlamaCpp modelscreate_llm()
function to handle Llama model creation.env.sample
file to include Llama-specific configuration parametersThe implementation allows flexible configuration of Llama models through environment variables, including model path, context size, and GPU layer configuration. This provides users with a seamless way to integrate local, open-source language models into their existing workflows.
Summary
LLM_TYPE.LLAMA
enum option_create_chat_llama()
functioncreate_llm()
to support Llama models.env.sample
with Llama configurationLlamaCpp
from LangChainFixes
Fixes #780. Continue the conversation here: https://app.sweep.dev/c/dca03bf8-dbba-467c-bdc0-8262932c6245.
To have Sweep make further changes, please add a comment to this PR starting with "Sweep:".
📖 For more information on how to use Sweep, please read our documentation.
LLAMA
を選択した場合の設定が可能になります。