llama_index icon indicating copy to clipboard operation
llama_index copied to clipboard

How to log prompt?

Open lcswillems opened this issue 2 years ago • 3 comments

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.

lcswillems avatar Feb 10 '23 13:02 lcswillems

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

PandaWhoCodes avatar Feb 10 '23 19:02 PandaWhoCodes

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

jerryjliu avatar Feb 11 '23 13:02 jerryjliu

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 avatar Feb 19 '23 10:02 lightondust

@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

jerryjliu avatar Feb 20 '23 19:02 jerryjliu

Set the environment variable OPENAI_LOG=debug and you'll see everything logged.

jkp avatar Feb 23 '23 22:02 jkp

The above didn't work for me, but this one did:

import logging

logging.getLogger().setLevel(logging.DEBUG)

mommi84 avatar Mar 06 '23 13:03 mommi84