-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathagent.py
More file actions
28 lines (20 loc) · 801 Bytes
/
agent.py
File metadata and controls
28 lines (20 loc) · 801 Bytes
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
from dotenv import load_dotenv
load_dotenv()
from langchain_google_genai import ChatGoogleGenerativeAI
from langchain_core.messages import HumanMessage
from schema import ExtractedData
def LLMagent(user_input: str):
try:
llm = ChatGoogleGenerativeAI(
model="models/gemini-2.5-flash",
temperature=0.0
)
prompt_message = [
HumanMessage(
content=f"Extract the requested data from the following text and conform to the provided schema:\n\nTEXT: {user_input}"
)
]
pydantic_output = llm.with_structured_output(ExtractedData).invoke(prompt_message)
return pydantic_output.model_dump()
except Exception as e:
return f"\n LangChain Agent Failed! Error: {e}"