Settings
object. Here's an example of how to do it using the OpenAI LLM:from llama_index.llms.openai import OpenAI from llama_index.core import Settings Settings.llm = OpenAI(temperature=0.2, model="gpt-4")
OpenAI
with your choice of LLM and adjust the parameters as needed.Settings
, it will be used in the subsequent stages of your pipeline, including the RetrieverQueryEngine
and response_synthesizer
.from llama_index.llms.openai import OpenAI from llama_index.core import Settings # Specify your choice of LLM Settings.llm = OpenAI(temperature=0.2, model="gpt-4") vector_store = PineconeVectorStore(pinecone_index=pinecone_index, add_sparse_vector=True) pinecone_vectorstore_index = VectorStoreIndex.from_vector_store(vector_store = vector_store) print('case id', request.case_id) retriever = pinecone_vectorstore_index.as_retriever( vector_store_kwargs={"filter": {"case_id": request.case_id}} ) response_synthesizer = get_response_synthesizer(response_mode="refine") query_engine = RetrieverQueryEngine( retriever=retriever, response_synthesizer=response_synthesizer ) query_engine.update_prompts( {"response_synthesizer:text_qa_template": custom_prompt} ) response = query_engine.query(request.query) return {"response": response.response}
SimpleDirectoryReader
or S3Reader
provided by LlamaIndex. Here's a step-by-step guide on how to do it:S3FileSystem
and then use it with SimpleDirectoryReader
to load documents from an S3 bucket.from s3fs import S3FileSystem from llama_index.readers import SimpleDirectoryReader s3_fs = S3FileSystem(anon=False, endpoint_url=endpoint_url) reader = SimpleDirectoryReader( input_dir=bucket_name, fs=s3_fs, recursive=True, # recursively searches all subdirectories ) docs = reader.load_data() print(f"Loaded {len(docs)} docs")
bucket_name
is the name of your S3 bucket and endpoint_url
is the URL of your S3 endpoint. The load_data()
method loads the documents from the S3 bucket (source ()).S3Reader
class in LlamaIndex, which is specifically designed for reading data from S3. Here's an example:from llama_index.readers.s3 import S3Reader reader = S3Reader( aws_access_id=aws_access_id, aws_access_secret=aws_access_secret, s3_endpoint_url=s3_endpoint_url, bucket=bucket_name, ) docs = reader.load_data()
aws_access_id
and aws_access_secret
are your AWS credentials, s3_endpoint_url
is the URL of your S3 endpoint, and bucket_name
is the name of your S3 bucket. The load_data()
method loads the documents from the S3 bucket (source ()).bucket
field is required when creating an instance of S3Reader
. This field should contain the name of your S3 bucket.from llama_index.readers.s3 import S3Reader reader = S3Reader( aws_access_id=aws_access_id, aws_access_secret=aws_access_secret, s3_endpoint_url=s3_endpoint_url, bucket='your_bucket_name', # replace with your actual bucket name )
'your_bucket_name'
with the name of your S3 bucket. Also, replace aws_access_id
, aws_access_secret
, and s3_endpoint_url
with your actual AWS credentials and S3 endpoint URL.S3Reader
class provided by LlamaIndex. Here's how you can do it:from llama_index.readers.s3 import S3Reader reader = S3Reader( aws_access_id='your_aws_access_id', # replace with your actual AWS access id aws_access_secret='your_aws_access_secret', # replace with your actual AWS access secret s3_endpoint_url='your_s3_endpoint_url', # replace with your actual S3 endpoint URL bucket='your_bucket_name', # replace with your actual bucket name ) docs = reader.load_s3_files_as_docs()
'your_aws_access_id'
, 'your_aws_access_secret'
, 'your_s3_endpoint_url'
, and 'your_bucket_name'
with your actual AWS credentials, S3 endpoint URL, and bucket name. The load_s3_files_as_docs()
method loads the documents from the S3 bucket.