Update app.py
Browse files
app.py
CHANGED
|
@@ -70,7 +70,84 @@ def search_terms_of_service(company_name: str) -> Dict:
|
|
| 70 |
print(error_msg) # debug, da AI prizna, če se zmoti
|
| 71 |
return {"error": error_msg}
|
| 72 |
|
| 73 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 74 |
|
| 75 |
@tool
|
| 76 |
def search_court_cases(keyword: str, jurisdiction: str = None,
|
|
@@ -239,7 +316,7 @@ with open("prompts.yaml", 'r') as stream:
|
|
| 239 |
#param za agenta
|
| 240 |
agent = CodeAgent(
|
| 241 |
model=model,
|
| 242 |
-
tools=[final_answer,search_terms_of_service], #search_court_cases, check_citation_status], #orodja
|
| 243 |
max_steps=6,
|
| 244 |
verbosity_level=1,
|
| 245 |
grammar=None,
|
|
|
|
| 70 |
print(error_msg) # debug, da AI prizna, če se zmoti
|
| 71 |
return {"error": error_msg}
|
| 72 |
|
| 73 |
+
@tool
|
| 74 |
+
def extract_tos_content(company_name: str) -> Dict:
|
| 75 |
+
"""
|
| 76 |
+
Search for a company's Terms of Service, access the link, and extract content.
|
| 77 |
+
|
| 78 |
+
Args:
|
| 79 |
+
company_name: Name of the organization/company to search for
|
| 80 |
+
|
| 81 |
+
Returns:
|
| 82 |
+
Dictionary containing company name, link, and extracted content
|
| 83 |
+
"""
|
| 84 |
+
|
| 85 |
+
# First use the existing function to get the TOS link
|
| 86 |
+
tos_info = search_terms_of_service(company_name)
|
| 87 |
+
|
| 88 |
+
# If there was an error in the search function, return that error
|
| 89 |
+
if "error" in tos_info:
|
| 90 |
+
return tos_info
|
| 91 |
+
|
| 92 |
+
try:
|
| 93 |
+
# Get the link from the search results
|
| 94 |
+
tos_link = tos_info["tos_link"]
|
| 95 |
+
|
| 96 |
+
print(f"Accessing TOS link: {tos_link}")
|
| 97 |
+
|
| 98 |
+
# Request the content from the TOS link
|
| 99 |
+
response = requests.get(tos_link)
|
| 100 |
+
response.raise_for_status()
|
| 101 |
+
|
| 102 |
+
# Parse the HTML content
|
| 103 |
+
soup = BeautifulSoup(response.text, 'html.parser')
|
| 104 |
+
|
| 105 |
+
# Extract repository content - assuming it's in a specific element
|
| 106 |
+
# You may need to adjust these selectors based on the actual page structure
|
| 107 |
+
repo_content = ""
|
| 108 |
+
repo_element = soup.find('div', class_='repository-content')
|
| 109 |
+
if repo_element:
|
| 110 |
+
repo_content = repo_element.get_text(strip=True)
|
| 111 |
+
|
| 112 |
+
# Extract TOS content - assuming it's in a specific element
|
| 113 |
+
# You may need to adjust these selectors based on the actual page structure
|
| 114 |
+
tos_content = ""
|
| 115 |
+
tos_element = soup.find('div', id='terms-of-service') or soup.find('div', class_='terms-of-service')
|
| 116 |
+
if tos_element:
|
| 117 |
+
tos_content = tos_element.get_text(strip=True)
|
| 118 |
+
|
| 119 |
+
# If we couldn't find specific elements, try to get the main content
|
| 120 |
+
if not repo_content and not tos_content:
|
| 121 |
+
main_content = soup.find('main') or soup.find('body')
|
| 122 |
+
if main_content:
|
| 123 |
+
main_content_text = main_content.get_text(strip=True)
|
| 124 |
+
return {
|
| 125 |
+
"company_name": tos_info["company_name"],
|
| 126 |
+
"tos_link": tos_link,
|
| 127 |
+
"content": main_content_text[:5000], # Limit content length
|
| 128 |
+
"note": "Could not identify specific repository or TOS sections"
|
| 129 |
+
}
|
| 130 |
+
|
| 131 |
+
return {
|
| 132 |
+
"company_name": tos_info["company_name"],
|
| 133 |
+
"tos_link": tos_link,
|
| 134 |
+
"repository_content": repo_content[:2500] if repo_content else "No repository content found",
|
| 135 |
+
"tos_content": tos_content[:2500] if tos_content else "No Terms of Service content found"
|
| 136 |
+
}
|
| 137 |
+
|
| 138 |
+
except requests.exceptions.RequestException as e:
|
| 139 |
+
error_msg = f"Error accessing TOS link: {str(e)}"
|
| 140 |
+
if hasattr(e, 'response') and e.response is not None:
|
| 141 |
+
error_msg += f" (Status code: {e.response.status_code})"
|
| 142 |
+
if hasattr(e.response, 'text'):
|
| 143 |
+
error_msg += f" - {e.response.text[:200]}"
|
| 144 |
+
print(error_msg)
|
| 145 |
+
return {"error": error_msg}
|
| 146 |
+
|
| 147 |
+
except Exception as e:
|
| 148 |
+
error_msg = f"Unexpected error while processing content: {str(e)}"
|
| 149 |
+
print(error_msg)
|
| 150 |
+
return {"error": error_msg}
|
| 151 |
|
| 152 |
@tool
|
| 153 |
def search_court_cases(keyword: str, jurisdiction: str = None,
|
|
|
|
| 316 |
#param za agenta
|
| 317 |
agent = CodeAgent(
|
| 318 |
model=model,
|
| 319 |
+
tools=[final_answer,search_terms_of_service,extract_tos_content], #search_court_cases, check_citation_status], #orodja
|
| 320 |
max_steps=6,
|
| 321 |
verbosity_level=1,
|
| 322 |
grammar=None,
|