Spaces:
Sleeping
Sleeping
Update tools/custom_tool.py
Browse files- tools/custom_tool.py +0 -141
tools/custom_tool.py
CHANGED
|
@@ -1,145 +1,4 @@
|
|
| 1 |
# #crew_tool.py
|
| 2 |
-
# import json
|
| 3 |
-
# import os
|
| 4 |
-
# import requests
|
| 5 |
-
# from crewai.tools import tool
|
| 6 |
-
# from dotenv import load_dotenv
|
| 7 |
-
|
| 8 |
-
# # Load environment variables
|
| 9 |
-
# load_dotenv()
|
| 10 |
-
|
| 11 |
-
# def safe_format_with_indicators(text):
|
| 12 |
-
# """Replace emojis with text indicators"""
|
| 13 |
-
# if not isinstance(text, str):
|
| 14 |
-
# text = str(text)
|
| 15 |
-
|
| 16 |
-
# emoji_replacements = {
|
| 17 |
-
# 'π': '[BATTERY]',
|
| 18 |
-
# 'β
': '[SUCCESS]',
|
| 19 |
-
# 'β': '[ERROR]',
|
| 20 |
-
# 'π': '[DOCUMENT]',
|
| 21 |
-
# 'π': '[CHART]',
|
| 22 |
-
# 'β οΈ': '[WARNING]',
|
| 23 |
-
# 'π': '[SEARCH]',
|
| 24 |
-
# 'π‘': '[INSIGHT]',
|
| 25 |
-
# 'π―': '[TARGET]',
|
| 26 |
-
# 'β¨': '[HIGHLIGHT]',
|
| 27 |
-
# 'π': '[LAUNCH]',
|
| 28 |
-
# 'π': '[GROWTH]',
|
| 29 |
-
# 'π': '[DECLINE]',
|
| 30 |
-
# 'π§': '[TOOL]',
|
| 31 |
-
# 'π»': '[CODE]',
|
| 32 |
-
# 'π': '[STAR]',
|
| 33 |
-
# 'π¨': '[DESIGN]',
|
| 34 |
-
# 'π±': '[MOBILE]',
|
| 35 |
-
# 'π₯οΈ': '[DESKTOP]',
|
| 36 |
-
# 'π': '[LINK]',
|
| 37 |
-
# 'π': '[NOTE]',
|
| 38 |
-
# 'π': '[ACHIEVEMENT]',
|
| 39 |
-
# 'π°': '[MONEY]',
|
| 40 |
-
# 'π': '[CELEBRATION]',
|
| 41 |
-
# 'π': '[SECURE]',
|
| 42 |
-
# 'π': '[UNLOCKED]',
|
| 43 |
-
# 'β': '[RATING]',
|
| 44 |
-
# 'β€οΈ': '[FAVORITE]',
|
| 45 |
-
# 'π': '[THUMBS_UP]',
|
| 46 |
-
# 'π': '[THUMBS_DOWN]',
|
| 47 |
-
# 'π₯': '[HOT]',
|
| 48 |
-
# 'βοΈ': '[COLD]',
|
| 49 |
-
# 'π‘οΈ': '[TEMPERATURE]'
|
| 50 |
-
# }
|
| 51 |
-
|
| 52 |
-
# for emoji, replacement in emoji_replacements.items():
|
| 53 |
-
# text = text.replace(emoji, replacement)
|
| 54 |
-
|
| 55 |
-
# return text
|
| 56 |
-
|
| 57 |
-
# def format_api_response(response_data):
|
| 58 |
-
# """
|
| 59 |
-
# Format API response and replace emojis with safe indicators.
|
| 60 |
-
|
| 61 |
-
# Args:
|
| 62 |
-
# response_data: Raw API response (dict, str, or other)
|
| 63 |
-
|
| 64 |
-
# Returns:
|
| 65 |
-
# str: Formatted response with safe emoji replacements
|
| 66 |
-
# """
|
| 67 |
-
# try:
|
| 68 |
-
# if isinstance(response_data, dict):
|
| 69 |
-
# # Convert dict to readable format
|
| 70 |
-
# formatted_parts = []
|
| 71 |
-
|
| 72 |
-
# for key, value in response_data.items():
|
| 73 |
-
# if isinstance(value, (str, int, float)):
|
| 74 |
-
# safe_value = safe_format_with_indicators(str(value))
|
| 75 |
-
# formatted_parts.append(f"{key}: {safe_value}")
|
| 76 |
-
# elif isinstance(value, list):
|
| 77 |
-
# safe_items = [safe_format_with_indicators(str(item)) for item in value]
|
| 78 |
-
# formatted_parts.append(f"{key}: {', '.join(safe_items)}")
|
| 79 |
-
# elif isinstance(value, dict):
|
| 80 |
-
# # Handle nested dictionaries
|
| 81 |
-
# nested_items = []
|
| 82 |
-
# for nested_key, nested_value in value.items():
|
| 83 |
-
# safe_nested = safe_format_with_indicators(str(nested_value))
|
| 84 |
-
# nested_items.append(f"{nested_key}: {safe_nested}")
|
| 85 |
-
# formatted_parts.append(f"{key}: {'; '.join(nested_items)}")
|
| 86 |
-
|
| 87 |
-
# result = "\n".join(formatted_parts)
|
| 88 |
-
# return safe_format_with_indicators(result)
|
| 89 |
-
# else:
|
| 90 |
-
# return safe_format_with_indicators(str(response_data))
|
| 91 |
-
|
| 92 |
-
# except Exception as e:
|
| 93 |
-
# error_msg = f"Error formatting response: {str(e)}"
|
| 94 |
-
# return safe_format_with_indicators(error_msg)
|
| 95 |
-
|
| 96 |
-
# @tool("LandingAI Document Analysis")
|
| 97 |
-
# def landing_ai_document_analysis(file_path: str, file_type: str = "image") -> str:
|
| 98 |
-
# """
|
| 99 |
-
# Analyze images or PDFs using LandingAI's document analysis API.
|
| 100 |
-
|
| 101 |
-
# Args:
|
| 102 |
-
# file_path (str): Path to the image or PDF file to analyze
|
| 103 |
-
# file_type (str): Type of file, either "image" or "pdf"
|
| 104 |
-
|
| 105 |
-
# Returns:
|
| 106 |
-
# str: Analysis results from the API
|
| 107 |
-
# """
|
| 108 |
-
# # Get API key from environment variable
|
| 109 |
-
# api_key = os.getenv("LANDING_AI_API_KEY")
|
| 110 |
-
|
| 111 |
-
# # API endpoint
|
| 112 |
-
# url = "https://api.va.landing.ai/v1/tools/agentic-document-analysis"
|
| 113 |
-
|
| 114 |
-
# # Prepare the file for upload based on file_type
|
| 115 |
-
# with open(file_path, "rb") as file_obj:
|
| 116 |
-
# if file_type.lower() == "pdf":
|
| 117 |
-
# files = {"pdf": file_obj}
|
| 118 |
-
# else:
|
| 119 |
-
# files = {"image": file_obj}
|
| 120 |
-
|
| 121 |
-
# # Prepare headers with authentication
|
| 122 |
-
# headers = {"Authorization": f"Basic {api_key}"}
|
| 123 |
-
|
| 124 |
-
|
| 125 |
-
|
| 126 |
-
# # Make the API request
|
| 127 |
-
# response = requests.post(url, files=files, headers=headers)
|
| 128 |
-
# if response.status_code == 200:
|
| 129 |
-
# try:
|
| 130 |
-
# response_json = response.json()
|
| 131 |
-
# formatted_result = format_api_response(response_json)
|
| 132 |
-
# # result += f"π ANALYSIS:\n{formatted_result}"
|
| 133 |
-
# return safe_format_with_indicators(formatted_result)
|
| 134 |
-
|
| 135 |
-
# except json.JSONDecodeError:
|
| 136 |
-
# # If response isn't JSON, format the text response
|
| 137 |
-
# safe_text = safe_format_with_indicators(response.text)
|
| 138 |
-
# return safe_format_with_indicators(safe_text)
|
| 139 |
-
|
| 140 |
-
|
| 141 |
-
# return response.json()
|
| 142 |
-
|
| 143 |
import json
|
| 144 |
import os
|
| 145 |
import requests
|
|
|
|
| 1 |
# #crew_tool.py
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 2 |
import json
|
| 3 |
import os
|
| 4 |
import requests
|