Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[BUG] Groundedness not working #1649

Open
liambarstad opened this issue Nov 14, 2024 · 2 comments
Open

[BUG] Groundedness not working #1649

liambarstad opened this issue Nov 14, 2024 · 2 comments
Assignees
Labels
bug Something isn't working

Comments

@liambarstad
Copy link

Bug Description
groundedness_measure_with_cot_reasons is failing silently

To Reproduce

session = TruSession()

class RAG:
    @instrument
    def get_chunks(self, response_body: dict) -> list:
        return [ s['doc'] for s in response_body['documents']

    @instrument
    def query(self, input: str) -> str:
        response = requests.post('<<url>>', json={'query': input})
        if response.status_code == 200:
            chunks = self.get_chunks(response.json())
            return response.json()['response']

rag = RAG()

provider = Bedrock(model_id='<<model_id>>', region_name='<<region name>>')

f_groundedness = (
    Feedback(
        provider.groundedness_measure_with_cot_reasons, name='Groundedness'
    )
    .on(Select.RecordCalls.get_chunks.rets.collect() 
    # this does not work with rets[:] or just rets either
    .on_output()
)

# this works fine with answer and context relevance

tru_rag = TruCustomApp(
    rag,
    feedbacks=[f_groundedness
)

Expected behavior
I expect the metric to show up in my dashboard, since I'm following the sample code in the docs nearly to the letter

Relevant Logs/Tracebacks
When the dashboard is opened, "No feedbacks" is displayed, or groundedness is not shown. Besides that, it fails completely silently

Environment:

  • OS: Windows
  • Python Version: 3.12
  • TruLens version: 1.2.6
  • Versions of other relevant installed libraries
@liambarstad liambarstad added the bug Something isn't working label Nov 14, 2024
@sfc-gh-jreini
Copy link
Contributor

sfc-gh-jreini commented Nov 16, 2024

Hey @liambarstad at least in this code snippet above you are missing some closing parenthesis and brackets that might lead to his error.

Here's your code fixed:

f_groundedness = (
    Feedback(
        provider.groundedness_measure_with_cot_reasons, name='Groundedness'
    )
    .on(Select.RecordCalls.get_chunks.rets.collect()) # added missing closing parenthesis
    .on_output()
)

# this works fine with answer and context relevance

tru_rag = TruCustomApp(
    rag,
    feedbacks=[f_groundedness] # added missing closing bracket
)

@liambarstad
Copy link
Author

Those were typos on my part from copying the code over, those aren't part of the original

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants