Find answers from the community

S
Sam W
Offline, last seen 3 months ago
Joined September 25, 2024
S
Sam W
·

```python

Plain Text
%pip -q install langchain==0.0.148 openai
%pip -q install llama_index==0.5.6

from llama_index import SimpleDirectoryReader, GPTListIndex, readers, GPTSimpleVectorIndex, LLMPredictor, PromptHelper, ServiceContext
from langchain import OpenAI
import sys
import os
from IPython.display import Markdown, display

def construct_index(directory_path):
    # set maximum input size
    max_input_size = 4096
    # set number of output tokens
    num_outputs = 30000
    # set maximum chunk overlap
    max_chunk_overlap = 60
    # set chunk size limit
    chunk_size_limit = 6024 

    # define prompt helper
    prompt_helper = PromptHelper(max_input_size, num_outputs, max_chunk_overlap, chunk_size_limit=chunk_size_limit)

    # define LLM
    llm_predictor = LLMPredictor(llm=OpenAI(temperature=0.5, model_name="gpt-3.5-turbo-0613", max_tokens=num_outputs))
 
    documents = SimpleDirectoryReader(directory_path).load_data()
    
    service_context = ServiceContext.from_defaults(llm_predictor=llm_predictor, prompt_helper=prompt_helper)
    index = GPTSimpleVectorIndex.from_documents(documents, service_context=service_context)

    index.save_to_disk('index.json')

    return index

def ask_ai():
    index = GPTSimpleVectorIndex.load_from_disk('index.json')
    while True: 
        query = input("What do you want to ask? ")
        response = index.query(query)
        display(Markdown(f"Response: <b>{response.response}</b>"))
construct_index("data/")
ask_ai()
Hey guys I can't increase my response length, what am I doing wrong? As u can see I increased the outputs and chunks and everything and no matter what I do it doesn't increase my output
38 comments
S
L