@@ -51,31 +51,28 @@ def create_ess_project(project_name: str) -> str:
5151 api_key = os .environ .get ("API_KEY" )
5252 region_id = os .environ .get ("REGION" , "aws-eu-west-1" )
5353
54-
5554 if not env_url :
5655 return "Error: ES_URL is not set in the environment."
5756 if not api_key :
5857 return "Error: API_KEY is not set in the environment."
5958
60-
6159 url = f"{ env_url } /api/v1/serverless/projects/elasticsearch"
6260
6361 headers = {"Authorization" : f"ApiKey { api_key } " , "Content-Type" : "application/json" }
6462 payload = {"name" : project_name , "region_id" : region_id }
6563
66-
6764 try :
6865 response = requests .post (url , headers = headers , json = payload )
6966 response .raise_for_status ()
7067 except requests .exceptions .RequestException as e :
7168 return f"Error during project creation: { e } "
7269
73-
7470 data = response .json ()
7571 project_id = data .get ("id" )
7672 if not project_id :
7773 return "Error: No project ID returned from the API."
78-
74+
75+
7976 if not re .fullmatch (r"^[a-z0-9]{32}$" , project_id ):
8077 return (
8178 f"Error: Received project ID '{ project_id } ' does not match expected format."
@@ -84,7 +81,6 @@ def create_ess_project(project_name: str) -> str:
8481 credentials = data .get ("credentials" )
8582 endpoints = data .get ("endpoints" )
8683
87-
8884 PROJECT_MAP [project_name ] = {
8985 "id" : project_id ,
9086 "credentials" : credentials ,
@@ -120,6 +116,7 @@ def delete_ess_project(project_name: str) -> str:
120116 if not api_key :
121117 return "Error: API_KEY is not set in the environment."
122118
119+
123120 url = f"{ env_url } /api/v1/serverless/projects/elasticsearch/{ project_id } "
124121 headers = {"Authorization" : f"ApiKey { api_key } " , "Content-Type" : "application/json" }
125122
@@ -164,7 +161,6 @@ def get_ess_project_status(project_name: str) -> str:
164161 except requests .exceptions .RequestException as e :
165162 return f"Error retrieving project status: { e } "
166163
167-
168164 status_data = response .json ()
169165 return json .dumps (status_data , indent = 4 )
170166
@@ -189,7 +185,8 @@ def get_ess_project_details(project_name: str) -> str:
189185 return "Error: ES_URL is not set in the environment."
190186 if not api_key :
191187 return "Error: API_KEY is not set in the environment."
192-
188+
189+
193190 url = f"{ env_url } /api/v1/serverless/projects/elasticsearch/{ project_id } "
194191 headers = {"Authorization" : f"ApiKey { api_key } " }
195192
@@ -206,6 +203,7 @@ def get_ess_project_details(project_name: str) -> str:
206203 details_data ["endpoints" ] = project_info .get ("endpoints" )
207204 return json .dumps (details_data , indent = 4 )
208205
206+
209207create_project_tool = FunctionTool .from_defaults (
210208 create_ess_project ,
211209 name = "create_ess_project" ,
@@ -269,14 +267,15 @@ def main():
269267 print (" - 'Get the status of the serverless project named my_project'" )
270268 print (" - 'Get the details of the serverless project named my_project'" )
271269
272-
273270 while True :
274271 user_input = input ("\n User: " )
275272 if user_input .strip ().lower () in {"exit" , "quit" }:
276273 break
274+
277275
278276 response = agent .chat (user_input )
279277 print ("\n Agent:" , response )
280278
279+
281280if __name__ == "__main__" :
282281 main ()
0 commit comments