llama_index
llama_index copied to clipboard
How to log prompt?
I am doing an AI that takes as input a set of .md file and a question and tries to answer the question. I have a code like this:
from gpt_index import GPTSimpleVectorIndex, SimpleDirectoryReader
documents = SimpleDirectoryReader("docs").load_data()
index = GPTSimpleVectorIndex(documents)
response = index.query(question)
How to log the prompt that is given to GPT? In particular, I want to check that GPT receives the correct context.
You can probably log the full prompt args after it has been formatted by langchain
https://github.com/jerryjliu/gpt_index/blob/aa0092a14420a75e2e4251a2bd8aa1d5f9c28e29/gpt_index/langchain_helpers/chain_wrapper.py#L97
if you set the logging level to debug, you'll be able to trace the calls logged to openai https://gpt-index.readthedocs.io/en/latest/getting_started/starter_example.html#viewing-queries-and-events-using-logging
if you set the logging level to debug, you'll be able to trace the calls logged to openai https://gpt-index.readthedocs.io/en/latest/getting_started/starter_example.html#viewing-queries-and-events-using-logging
Thanks, that helps.
But it seems that the code only works in jupyter notebooks
import logging
import sys
logging.basicConfig(stream=sys.stdout, level=logging.DEBUG)
logging.getLogger().addHandler(logging.StreamHandler(stream=sys.stdout))
If I run the code in a .py file, nothing logged, any idea about the reason?
@lightondust not sure what your setup is, but maybe try https://stackoverflow.com/questions/13733552/logger-configuration-to-log-to-file-and-print-to-stdout
Set the environment variable OPENAI_LOG=debug and you'll see everything logged.
The above didn't work for me, but this one did:
import logging
logging.getLogger().setLevel(logging.DEBUG)