diff options
| -rw-r--r-- | main.py | 19 | ||||
| -rw-r--r-- | shell.nix | 8 |
2 files changed, 23 insertions, 4 deletions
@@ -1,7 +1,8 @@ +from typing import Any from langchain_ollama import ChatOllama from langchain.agents import create_agent -from langchain_community.tools.file_management import FileSearchTool - +from langchain_community.tools.file_management import ListDirectoryTool +from langchain.agents.middleware import after_model, AgentState GEMMA3 = "gemma3" LLAMA3 = "llama3.1:8b" @@ -14,12 +15,22 @@ model = ChatOllama( num_predict=256, ) + +@after_model +def log_response(state: AgentState, runtime) -> dict[str, Any] | None: + print(f"Model returned: {state['messages'][-1].content}") + return None + + agent = create_agent( model, tools=[ - FileSearchTool(), + ListDirectoryTool(), ], system_prompt="You are a helpful assistent.", + middleware=[ + log_response, + ], ) result = agent.invoke( @@ -27,7 +38,7 @@ result = agent.invoke( "messages": [ { "role": "user", - "content": "What files match *.py in .?", + "content": "What files are in .?", } ] } @@ -24,11 +24,19 @@ let ollama serve ''; }; + + main = writeShellApplication { + name = "main"; + text = '' + python main.py + ''; + }; in mkShell { packages = [ + main ollama pull python |
