GithubHelp home page GithubHelp logo

Comments (5)

doberst avatar doberst commented on May 14, 2024 1

Ok - got it! :). We have replicated the error. The script works fine with the .add.source_document method if the filter is the original script "base salary" - but if you replace with "diseases" then it is returning an empty source - e.g.,source - {'text_batch': [], 'metadata_batch': [], 'batches_count': 0} since the word "diseases" is not found in the parsed text. When .prompt_with_source hits this empty source, it throws the error as the intention is that there will be a non-empty context passage included in the prompt. Two work-arounds:

  1. In the script, you could add a check for an empty source, and then not prompt, e.g., "No evidence found to support the question." You can print out the sources output and you will see the dictionary above, with sources["text_batch"] as empty and/or

  2. We will take a look at better exception handling of this case in the prompt_with_source method so that it is not necessarily breaking ... if you have a specific recommendation on the behavior you would prefer, let us know.

Appreciate you raising this issue. Let us know if this works for you.

from llmware.

doberst avatar doberst commented on May 14, 2024

please try the method: ".add_source_document" which takes as input a file_path, and a file_name, and then parses the document and attaches to the prompt. We will update the exception too. Please let us know if that fixes the issue.

from llmware.

doberst avatar doberst commented on May 14, 2024

Sorry, responded too quickly - let me go thru the script too - and see if we can replicate the error

from llmware.

shneeba avatar shneeba commented on May 14, 2024

This is something I've noticed as well and I've implemented a rudimentary check in my script if no text is found:

    # Attempt to attach the document as a source
    try:
        prompter.add_source_document(file_path, local_file, query=user_query)
    except Exception as e:
        print(f"Error adding source document: {e}")
        return

    # Run the inference
    try:
        response = prompter.prompt_with_source(prompt=user_prompt)
    except Exception as e:
        print(f"Error during prompting: {e}")
        return

    # Check if response is empty or not in expected format
    if not response or 'llm_response' not in response[0] or not response[0]['llm_response'].strip():
        print("No text found, try a different query")
    else:
        # Display the response
        response_display = response[0]["llm_response"]
        print(f"- Context: {local_file}\n- Prompt: {user_prompt}\n- LLM Response:\n{response_display}")

    # Clear the source materials after use
    prompter.clear_source_materials()

This gives you a result like so:

stdout: Starting prompt with sources using model: gpt-4-1106-preview
- Context: CBP-7692.pdf
- Prompt: What is a referendum
- LLM Response:
A referendum is a process or principle of referring an important political question, such as a proposed constitutional change, to be decided by a general vote of the entire electorate; a vote taken by referendum.

stderr: 
stdout: Starting prompt with sources using model: gpt-4-1106-preview
No text found, try a different query

stderr: ERROR:root:error:  to use prompt_with_source, there must be a loaded source - try '.add_sources' first

Showing the user that no text was found would be preferred.

from llmware.

doberst avatar doberst commented on May 14, 2024

Improved handling of this error has been added and merged into the main branch. Thanks for your feedback!

from llmware.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.