Find answers from the community

Updated 3 months ago

Does anyone know why response is none

Does anyone know why response is none?
Plain Text
import os
from flask import Flask, request
from langchain.chat_models import ChatOpenAI
from llama_index import GPTKeywordTableIndex, LLMPredictor, ServiceContext, SimpleDirectoryReader

os.environ["OPENAI_API_KEY"] = "MY KEY HERE"

app = Flask(__name__)

documents = SimpleDirectoryReader("C:\\temp\\Test").load_data()
llm_predictor = LLMPredictor(llm=ChatOpenAI(temperature=0, model_name='gpt-3.5-turbo'))
service_context = ServiceContext.from_defaults(llm_predictor=llm_predictor)
index = GPTKeywordTableIndex.from_documents(documents, service_context=service_context)

@app.route("/query", methods=["GET"])
def query():
    query_text = request.args.get("text", None)
    response = index.query(query_text)
    return str(response), 200
L
J
9 comments
is the query endpoint actually getting the text? Try printing query_text before running the query
It is πŸ™‚
πŸ€” and the index actually has documents in it? You could also try print(len(documents)) before building the index

(just trying to narrow down the problem lol)
It's a keyword index
I thiiiiink if they query text does not have any keywords that are in the keyword table, then it won't really return anything
There are documents, but will it only return something if there's a keyword match?
Exactly! Otherwise, it won't know which documents to pick
There are other index types though (vector, list, etc.)
Add a reply
Sign up and join the conversation on Discord