mirror of
https://github.com/Significant-Gravitas/AutoGPT.git
synced 2026-01-09 15:17:59 -05:00
feat(blocks): Add references output pin to Fact Checker block (#11166)
Closes #11163 ## Summary Expanded the Fact Checker block to yield its references list from the Jina AI API response. ## Changes 🏗️ - Added `Reference` TypedDict to define the structure of reference objects - Added `references` field to the Output schema - Modified the `run` method to extract and yield references from the API response - Added fallback to empty list if references are not present ## Checklist 📋 ### For code changes: - [x] I have clearly listed my changes in the PR description - [x] I have made a test plan - [x] I have tested my changes according to the test plan: - [x] Verified that the Fact Checker block schema includes the new references field - [x] Confirmed that references are properly extracted from the API response when present - [x] Tested the fallback behavior when references are not in the API response - [x] Ensured backward compatibility - existing functionality remains unchanged - [x] Verified the Reference TypedDict matches the expected API response structure Generated with [Claude Code](https://claude.ai/code) ## Summary by CodeRabbit * **New Features** * Fact-checking results now include a references list to support verification. * Each reference provides a URL, a key quote, and an indicator showing whether it supports the claim. * References are presented alongside factuality, result, and reasoning when available; otherwise, an empty list is returned. * Enhances transparency and traceability of fact-check outcomes without altering existing result fields. --------- Co-authored-by: claude[bot] <41898282+claude[bot]@users.noreply.github.com> Co-authored-by: Toran Bruce Richards <Torantulino@users.noreply.github.com> Co-authored-by: Bentlybro <Github@bentlybro.com>
This commit is contained in:
committed by
GitHub
parent
0f19d01483
commit
adfa75eca8
@@ -1,5 +1,8 @@
|
||||
from typing import List
|
||||
from urllib.parse import quote
|
||||
|
||||
from typing_extensions import TypedDict
|
||||
|
||||
from backend.blocks.jina._auth import (
|
||||
JinaCredentials,
|
||||
JinaCredentialsField,
|
||||
@@ -10,6 +13,12 @@ from backend.data.model import SchemaField
|
||||
from backend.util.request import Requests
|
||||
|
||||
|
||||
class Reference(TypedDict):
|
||||
url: str
|
||||
keyQuote: str
|
||||
isSupportive: bool
|
||||
|
||||
|
||||
class FactCheckerBlock(Block):
|
||||
class Input(BlockSchema):
|
||||
statement: str = SchemaField(
|
||||
@@ -23,6 +32,10 @@ class FactCheckerBlock(Block):
|
||||
)
|
||||
result: bool = SchemaField(description="The result of the factuality check")
|
||||
reason: str = SchemaField(description="The reason for the factuality result")
|
||||
references: List[Reference] = SchemaField(
|
||||
description="List of references supporting or contradicting the statement",
|
||||
default=[],
|
||||
)
|
||||
error: str = SchemaField(description="Error message if the check fails")
|
||||
|
||||
def __init__(self):
|
||||
@@ -53,5 +66,11 @@ class FactCheckerBlock(Block):
|
||||
yield "factuality", data["factuality"]
|
||||
yield "result", data["result"]
|
||||
yield "reason", data["reason"]
|
||||
|
||||
# Yield references if present in the response
|
||||
if "references" in data:
|
||||
yield "references", data["references"]
|
||||
else:
|
||||
yield "references", []
|
||||
else:
|
||||
raise RuntimeError(f"Expected 'data' key not found in response: {data}")
|
||||
|
||||
Reference in New Issue
Block a user