-2

I am querying a text using chatGPT. But I need chatGPT to respond with single direct answers, rather than long stories or irrelevant text. Any way to achieve this?

My code looks like:

from langchain.document_loaders import TextLoader
from langchain.vectorstores import DocArrayInMemorySearch
from langchain.indexes import VectorstoreIndexCreator

loader = TextLoader("path/to/extracted_text.txt")
loaded_text = loader.load()
# Save document text as vector.
index = VectorstoreIndexCreator(
            vectorstore_cls=DocArrayInMemorySearch
        ).from_loaders([loader])

# Query the text
response = index.query("At what time did john come home yesterday?")
print("Loaded text is:", loaded_text)
print("ChatGPT response is:", response)

>>> Loaded text is: "< a really long text > + John came home last night at 11:30pm + < a really long text >"

>>> ChatGPT response is: "John came back yesterday at 11:30pm."

The problem is that I want a concise answer 11:30pm rather than a full sentence John came home last night at 11:30pm. Is there a way to achieve this without adding "I need a short direct response" to my query? Can I achieve a more guaranteed concise response by setting a parameter through some other means instead?

trazoM
  • 50
  • 1
  • 8
  • This comes down to prompt engineering and is therefore not programming and therefore off-topic. You need to wait for https://meta.stackexchange.com/questions/390463/starting-the-prompt-design-site-a-new-home-in-our-stack-exchange-neighborhood?cb=1 – luk2302 Jul 12 '23 at 10:45
  • what luk2302 said, but also, asking, "how can I get a generative AI to do a thing without telling it to do the thing" is quite a strange question. ChatGPT can't read your mind – Mark Jul 12 '23 at 10:48
  • Perhaps, that is the reason for the downvotes. The problem is that I do not want to take the prompt engineering route, hence the reason why I have posted this question. I felt perhaps someone would offer an alternative means to let me tune a parameter like the temperature, top_k, set_top_p, etc... Been going through the docs but found nothing yet. @luk2302 – trazoM Jul 12 '23 at 10:51

1 Answers1

0

The ONLY way to achieve what you want is Proper Prompt Engineering. Period. No way around it. It's more of a thought discipline than acquiring a new skill. Read this quick Microsoft Learn doc about prompt engineering to privy yourself to the knowledge you need to advance your task. Best wishes!