get_text
Retrieve Jewish texts and commentaries from the Sefaria library by providing a reference such as 'Genesis 1:1' or 'שולחן ערוך אורח חיים סימן א'.
Instructions
get a jewish text from the jewish library
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| reference | Yes | The reference of the jewish text, e.g. 'שולחן ערוך אורח חיים סימן א' or 'Genesis 1:1' |
Implementation Reference
- Core handler function for the 'get_text' tool that retrieves Hebrew text from the Sefaria API for the given reference.async def get_text(reference: str) -> str: """ Retrieves the text for a given reference. """ return str(get_hebrew_text(reference))
- Dispatch handler within @server.call_tool() that processes 'get_text' tool calls, extracts the 'reference' argument, invokes get_text, and formats the response as TextContent.if name == "get_text": try: reference = arguments.get("reference") if not reference: raise ValueError("Missing reference parameter") logger.debug(f"handle_get_text: {reference}") text = await get_text(reference) return [types.TextContent( type="text", text= text )] except Exception as err: logger.error(f"retreive text error: {err}", exc_info=True) return [types.TextContent( type="text", text=f"Error: {str(err)}" )]
- src/sefaria_jewish_library/server.py:36-49 (registration)Tool registration in @server.list_tools(): defines name, description, and input schema requiring a 'reference' string.types.Tool( name="get_text", description="get a jewish text from the jewish library", inputSchema={ "type": "object", "properties": { "reference": { "type": "string", "description": "The reference of the jewish text, e.g. 'שולחן ערוך אורח חיים סימן א' or 'Genesis 1:1'", }, }, "required": ["reference"], }, ),
- JSON schema for 'get_text' tool input: object with required 'reference' property of type string.inputSchema={ "type": "object", "properties": { "reference": { "type": "string", "description": "The reference of the jewish text, e.g. 'שולחן ערוך אורח חיים סימן א' or 'Genesis 1:1'", }, }, "required": ["reference"], },
- Helper function used by get_text to query the Sefaria API for Hebrew text of the reference.def get_hebrew_text(parasha_ref): """ Retrieves the Hebrew text and version title for the given verse. """ data = get_request_json_data("api/v3/texts/", parasha_ref) if data and "versions" in data and len(data['versions']) > 0: he_pasuk = data['versions'][0]['text'] return he_pasuk else: print(f"Could not retrieve Hebrew text for {parasha_ref}") return None