#how do i increase output response size?
102 messages · Page 1 of 1 (latest)
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
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
Thank you I’ll test it
@winged hull
that is because of llama-index version
could you please remove current version and install latest version?
I did, still same error
'
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>"))
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
my llama-index version is 0.6.34
ok sec
@winged hull , are you using venv, right?
I am normally using venv to detect issue of current project, global packages.
please reference this. 🙂
I'm in a notebook
i got this error last time
this is why we had to downgrade versions
GPTVectorStoreIndex
Please use this
GPTSimpleVectorIndex is not working in latest version
just replace to GPTVectorStoreIndex from GPTSimpleVectorIndex
GPTSimpleVectorIndex is not working in latest version
ok now this is giving the error we had last time
%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
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?
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'```
getting this error now
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
Storagecontext not defined
from llama_index import SimpleDirectoryReader, GPTListIndex, readers, GPTVectorStoreIndex, LLMPredictor, PromptHelper, ServiceContext, StorageContext
you still didn't add StorageContext
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
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
---------------------------------------------------------------------------
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```
yes, need to update those part as well
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>"))
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
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
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
you can import that from llama-index
from llama_index import SimpleDirectoryReader, GPTListIndex, readers, GPTVectorStoreIndex, LLMPredictor, PromptHelper, ServiceContext, StorageContext, load_index_from_storage
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'
and define service_context in ask_ai function
you are using that without define
@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```
persist_dir is where json file exist
also need to define llm_predictor
you are using that without define
hehe
hehe
so all this needs to go in ask_ai?
it seems that you are not familiar with python, friend
I am lol
Yes
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.
hmm I defined it outside the scope to try and rig it, still doesn't like it