optimize for dumb models
This commit is contained in:
@@ -230,16 +230,16 @@ Bu FastMCP sunucusu aşağıdaki temel araçları sunar:
|
|||||||
|
|
||||||
* **Yargıtay Araçları:**
|
* **Yargıtay Araçları:**
|
||||||
* `search_yargitay_detailed(search_query: YargitayDetailedSearchRequest) -> CompactYargitaySearchResult`: Yargıtay kararlarını detaylı kriterlerle arar.
|
* `search_yargitay_detailed(search_query: YargitayDetailedSearchRequest) -> CompactYargitaySearchResult`: Yargıtay kararlarını detaylı kriterlerle arar.
|
||||||
* `get_yargitay_document_markdown(document_id: str) -> YargitayDocumentMarkdown`: Belirli bir Yargıtay kararının metnini Markdown formatında getirir.
|
* `get_yargitay_document_markdown(id: str) -> YargitayDocumentMarkdown`: Belirli bir Yargıtay kararının metnini Markdown formatında getirir.
|
||||||
|
|
||||||
* **Danıştay Araçları:**
|
* **Danıştay Araçları:**
|
||||||
* `search_danistay_by_keyword(search_query: DanistayKeywordSearchRequest) -> CompactDanistaySearchResult`: Danıştay kararlarını anahtar kelimelerle arar.
|
* `search_danistay_by_keyword(search_query: DanistayKeywordSearchRequest) -> CompactDanistaySearchResult`: Danıştay kararlarını anahtar kelimelerle arar.
|
||||||
* `search_danistay_detailed(search_query: DanistayDetailedSearchRequest) -> CompactDanistaySearchResult`: Danıştay kararlarını detaylı kriterlerle arar.
|
* `search_danistay_detailed(search_query: DanistayDetailedSearchRequest) -> CompactDanistaySearchResult`: Danıştay kararlarını detaylı kriterlerle arar.
|
||||||
* `get_danistay_document_markdown(document_id: str) -> DanistayDocumentMarkdown`: Belirli bir Danıştay kararının metnini Markdown formatında getirir.
|
* `get_danistay_document_markdown(id: str) -> DanistayDocumentMarkdown`: Belirli bir Danıştay kararının metnini Markdown formatında getirir.
|
||||||
|
|
||||||
* **Emsal Karar Araçları:**
|
* **Emsal Karar Araçları:**
|
||||||
* `search_emsal_detailed_decisions(search_query: EmsalSearchRequest) -> CompactEmsalSearchResult`: Emsal (UYAP) kararlarını detaylı kriterlerle arar.
|
* `search_emsal_detailed_decisions(search_query: EmsalSearchRequest) -> CompactEmsalSearchResult`: Emsal (UYAP) kararlarını detaylı kriterlerle arar.
|
||||||
* `get_emsal_document_markdown(document_id: str) -> EmsalDocumentMarkdown`: Belirli bir Emsal kararının metnini Markdown formatında getirir.
|
* `get_emsal_document_markdown(id: str) -> EmsalDocumentMarkdown`: Belirli bir Emsal kararının metnini Markdown formatında getirir.
|
||||||
|
|
||||||
* **Uyuşmazlık Mahkemesi Araçları:**
|
* **Uyuşmazlık Mahkemesi Araçları:**
|
||||||
* `search_uyusmazlik_decisions(search_params: UyusmazlikSearchRequest) -> UyusmazlikSearchResponse`: Uyuşmazlık Mahkemesi kararlarını çeşitli form kriterleriyle arar.
|
* `search_uyusmazlik_decisions(search_params: UyusmazlikSearchRequest) -> UyusmazlikSearchResponse`: Uyuşmazlık Mahkemesi kararlarını çeşitli form kriterleriyle arar.
|
||||||
|
|||||||
@@ -143,14 +143,14 @@ class DanistayApiClient:
|
|||||||
|
|
||||||
return markdown_text
|
return markdown_text
|
||||||
|
|
||||||
async def get_decision_document_as_markdown(self, document_id: str) -> DanistayDocumentMarkdown:
|
async def get_decision_document_as_markdown(self, id: str) -> DanistayDocumentMarkdown:
|
||||||
"""
|
"""
|
||||||
Retrieves a specific Danıştay decision by ID and returns its content as Markdown.
|
Retrieves a specific Danıştay decision by ID and returns its content as Markdown.
|
||||||
The /getDokuman endpoint for Danıştay returns direct HTML.
|
The /getDokuman endpoint for Danıştay returns direct HTML.
|
||||||
"""
|
"""
|
||||||
document_api_url = f"{self.DOCUMENT_ENDPOINT}?id={document_id}"
|
document_api_url = f"{self.DOCUMENT_ENDPOINT}?id={id}"
|
||||||
source_url = f"{self.BASE_URL}{document_api_url}"
|
source_url = f"{self.BASE_URL}{document_api_url}"
|
||||||
logger.info(f"DanistayApiClient: Fetching Danistay document for Markdown (ID: {document_id}) from {source_url}")
|
logger.info(f"DanistayApiClient: Fetching Danistay document for Markdown (ID: {id}) from {source_url}")
|
||||||
|
|
||||||
try:
|
try:
|
||||||
# For direct HTML response, we might want different headers if the API is sensitive,
|
# For direct HTML response, we might want different headers if the API is sensitive,
|
||||||
@@ -162,10 +162,10 @@ class DanistayApiClient:
|
|||||||
html_content_from_api = response.text
|
html_content_from_api = response.text
|
||||||
|
|
||||||
if not isinstance(html_content_from_api, str) or not html_content_from_api.strip():
|
if not isinstance(html_content_from_api, str) or not html_content_from_api.strip():
|
||||||
logger.warning(f"DanistayApiClient: Received empty or non-string HTML content for ID {document_id}.")
|
logger.warning(f"DanistayApiClient: Received empty or non-string HTML content for ID {id}.")
|
||||||
# Return with None markdown_content if HTML is effectively empty
|
# Return with None markdown_content if HTML is effectively empty
|
||||||
return DanistayDocumentMarkdown(
|
return DanistayDocumentMarkdown(
|
||||||
document_id=document_id,
|
id=id,
|
||||||
markdown_content=None,
|
markdown_content=None,
|
||||||
source_url=source_url
|
source_url=source_url
|
||||||
)
|
)
|
||||||
@@ -173,16 +173,16 @@ class DanistayApiClient:
|
|||||||
markdown_content = self._convert_html_to_markdown_danistay(html_content_from_api)
|
markdown_content = self._convert_html_to_markdown_danistay(html_content_from_api)
|
||||||
|
|
||||||
return DanistayDocumentMarkdown(
|
return DanistayDocumentMarkdown(
|
||||||
document_id=document_id,
|
id=id,
|
||||||
markdown_content=markdown_content,
|
markdown_content=markdown_content,
|
||||||
source_url=source_url
|
source_url=source_url
|
||||||
)
|
)
|
||||||
except httpx.RequestError as e:
|
except httpx.RequestError as e:
|
||||||
logger.error(f"DanistayApiClient: HTTP error fetching Danistay document (ID: {document_id}): {e}")
|
logger.error(f"DanistayApiClient: HTTP error fetching Danistay document (ID: {id}): {e}")
|
||||||
raise
|
raise
|
||||||
# Removed ValueError for JSON as Danistay /getDokuman returns direct HTML
|
# Removed ValueError for JSON as Danistay /getDokuman returns direct HTML
|
||||||
except Exception as e: # Catches other errors like MarkItDown issues if they propagate
|
except Exception as e: # Catches other errors like MarkItDown issues if they propagate
|
||||||
logger.error(f"DanistayApiClient: General error processing Danistay document (ID: {document_id}): {e}")
|
logger.error(f"DanistayApiClient: General error processing Danistay document (ID: {id}): {e}")
|
||||||
raise
|
raise
|
||||||
|
|
||||||
async def close_client_session(self):
|
async def close_client_session(self):
|
||||||
|
|||||||
@@ -104,7 +104,7 @@ class DanistayApiResponse(BaseModel):
|
|||||||
|
|
||||||
class DanistayDocumentMarkdown(BaseModel):
|
class DanistayDocumentMarkdown(BaseModel):
|
||||||
"""Model for a Danistay decision document, containing only Markdown content."""
|
"""Model for a Danistay decision document, containing only Markdown content."""
|
||||||
document_id: str
|
id: str
|
||||||
markdown_content: Optional[str] = Field(None, description="The decision content converted to Markdown.")
|
markdown_content: Optional[str] = Field(None, description="The decision content converted to Markdown.")
|
||||||
source_url: HttpUrl
|
source_url: HttpUrl
|
||||||
|
|
||||||
|
|||||||
@@ -133,14 +133,14 @@ class EmsalApiClient:
|
|||||||
|
|
||||||
return markdown_text
|
return markdown_text
|
||||||
|
|
||||||
async def get_decision_document_as_markdown(self, document_id: str) -> EmsalDocumentMarkdown:
|
async def get_decision_document_as_markdown(self, id: str) -> EmsalDocumentMarkdown:
|
||||||
"""
|
"""
|
||||||
Retrieves a specific Emsal decision by ID and returns its content as Markdown.
|
Retrieves a specific Emsal decision by ID and returns its content as Markdown.
|
||||||
Assumes Emsal /getDokuman endpoint returns JSON with HTML content in the 'data' field.
|
Assumes Emsal /getDokuman endpoint returns JSON with HTML content in the 'data' field.
|
||||||
"""
|
"""
|
||||||
document_api_url = f"{self.DOCUMENT_ENDPOINT}?id={document_id}"
|
document_api_url = f"{self.DOCUMENT_ENDPOINT}?id={id}"
|
||||||
source_url = f"{self.BASE_URL}{document_api_url}"
|
source_url = f"{self.BASE_URL}{document_api_url}"
|
||||||
logger.info(f"EmsalApiClient: Fetching Emsal document for Markdown (ID: {document_id}) from {source_url}")
|
logger.info(f"EmsalApiClient: Fetching Emsal document for Markdown (ID: {id}) from {source_url}")
|
||||||
|
|
||||||
try:
|
try:
|
||||||
response = await self.http_client.get(document_api_url)
|
response = await self.http_client.get(document_api_url)
|
||||||
@@ -151,24 +151,24 @@ class EmsalApiClient:
|
|||||||
html_content_from_api = response_json.get("data")
|
html_content_from_api = response_json.get("data")
|
||||||
|
|
||||||
if not isinstance(html_content_from_api, str) or not html_content_from_api.strip():
|
if not isinstance(html_content_from_api, str) or not html_content_from_api.strip():
|
||||||
logger.warning(f"EmsalApiClient: Received empty or non-string HTML in 'data' field for Emsal ID {document_id}.")
|
logger.warning(f"EmsalApiClient: Received empty or non-string HTML in 'data' field for Emsal ID {id}.")
|
||||||
return EmsalDocumentMarkdown(document_id=document_id, markdown_content=None, source_url=source_url)
|
return EmsalDocumentMarkdown(id=id, markdown_content=None, source_url=source_url)
|
||||||
|
|
||||||
markdown_content = self._clean_html_and_convert_to_markdown_emsal(html_content_from_api)
|
markdown_content = self._clean_html_and_convert_to_markdown_emsal(html_content_from_api)
|
||||||
|
|
||||||
return EmsalDocumentMarkdown(
|
return EmsalDocumentMarkdown(
|
||||||
document_id=document_id,
|
id=id,
|
||||||
markdown_content=markdown_content,
|
markdown_content=markdown_content,
|
||||||
source_url=source_url
|
source_url=source_url
|
||||||
)
|
)
|
||||||
except httpx.RequestError as e:
|
except httpx.RequestError as e:
|
||||||
logger.error(f"EmsalApiClient: HTTP error fetching Emsal document (ID: {document_id}): {e}")
|
logger.error(f"EmsalApiClient: HTTP error fetching Emsal document (ID: {id}): {e}")
|
||||||
raise
|
raise
|
||||||
except ValueError as e:
|
except ValueError as e:
|
||||||
logger.error(f"EmsalApiClient: ValueError processing Emsal document response (ID: {document_id}): {e}")
|
logger.error(f"EmsalApiClient: ValueError processing Emsal document response (ID: {id}): {e}")
|
||||||
raise
|
raise
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
logger.error(f"EmsalApiClient: General error processing Emsal document (ID: {document_id}): {e}")
|
logger.error(f"EmsalApiClient: General error processing Emsal document (ID: {id}): {e}")
|
||||||
raise
|
raise
|
||||||
|
|
||||||
async def close_client_session(self):
|
async def close_client_session(self):
|
||||||
|
|||||||
@@ -92,7 +92,7 @@ class EmsalApiResponse(BaseModel):
|
|||||||
|
|
||||||
class EmsalDocumentMarkdown(BaseModel):
|
class EmsalDocumentMarkdown(BaseModel):
|
||||||
"""Model for an Emsal decision document, containing only Markdown content."""
|
"""Model for an Emsal decision document, containing only Markdown content."""
|
||||||
document_id: str
|
id: str
|
||||||
markdown_content: Optional[str] = Field(None, description="The decision content converted to Markdown.")
|
markdown_content: Optional[str] = Field(None, description="The decision content converted to Markdown.")
|
||||||
source_url: HttpUrl
|
source_url: HttpUrl
|
||||||
|
|
||||||
|
|||||||
+13
-13
@@ -169,12 +169,12 @@ async def search_yargitay_detailed(
|
|||||||
raise
|
raise
|
||||||
|
|
||||||
@app.tool()
|
@app.tool()
|
||||||
async def get_yargitay_document_markdown(document_id: str) -> YargitayDocumentMarkdown:
|
async def get_yargitay_document_markdown(id: str) -> YargitayDocumentMarkdown:
|
||||||
"""Retrieves a specific Yargitay decision by its ID and returns its content as Markdown."""
|
"""Retrieves a specific Yargitay decision by its ID and returns its content as Markdown. Use id field from previous Yargıtay search results."""
|
||||||
logger.info(f"Tool 'get_yargitay_document_markdown' called for ID: {document_id}")
|
logger.info(f"Tool 'get_yargitay_document_markdown' called for ID: {id}")
|
||||||
if not document_id or not document_id.strip(): raise ValueError("Document ID must be a non-empty string.")
|
if not id or not id.strip(): raise ValueError("Document ID must be a non-empty string.")
|
||||||
try:
|
try:
|
||||||
return await yargitay_client_instance.get_decision_document_as_markdown(document_id)
|
return await yargitay_client_instance.get_decision_document_as_markdown(id)
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
logger.exception(f"Error in tool 'get_yargitay_document_markdown'.")
|
logger.exception(f"Error in tool 'get_yargitay_document_markdown'.")
|
||||||
raise
|
raise
|
||||||
@@ -271,12 +271,12 @@ async def search_danistay_detailed(
|
|||||||
raise
|
raise
|
||||||
|
|
||||||
@app.tool()
|
@app.tool()
|
||||||
async def get_danistay_document_markdown(document_id: str) -> DanistayDocumentMarkdown:
|
async def get_danistay_document_markdown(id: str) -> DanistayDocumentMarkdown:
|
||||||
"""Retrieves a specific Danıştay decision by ID and returns its content as Markdown."""
|
"""Retrieves a specific Danıştay decision by ID and returns its content as Markdown."""
|
||||||
logger.info(f"Tool 'get_danistay_document_markdown' called for ID: {document_id}")
|
logger.info(f"Tool 'get_danistay_document_markdown' called for ID: {id}")
|
||||||
if not document_id or not document_id.strip(): raise ValueError("Document ID must be a non-empty string for Danıştay.")
|
if not id or not id.strip(): raise ValueError("Document ID must be a non-empty string for Danıştay.")
|
||||||
try:
|
try:
|
||||||
return await danistay_client_instance.get_decision_document_as_markdown(document_id)
|
return await danistay_client_instance.get_decision_document_as_markdown(id)
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
logger.exception(f"Error in tool 'get_danistay_document_markdown'.")
|
logger.exception(f"Error in tool 'get_danistay_document_markdown'.")
|
||||||
raise
|
raise
|
||||||
@@ -339,12 +339,12 @@ async def search_emsal_detailed_decisions(
|
|||||||
raise
|
raise
|
||||||
|
|
||||||
@app.tool()
|
@app.tool()
|
||||||
async def get_emsal_document_markdown(document_id: str) -> EmsalDocumentMarkdown:
|
async def get_emsal_document_markdown(id: str) -> EmsalDocumentMarkdown:
|
||||||
"""Retrieves a specific Emsal decision by ID and returns its content as Markdown."""
|
"""Retrieves a specific Emsal decision by ID and returns its content as Markdown."""
|
||||||
logger.info(f"Tool 'get_emsal_document_markdown' called for ID: {document_id}")
|
logger.info(f"Tool 'get_emsal_document_markdown' called for ID: {id}")
|
||||||
if not document_id or not document_id.strip(): raise ValueError("Document ID required for Emsal.")
|
if not id or not id.strip(): raise ValueError("Document ID required for Emsal.")
|
||||||
try:
|
try:
|
||||||
return await emsal_client_instance.get_decision_document_as_markdown(document_id)
|
return await emsal_client_instance.get_decision_document_as_markdown(id)
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
logger.exception(f"Error in tool 'get_emsal_document_markdown'.")
|
logger.exception(f"Error in tool 'get_emsal_document_markdown'.")
|
||||||
raise
|
raise
|
||||||
|
|||||||
@@ -130,15 +130,15 @@ class YargitayOfficialApiClient:
|
|||||||
|
|
||||||
return markdown_output
|
return markdown_output
|
||||||
|
|
||||||
async def get_decision_document_as_markdown(self, document_id: str) -> YargitayDocumentMarkdown:
|
async def get_decision_document_as_markdown(self, id: str) -> YargitayDocumentMarkdown:
|
||||||
"""
|
"""
|
||||||
Retrieves a specific Yargitay decision by its ID and returns its content
|
Retrieves a specific Yargitay decision by its ID and returns its content
|
||||||
as Markdown.
|
as Markdown.
|
||||||
Based on user-provided /getDokuman response structure.
|
Based on user-provided /getDokuman response structure.
|
||||||
"""
|
"""
|
||||||
document_api_url = f"{self.DOCUMENT_ENDPOINT}?id={document_id}"
|
document_api_url = f"{self.DOCUMENT_ENDPOINT}?id={id}"
|
||||||
source_url = f"{self.BASE_URL}{document_api_url}" # The original URL of the document
|
source_url = f"{self.BASE_URL}{document_api_url}" # The original URL of the document
|
||||||
logger.info(f"YargitayOfficialApiClient: Fetching document for Markdown conversion (ID: {document_id})")
|
logger.info(f"YargitayOfficialApiClient: Fetching document for Markdown conversion (ID: {id})")
|
||||||
|
|
||||||
try:
|
try:
|
||||||
response = await self.http_client.get(document_api_url)
|
response = await self.http_client.get(document_api_url)
|
||||||
@@ -149,24 +149,24 @@ class YargitayOfficialApiClient:
|
|||||||
html_content_from_api = response_json.get("data")
|
html_content_from_api = response_json.get("data")
|
||||||
|
|
||||||
if not isinstance(html_content_from_api, str):
|
if not isinstance(html_content_from_api, str):
|
||||||
logger.error(f"YargitayOfficialApiClient: 'data' field in API response is not a string or not found (ID: {document_id}).")
|
logger.error(f"YargitayOfficialApiClient: 'data' field in API response is not a string or not found (ID: {id}).")
|
||||||
raise ValueError("Expected HTML content not found in API response's 'data' field.")
|
raise ValueError("Expected HTML content not found in API response's 'data' field.")
|
||||||
|
|
||||||
markdown_content = self._convert_html_to_markdown(html_content_from_api)
|
markdown_content = self._convert_html_to_markdown(html_content_from_api)
|
||||||
|
|
||||||
return YargitayDocumentMarkdown(
|
return YargitayDocumentMarkdown(
|
||||||
document_id=document_id,
|
id=id,
|
||||||
markdown_content=markdown_content,
|
markdown_content=markdown_content,
|
||||||
source_url=source_url
|
source_url=source_url
|
||||||
)
|
)
|
||||||
except httpx.RequestError as e:
|
except httpx.RequestError as e:
|
||||||
logger.error(f"YargitayOfficialApiClient: HTTP error fetching document for Markdown (ID: {document_id}): {e}")
|
logger.error(f"YargitayOfficialApiClient: HTTP error fetching document for Markdown (ID: {id}): {e}")
|
||||||
raise
|
raise
|
||||||
except ValueError as e: # For JSON parsing errors or missing 'data' field
|
except ValueError as e: # For JSON parsing errors or missing 'data' field
|
||||||
logger.error(f"YargitayOfficialApiClient: Error processing document response for Markdown (ID: {document_id}): {e}")
|
logger.error(f"YargitayOfficialApiClient: Error processing document response for Markdown (ID: {id}): {e}")
|
||||||
raise
|
raise
|
||||||
except Exception as e: # For other unexpected errors
|
except Exception as e: # For other unexpected errors
|
||||||
logger.error(f"YargitayOfficialApiClient: General error fetching/processing document for Markdown (ID: {document_id}): {e}")
|
logger.error(f"YargitayOfficialApiClient: General error fetching/processing document for Markdown (ID: {id}): {e}")
|
||||||
raise
|
raise
|
||||||
|
|
||||||
async def close_client_session(self):
|
async def close_client_session(self):
|
||||||
|
|||||||
@@ -64,7 +64,7 @@ class YargitayApiSearchResponse(BaseModel):
|
|||||||
|
|
||||||
class YargitayDocumentMarkdown(BaseModel):
|
class YargitayDocumentMarkdown(BaseModel):
|
||||||
"""Model for a Yargitay decision document, containing only Markdown content."""
|
"""Model for a Yargitay decision document, containing only Markdown content."""
|
||||||
document_id: str = Field(..., description="The unique ID of the document.")
|
id: str = Field(..., description="The unique ID of the document.")
|
||||||
markdown_content: Optional[str] = Field(None, description="The decision content converted to Markdown.")
|
markdown_content: Optional[str] = Field(None, description="The decision content converted to Markdown.")
|
||||||
source_url: HttpUrl = Field(..., description="The source URL of the original document.")
|
source_url: HttpUrl = Field(..., description="The source URL of the original document.")
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user