Skip to content

Commit

Permalink
import llama_index gracefully, solves #318 (#319)
Browse files Browse the repository at this point in the history
I added informative message for import errors regarding llama_index, and
changed the existing messages to match each other.
  • Loading branch information
ceferisbarov authored Nov 21, 2023
1 parent 13465f0 commit 1cfbaa1
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 6 deletions.
2 changes: 1 addition & 1 deletion src/ragas/llama_index/evaluation.py
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ def evaluate(
except ImportError:
raise ImportError(
"llama_index must be installed to use this function. "
"Install it with `pip install llama_index`."
"Please, install it with `pip install llama_index`."
)

# TODO: rate limit, error handling, retries
Expand Down
8 changes: 7 additions & 1 deletion src/ragas/llms/llamaindex.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,13 @@
if t.TYPE_CHECKING:
from langchain.callbacks.base import Callbacks
from langchain.prompts import ChatPromptTemplate
from llama_index.llms.base import LLM as LiLLM
try:
from llama_index.llms.base import LLM as LiLLM
except ImportError:
raise ImportError(
"llama_index must be installed to use this function. "
"Please, install it with `pip install llama_index`."
)


class LlamaIndexLLM(RagasLLM):
Expand Down
15 changes: 11 additions & 4 deletions src/ragas/testset/testset_generator.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,17 +5,24 @@
from collections import defaultdict, namedtuple
from dataclasses import dataclass

try:
from llama_index.indices.query.embedding_utils import get_top_k_embeddings
from llama_index.node_parser import SimpleNodeParser
from llama_index.readers.schema import Document as LlamaindexDocument
from llama_index.schema import BaseNode
except ImportError:
raise ImportError(
"llama_index must be installed to use this function. "
"Please, install it with `pip install llama_index`."
)

import numpy as np
import numpy.testing as npt
import pandas as pd
from langchain.embeddings import OpenAIEmbeddings
from langchain.embeddings.base import Embeddings
from langchain.prompts import ChatPromptTemplate
from langchain.schema.document import Document as LangchainDocument
from llama_index.indices.query.embedding_utils import get_top_k_embeddings
from llama_index.node_parser import SimpleNodeParser
from llama_index.readers.schema import Document as LlamaindexDocument
from llama_index.schema import BaseNode
from numpy.random import default_rng
from tqdm import tqdm

Expand Down

0 comments on commit 1cfbaa1

Please sign in to comment.