#how do i increase output response size?

102 messages · Page 1 of 1 (latest)

sleek thistle
#

are you using gpt-index?

#

that looks like gpt-index code

winged hull
# sleek thistle are you using gpt-index?

yes ```python

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

# 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>"))

#

I am, what does that have to do with the resposne length?

#

using gpt-3.5-turbo-0613 model

sleek thistle
#

service_context = ServiceContext.from_defaults(
llm_predictor=llm_predictor,
chunk_size=1024
)

Output is related with service context configuration.
Please try to remove prompt_helper, and just configure service_context like this.

#

Let me know the update.

#

@winged hull

winged hull
#

Thank you I’ll test it

winged hull
#

@sleek thistle

sleek thistle
#

@winged hull

#

that is because of llama-index version

#

could you please remove current version and install latest version?

winged hull
#
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 = 10000
    # set maximum chunk overlap
    max_chunk_overlap = 20
    # set chunk size limit
    chunk_size_limit = 600 

    # 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)
    service_context = ServiceContext.from_defaults(
            llm_predictor=llm_predictor,
            chunk_size=1024
        )
    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>"))


sleek thistle
#

Please check llama-index version.

#

before I get that issue using low version

winged hull
#

i removed the old version number

#

maybe need to restart kernel sec

winged hull
# sleek thistle Please check llama-index version.
Note: you may need to restart the kernel to use updated packages.
Note: you may need to restart the kernel to use updated packages.
Name: llama-index
Version: 0.5.6
Summary: Interface between LLMs and your data.
Home-page: https://github.com/jerryjliu/gpt_index
Author: 
Author-email: 
License: MIT
Location: /opt/homebrew/lib/python3.11/site-packages
Requires: dataclasses-json, langchain, numpy, openai, pandas, tenacity, tiktoken
Required-by: ``` this ur version?
#

still getting the errror

sleek thistle
#

my llama-index version is 0.6.34

winged hull
#

ok sec

sleek thistle
#

@winged hull , are you using venv, right?

#

I am normally using venv to detect issue of current project, global packages.

#

please reference this. 🙂

winged hull
winged hull
#

i got this error last time

#

this is why we had to downgrade versions

sleek thistle
#

GPTVectorStoreIndex
Please use this

#

GPTSimpleVectorIndex is not working in latest version

winged hull
#

do I replace that with the new library, need to change the construction of it?

sleek thistle
#

just replace to GPTVectorStoreIndex from GPTSimpleVectorIndex

#

GPTSimpleVectorIndex is not working in latest version

winged hull
winged hull
sleek thistle
#

please share me your full code

#

let me update them and return to you.

winged hull
# sleek thistle let me update them and return to you.
%pip -q install langchain==0.0.148 openai
%pip -q install llama_index==0.6.34
!pip show llama_index
from llama_index import SimpleDirectoryReader, GPTListIndex, readers, GPTVectorStoreIndex, 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 = 10000
    # set maximum chunk overlap
    max_chunk_overlap = 20
    # set chunk size limit
    chunk_size_limit = 600 

    # 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)
    service_context = ServiceContext.from_defaults(
            llm_predictor=llm_predictor,
            chunk_size=1024
        )
    index = GPTVectorStoreIndex.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>"))
# os.environ["OPENAI_API_KEY"] = input("Paste your OpenAI key here and hit enter:")
os.environ["OPENAI_API_KEY"] = ""
construct_index("data/")
ask_ai()```
#

this is in a notebook

sleek thistle
#

prompt_helper = PromptHelper(max_input_size, num_outputs, max_chunk_overlap, chunk_size_limit=chunk_size_limit)

#

remove this code

#

also remove PromptHelper from this code.
from llama_index import SimpleDirectoryReader, GPTListIndex, readers, GPTVectorStoreIndex, LLMPredictor, PromptHelper, ServiceContext

#

@winged hull

#

can you try?

winged hull
#

ok sec

#
Cell In[9], line 32, in construct_index(directory_path)
     26 service_context = ServiceContext.from_defaults(
     27         llm_predictor=llm_predictor,
     28         chunk_size=1024
     29     )
     30 index = GPTVectorStoreIndex.from_documents(documents, service_context=service_context)
---> 32 index.save_to_disk('index.json')
     34 return index

AttributeError: 'VectorStoreIndex' object has no attribute 'save_to_disk'```
winged hull
sleek thistle
#

yes, save_to_disk function is not working in latest version

#

storage_context = StorageContext.from_defaults()
storage_context.persist(persist_dir="Directory to save")

#

so, please add StorageContext.

from llama_index import SimpleDirectoryReader, GPTListIndex, readers, GPTVectorStoreIndex, LLMPredictor, PromptHelper, ServiceContext

#

storage_context = StorageContext.from_defaults()
storage_context.persist(persist_dir="Directory to save")

and define storage_context like this

winged hull
#

Storagecontext not defined

sleek thistle
#

from llama_index import SimpleDirectoryReader, GPTListIndex, readers, GPTVectorStoreIndex, LLMPredictor, PromptHelper, ServiceContext, StorageContext

#

you still didn't add StorageContext

winged hull
# sleek thistle use this code
Cell In[21], line 36, in construct_index(directory_path)
     30 service_context = ServiceContext.from_defaults(
     31         llm_predictor=llm_predictor,
     32         chunk_size=1024
     33     )
     34 index = GPTVectorStoreIndex.from_documents(documents, service_context=service_context)
---> 36 index.save_to_disk('index.json')
     38 return index

AttributeError: 'VectorStoreIndex' object has no attribute 'save_to_disk'```
#

that fixed that, now this error

sleek thistle
#

Please remove index.save_to_disk('index.json')

#

storage_context = StorageContext.from_defaults()
storage_context.persist(persist_dir="Directory to save")

And add this below service_context

winged hull
#
---------------------------------------------------------------------------
NameError                                 Traceback (most recent call last)
Cell In[32], line 1
----> 1 ask_ai()

Cell In[29], line 41, in ask_ai()
     40 def ask_ai():
---> 41     index = GPTSimpleVectorIndex.load_from_disk('index.json')
     42     while True: 
     43         query = input("What do you want to ask? ")

NameError: name 'GPTSimpleVectorIndex' is not defined```
sleek thistle
#

yes, need to update those part as well

winged hull
#

ok sec

#

def ask_ai():
index = GPTVectorStoreIndex.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>"))

sleek thistle
#

storage_context = StorageContext.from_defaults(persist_dir="Directory of JSON")
index = load_index_from_storage(storage_context,service_context=service_context)

#

storage_context = StorageContext.from_defaults(persist_dir="Directory of JSON")
index = load_index_from_storage(storage_context,service_context=service_context)

#

update using this

winged hull
#

like this?

sleek thistle
#

def ask_ai():
storage_context = StorageContext.from_defaults(persist_dir="Directory of JSON")
index = load_index_from_storage(storage_context,service_context=service_context)
while True:
query = input("What do you want to ask? ")
response = index.query(query)
display(Markdown(f"Response: <b>{response.response}</b>"))

#

like this

#

yes, but need to do following things

#

import load_index_from_storage

#

and define service_context in ask_ai function

winged hull
#
from llama_index import SimpleDirectoryReader, GPTListIndex, readers, GPTVectorStoreIndex, LLMPredictor, PromptHelper, ServiceContext, StorageContext
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 = 10000
    # set maximum chunk overlap
    max_chunk_overlap = 20
    # set chunk size limit
    chunk_size_limit = 600 

    # 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()
    

    # storage_context = StorageContext.from_defaults()
    # storage_context.persist(persist_dir="/Users/og/Downloads/RozGPT-main")

    # service_context = ServiceContext.from_defaults(llm_predictor=llm_predictor, prompt_helper=prompt_helper)
    service_context = ServiceContext.from_defaults(
            llm_predictor=llm_predictor,
            chunk_size=1024
        )
    index = GPTVectorStoreIndex.from_documents(documents, service_context=service_context)

    storage_context = StorageContext.from_defaults()
    storage_context.persist(persist_dir="/Users/og/Downloads/GPT-main")
    # index.save_to_disk('index.json')

    return index

def ask_ai():
    storage_context = StorageContext.from_defaults(persist_dir="index.json")
    index = load_index_from_storage(storage_context,service_context=service_context)
    while True: 
        query = input("What do you want to ask? ")
        response = index.query(query)
        display(Markdown(f"Response: <b>{response.response}</b>"))```
#

is this right? It giving errors

sleek thistle
#

from llama_index import SimpleDirectoryReader, GPTListIndex, readers, GPTVectorStoreIndex, LLMPredictor, PromptHelper, ServiceContext, StorageContext, load_index_from_storage

winged hull
#
Cell In[52], line 1
----> 1 ask_ai()

Cell In[49], line 43, in ask_ai()
     42 def ask_ai():
---> 43     storage_context = StorageContext.from_defaults(persist_dir="index.json")
     44     index = load_index_from_storage(storage_context,service_context=service_context)
     45     while True: 

File /opt/homebrew/lib/python3.11/site-packages/llama_index/storage/storage_context.py:75, in StorageContext.from_defaults(cls, docstore, index_store, vector_store, graph_store, persist_dir, fs)
     73     graph_store = graph_store or SimpleGraphStore()
     74 else:
---> 75     docstore = docstore or SimpleDocumentStore.from_persist_dir(
     76         persist_dir, fs=fs
     77     )
     78     index_store = index_store or SimpleIndexStore.from_persist_dir(
     79         persist_dir, fs=fs
     80     )
     81     vector_store = vector_store or SimpleVectorStore.from_persist_dir(
     82         persist_dir, fs=fs
     83     )

File /opt/homebrew/lib/python3.11/site-packages/llama_index/storage/docstore/simple_docstore.py:57, in SimpleDocumentStore.from_persist_dir(cls, persist_dir, namespace, fs)
...
--> 319         self.f = open(self.path, mode=self.mode)
    320         if self.compression:
    321             compress = compr[self.compression]

NotADirectoryError: [Errno 20] Not a directory: '/Users/og/Downloads/GPT-main/index.json/docstore.json'
sleek thistle
#

and define service_context in ask_ai function

#

you are using that without define

#

@winged hull

winged hull
#
Cell In[57], line 1
----> 1 ask_ai()

Cell In[54], line 44, in ask_ai()
     42 def ask_ai():
     43     service_context = ServiceContext.from_defaults(
---> 44             llm_predictor=llm_predictor,
     45             chunk_size=1024
     46         )
     47     storage_context = StorageContext.from_defaults(persist_dir="index.json")
     48     index = load_index_from_storage(storage_context,service_context=service_context)

NameError: name 'llm_predictor' is not defined```
sleek thistle
#

persist_dir is where json file exist

#

also need to define llm_predictor

#

you are using that without define

#

hehe

#

hehe

winged hull
#

so all this needs to go in ask_ai?

sleek thistle
#

it seems that you are not familiar with python, friend

winged hull
#

I am lol

sleek thistle
#

lol, I guess you are not familiar with that.

#

I can fix that script today for you.

#

just need to set up env for you.

winged hull
#

hmm I defined it outside the scope to try and rig it, still doesn't like it