-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path_work_flow_gen.py
More file actions
34 lines (25 loc) · 997 Bytes
/
Copy path_work_flow_gen.py
File metadata and controls
34 lines (25 loc) · 997 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
28
29
30
31
32
33
34
import json
import os
from dotenv import load_dotenv
from langchain_google_genai import ChatGoogleGenerativeAI
from langchain_core.messages import SystemMessage, HumanMessage
load_dotenv()
# Load system prompt and function registry once
with open("sys_prompt_temp.txt", 'r') as f:
sys_prompt_temp = f.read()
with open("function_registry.json") as f:
function_registry = json.load(f)
llm = ChatGoogleGenerativeAI(model="gemini-2.5-flash",api_key=os.getenv("GOOGLE_API_KEY"))
def generate_workflow(user_prompt: str):
messages = [
SystemMessage(content=sys_prompt_temp),
HumanMessage(content=user_prompt)
]
res = llm.invoke(messages)
content = res.content.lstrip("```json").rstrip("```")
try:
parsed = json.loads(content)
return parsed
except json.JSONDecodeError as e:
raise ValueError(f"Invalid JSON from LLM: {content}") from e
# print(generate_workflow("land cover map of Chennai with low level of elevation"))