[Python] Get chatGPT to respond with a single direct answer

Discussão em 'Python' iniciado por Stack, Setembro 27, 2024.

  1. Stack

    Stack Membro Participativo

    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?

    Continue reading...

Compartilhe esta Página