geekphoenix commited on
Commit
d1db473
Β·
verified Β·
1 Parent(s): bf5695d

Update tools/custom_tool.py

Browse files
Files changed (1) hide show
  1. 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