Skip to content
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

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

sweep-ai[bot]
Copy link
Contributor

@sweep-ai sweep-ai bot commented Dec 22, 2024

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:

  1. In gpt_all_star/core/llm.py:

    • Add LLAMA to LLM_TYPE enum
    • Create new _create_chat_llama helper function
    • Update create_llm to handle Llama case
  2. In .env.sample:

    • Add Llama-specific environment variables section
    • Include model path and parameters

Test:

  1. In tests/core/test_llm.py:
    • Add test case for Llama LLM creation
    • Mock Llama model initialization
    • Test configuration parameters

Implementation Notes:

  • Follow existing pattern of other LLM implementations
  • Use LangChain's Llama integration
  • Maintain consistent temperature and streaming settings
  • Support model path configuration via environment variables

Description

This pull request introduces comprehensive support for local LLama models by:

  • Adding a new LLAMA option to the LLM_TYPE enum
  • Creating a new _create_chat_llama() function to initialize LlamaCpp models
  • Updating the create_llm() function to handle Llama model creation
  • Modifying the .env.sample file to include Llama-specific configuration parameters
  • Adding unit tests to validate the new Llama model creation functionality

The 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

  • Added support for local LLama models
  • Introduced new LLM_TYPE.LLAMA enum option
  • Created _create_chat_llama() function
  • Updated create_llm() to support Llama models
  • Modified .env.sample with Llama configuration
  • Added unit tests for Llama model creation
  • Integrated LlamaCpp from LangChain
  • Implemented streaming callback support

Fixes

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.

Tracking ID: 27853a050e
### Summary by CodeRabbit
  • 新機能: LLamaモデルのローカルサポートを追加しました。これにより、エンドポイントとしてLLAMAを選択した場合の設定が可能になります。
  • 新機能: LLamaモデルの作成と初期化のための関数を更新しました。これにより、LLamaモデルのパス、コンテキストサイズ、GPUレイヤーの設定が可能になります。
  • テスト: LLamaモデル作成機能の検証のために新たなユニットテストを追加しました。これにより、LLamaモデルの正確な動作が保証されます。

Copy link
Contributor Author

sweep-ai bot commented Dec 22, 2024

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

Copy link

github-actions bot commented Dec 22, 2024

Image description CodeRabbit

Walkthrough

この変更は、LLamaモデルのローカルサポートを追加するためのものです。新たな環境変数の追加、LLamaモデルの作成と初期化のための関数の更新、そして新たなユニットテストの追加が含まれています。これらの変更は、コードの外部インターフェースや振る舞いに影響を与える可能性があります。

Changes

ファイル 変更の概要
.env.sample, gpt_all_star/core/llm.py, tests/core/test_llm.py LLamaモデルのローカルサポートを追加。新たな環境変数を.env.sampleに追加し、LLamaモデルの作成と初期化のための関数をgpt_all_star/core/llm.pyに追加。新たなユニットテストをtests/core/test_llm.pyに追加。

🐇💻

コードの海を泳ぎ、

新たな機能を追い求めて。

LLamaモデルの力を借り、

我々の旅はさらに進む。

🎉🚀


Uplevel your code reviews with CodeRabbit Pro

CodeRabbit Pro

If 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.

Copy link

@github-actions github-actions bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Image description CodeRabbit

Commits Files that changed from the base of the PR and between 91616ca and 3475bf7 commits.
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 Image description 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.

Comment on lines +8 to +17
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"

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Image description CodeRabbit

新たにLlamaCppのインポートとLLM_TYPE列挙型にLLAMAオプションを追加しています。これにより、LLamaモデルのサポートが追加されます。

Comment on lines +44 to +50
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")),
)

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Image description CodeRabbit

create_llm()関数が更新され、LLM_TYPE.LLAMAの場合に_create_chat_llama()関数を呼び出すようになりました。これにより、LLamaモデルの作成が可能になります。

Comment on lines +99 to +113
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,
)

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Image description CodeRabbit

新たに_create_chat_llama()関数が作成されました。この関数は、LLamaモデルの初期化を行い、LlamaCppインスタンスを返します。

Comment on lines +20 to +29
@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

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Image description CodeRabbit

新たにmock_llamacppmock_callback_managerという2つのfixtureが追加されています。これらは、LlamaCppCallbackManagerのモックを作成し、テストで使用します。問題はありません。

Comment on lines +57 to +78
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,
)

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Image description CodeRabbit

新たにtest_create_chat_llamaというテスト関数が追加されています。この関数では、_create_chat_llama関数が期待通りに動作するかを検証しています。具体的には、LlamaCppCallbackManagerが適切に呼び出され、正しいパラメータで初期化されることを確認しています。問題はありません。

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Sweep: Add llama3.3 support
0 participants