35 lines
1.4 KiB
Python
35 lines
1.4 KiB
Python
"""
|
|
This module defines a LangGraph node function for retrieving files from a repository.
|
|
The function interacts with an LLM to determine the workflow files available in the
|
|
specified repository and scope.
|
|
"""
|
|
|
|
async def process(state: dict) -> dict:
|
|
from app.agent import llm
|
|
from langchain_core.messages import SystemMessage, HumanMessage
|
|
|
|
try:
|
|
# Extract input fields from state
|
|
repository_url = state.get("repository_url", "")
|
|
update_scope = state.get("update_scope", "")
|
|
|
|
# Validate inputs
|
|
if not repository_url or not update_scope:
|
|
raise ValueError("Both 'repository_url' and 'update_scope' must be provided.")
|
|
|
|
# Prepare messages for the LLM
|
|
messages = [
|
|
SystemMessage(content="You are an expert in repository management and file retrieval."),
|
|
HumanMessage(content=f"Retrieve all workflow files from the repository at '{repository_url}' "
|
|
f"within the scope '{update_scope}'. Provide the list of file names.")
|
|
]
|
|
|
|
# Invoke the LLM
|
|
response = await llm.ainvoke(messages)
|
|
|
|
# Parse the response and return the output
|
|
workflow_files = response.content.splitlines() # Assuming the LLM returns file names as newline-separated text
|
|
return {"workflow_files": workflow_files, "phase": "complete"}
|
|
|
|
except Exception as exc:
|
|
return {"error": str(exc), "phase": "failed"} |