-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathai.py
More file actions
46 lines (35 loc) · 1.45 KB
/
ai.py
File metadata and controls
46 lines (35 loc) · 1.45 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
import json
import time
from SimplerLLM.language.llm import LLM, LLMProvider
from SimplerLLM.tools.generic_loader import load_content
def fetch_apis(filepath):
text_file = load_content(filepath)
content = json.loads(text_file.content)
return content
def find_best_api(user_query, apis):
llm_instance = LLM.create(provider=LLMProvider.OPENAI, model_name="gpt-4o-mini")
u_prompt = f"""
You are an expert in problem solving. I have a user specific query and I want to check if I have an API
that would help him solve this problem. I'll give you both the user inquery and the list of APIs in the inputs
section delimited between triple backticks. So analyze both of them very well and check if there's an API which
can help him or no.
##Inputs
user inquiry: ```[{user_query}]```
API list: ```[{apis}]```
#Output
The output should only be the API name as provided in the inputs and nothing else. If no API was found return None.
"""
response = llm_instance.generate_response(prompt=u_prompt)
return response
# Input:
filepath = 'apis.json'
apis = fetch_apis(filepath)
user_query = input("Enter your inquiry: ")
start_time = time.time() # Start timer
result = find_best_api(user_query, apis)
if result!="None":
print(f"\nThe best API to use is: {result}\n")
else:
print("\nNo suitable API found.\n")
end_time = time.time() # End timer
print(f"Execution time: {end_time - start_time} seconds")