Find answers from the community

3
3bs
Offline, last seen 4 months ago
Joined September 25, 2024

def create_index(path):
max_input = 4096
tokens = 512
chunk_size = 600
max_chunk_overlap = 0.2
promptHelper = PromptHelper(max_input, tokens, max_chunk_overlap, chunk_size_limit=chunk_size)

# Define LLm
llmPredictor = LLMPredictor(llm=OpenAI(temperature=0, model_name="text-davinci-003", max_tokens=tokens))

# Load data
docs = SimpleDirectoryReader(path).load_data()

# Create vector index
service_context = ServiceContext.from_defaults(llm_predictor=llmPredictor, prompt_helper=promptHelper)

vectorIndex = GPTVectorStoreIndex.from_documents(documents=docs, service_context=service_context)
vectorIndex.storage_context.persist(persist_dir='index_store')
return vectorIndex

def answerMe(question):

storage_context = StorageContext.from_defaults(persist_dir='index_store')
index = load_index_from_storage(storage_context)
query_engine = index.as_query_engine(response_mode='refine')
for sent in rewriting:
if sent in question :
qq = "Write a lengthy response to this query"
response = query_engine.query(qq + '\n\n'+ question)
return response
response = query_engine.query(question)
for phrase in phrases:
if phrase in str(response) :
content =agent({"input": question})
actualcontent = content['output']
response = re.sub(r'(.?)', r'<a href="\2" target="_blank">\1</a>', actualcontent)

return response

how to costume this to organize the response and outputs in a good shape not just as a paragraph having no static schema or anything
8 comments
3
k

max_input = 4096
tokens = 512
chunk_size = 600
max_chunk_overlap = 0.2
promptHelper = PromptHelper(max_input, tokens, max_chunk_overlap, chunk_size_limit=chunk_size)

# Define LLm
llmPredictor = LLMPredictor(llm=OpenAI(temperature=0, model_name="text-davinci-003", max_tokens=tokens))

# Load data
docs = SimpleDirectoryReader(path).load_data()

# Create vector index
service_context = ServiceContext.from_defaults(llm_predictor=llmPredictor, prompt_helper=promptHelper)

vectorIndex = GPTVectorStoreIndex.from_documents(documents=docs, service_context=service_context)
vectorIndex.storage_context.persist(persist_dir='index_store')
return vectorIndex
query_engine = index.as_query_engine(response_mode='refine')

here what could be the maximum reponse size
25 comments
k
3
L
how to use llama index for rewriting
20 comments
k
3
how the query engine decides if it find response from llama index or not
def create_index(path):
max_input = 4096
tokens = 512
chunk_size = 600
max_chunk_overlap = 0.2
promptHelper = PromptHelper(max_input, tokens, max_chunk_overlap, chunk_size_limit=chunk_size)

# Define LLm
llmPredictor = LLMPredictor(llm=OpenAI(temperature=0, model_name="text-davinci-003", max_tokens=tokens))

# Load data
docs = SimpleDirectoryReader(path).load_data()

# Create vector index
service_context = ServiceContext.from_defaults(llm_predictor=llmPredictor, prompt_helper=promptHelper)

vectorIndex = GPTVectorStoreIndex.from_documents(documents=docs, service_context=service_context)
vectorIndex.storage_context.persist(persist_dir='index_store')
return vectorIndex


def answerMe(question):
storage_context = StorageContext.from_defaults(persist_dir='index_store')
index = load_index_from_storage(storage_context)
query_engine = index.as_query_engine(streaming=True,retriever=True ,verbose=True)
response = query_engine.query(question)
print(query_engine.query(question).print_response_stream())
# i want to check something weather the query engine find a response to just return it if not i want tot do smth else >>(what should i check)
return response
15 comments
L
3