Skip to content

armgit / dspy

Public Imported from GitHub
0

DSPy: The framework for programming—not prompting—language models

Python

Removed import position

Abdul Dridi74ec6afd00c8
diff --git a/dsp/modules/llama.py b/dsp/modules/llama.py
index e1a920eac..33ff3bb5f 100644
--- a/dsp/modules/llama.py
+++ b/dsp/modules/llama.py
@@ -1,30 +1,28 @@
-try:
- import llama_cpp
- from llama_cpp import Llama
-except ImportError as exc:
- raise ModuleNotFoundError(
- """You need to install llama_cpp library to use gguf models.
- CPU - pip install llama-cpp-python
- CUDA - pip install llama-cpp-python --extra-index-url https://abetlen.github.io/llama-cpp-python/whl/<cuda-version> e.g. cu121 for CUDA 12.1
- METAL(Mac) - pip install llama-cpp-python --extra-index-url https://abetlen.github.io/llama-cpp-python/whl/metal
- others: https://pypi.org/project/llama-cpp-python/""",
- ) from exc
-
from typing import Any, Literal
-
from dsp.modules.lm import LM
-
class LlamaCpp(LM):
def __init__(
self,
model: str, # "llama" or the actual model name
- llama_model: Llama,
+ llama_model: Any = None,
model_type: Literal["chat", "text"] = None,
**kwargs,
):
super().__init__(model)
+ try:
+ import llama_cpp
+ from llama_cpp import Llama
+ except ImportError as exc:
+ raise ModuleNotFoundError(
+ """You need to install the llama_cpp library to use gguf models.
+ CPU - pip install llama-cpp-python
+ CUDA - pip install llama-cpp-python --extra-index-url https://abetlen.github.io/llama-cpp-python/whl/<cuda-version> e.g. cu121 for CUDA 12.1
+ METAL(Mac) - pip install llama-cpp-python --extra-index-url https://abetlen.github.io/llama-cpp-python/whl/metal
+ others: https://pypi.org/project/llama-cpp-python/""",
+ ) from exc
+
default_model_type = "text"
self.model_type = model_type if model_type else default_model_type
self.provider = "llama"
diff --git a/pyproject.toml b/pyproject.toml
index 26f4d2694..9afb45e5e 100644
--- a/pyproject.toml
+++ b/pyproject.toml
@@ -126,7 +126,6 @@ pgvector = { version = "^0.2.5", optional = true }
structlog = "^24.1.0"
llama-index = {version = "^0.10.30", optional = true}
snowflake-snowpark-python = { version = "*",optional=true, python = ">=3.9,<3.12" }
-llama-cpp-python = { version = "^0.2.82", optional = true }
jinja2 = "^3.1.3"