Spaces:
Sleeping
Sleeping
Luigi D'Addona
commited on
Commit
·
7397ba9
1
Parent(s):
cbb9f5e
aggiunte istruzioni per ottenere solo la risposta, senza commenti/spiegazioni
Browse files
agent.py
CHANGED
|
@@ -4,7 +4,7 @@ import traceback
|
|
| 4 |
|
| 5 |
from typing import Annotated,Sequence, TypedDict
|
| 6 |
|
| 7 |
-
from langchain_core.messages import BaseMessage
|
| 8 |
from langgraph.graph.message import add_messages # helper function to add messages to the state
|
| 9 |
from langchain_core.messages import ToolMessage
|
| 10 |
from langchain_core.runnables import RunnableConfig
|
|
@@ -71,8 +71,18 @@ def call_tool(state: AgentState):
|
|
| 71 |
|
| 72 |
|
| 73 |
def call_model( state: AgentState, config: RunnableConfig):
|
|
|
|
| 74 |
# Invoke the model with the system prompt and the messages
|
| 75 |
-
response = chat_with_tools.invoke(state["messages"], config)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 76 |
# We return a list, because this will get added to the existing messages state using the add_messages reducer
|
| 77 |
return {"messages": [response]}
|
| 78 |
|
|
|
|
| 4 |
|
| 5 |
from typing import Annotated,Sequence, TypedDict
|
| 6 |
|
| 7 |
+
from langchain_core.messages import BaseMessage, HumanMessage
|
| 8 |
from langgraph.graph.message import add_messages # helper function to add messages to the state
|
| 9 |
from langchain_core.messages import ToolMessage
|
| 10 |
from langchain_core.runnables import RunnableConfig
|
|
|
|
| 71 |
|
| 72 |
|
| 73 |
def call_model( state: AgentState, config: RunnableConfig):
|
| 74 |
+
# Modo 1)
|
| 75 |
# Invoke the model with the system prompt and the messages
|
| 76 |
+
#response = chat_with_tools.invoke(state["messages"], config)
|
| 77 |
+
|
| 78 |
+
# Modo 2)
|
| 79 |
+
# Create a copy to avoid modifying the original state and append instruction to the end
|
| 80 |
+
messages = state["messages"][:]
|
| 81 |
+
messages.append(
|
| 82 |
+
HumanMessage(content="Provide only the answer, without explanations or comments.")
|
| 83 |
+
) # Append instruction to the end
|
| 84 |
+
response = chat_with_tools.invoke(messages, config)
|
| 85 |
+
|
| 86 |
# We return a list, because this will get added to the existing messages state using the add_messages reducer
|
| 87 |
return {"messages": [response]}
|
| 88 |
|