-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathvalidator.py
More file actions
21 lines (19 loc) · 745 Bytes
/
Copy pathvalidator.py
File metadata and controls
21 lines (19 loc) · 745 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
import os
from dotenv import load_dotenv
from langchain_openai import ChatOpenAI
load_dotenv()
openai_api_key = os.getenv("OPENAI_API_KEY")
def validate_query(query: str) -> bool:
prompt = (
f"Can the following task be performed using a web browser, such as searching, reading, or interacting with websites? "
f"Respond with only YES or NO.\n\nTask: \"{query}\""
)
try:
llm = ChatOpenAI(model_name="gpt-3.5-turbo", openai_api_key=openai_api_key)
response = llm.invoke(prompt)
answer = response.content.strip().lower()
print(f"Validation response: {answer}")
return answer.startswith("yes")
except Exception as e:
print("Validation error:", e)
return False