Update agent.py
Browse files
agent.py
CHANGED
@@ -1,5 +1,5 @@
|
|
1 |
from typing import Annotated, Sequence, TypedDict
|
2 |
-
from langchain_community.llms import HuggingFaceHub
|
3 |
from langchain_core.messages import BaseMessage, HumanMessage, AIMessage
|
4 |
from langgraph.graph import StateGraph, END
|
5 |
from langchain_core.agents import AgentAction, AgentFinish
|
@@ -14,14 +14,19 @@ class AgentState(TypedDict):
|
|
14 |
|
15 |
def build_graph():
|
16 |
# 1. 初始化模型 - 使用HuggingFace免费接口
|
17 |
-
llm =
|
18 |
-
|
19 |
-
|
|
|
|
|
|
|
|
|
|
|
20 |
)
|
21 |
|
22 |
# 2. 创建ReAct代理
|
23 |
prompt = hub.pull("hwchase17/react")
|
24 |
-
tools = get_tools()
|
25 |
agent = create_react_agent(llm, tools, prompt)
|
26 |
|
27 |
# 3. 定义节点行为
|
|
|
1 |
from typing import Annotated, Sequence, TypedDict
|
2 |
+
from langchain_community.llms import HuggingFaceHub,HuggingFaceEndpoint
|
3 |
from langchain_core.messages import BaseMessage, HumanMessage, AIMessage
|
4 |
from langgraph.graph import StateGraph, END
|
5 |
from langchain_core.agents import AgentAction, AgentFinish
|
|
|
14 |
|
15 |
def build_graph():
|
16 |
# 1. 初始化模型 - 使用HuggingFace免费接口
|
17 |
+
llm = HuggingFaceEndpoint(
|
18 |
+
endpoint_url="https://api-inference.huggingface.co/models/mistralai/Mistral-7B-Instruct-v0.2",
|
19 |
+
task="text-generation",
|
20 |
+
model_kwargs={
|
21 |
+
"temperature": 0.1,
|
22 |
+
"max_new_tokens": 500,
|
23 |
+
"repetition_penalty": 1.2
|
24 |
+
}
|
25 |
)
|
26 |
|
27 |
# 2. 创建ReAct代理
|
28 |
prompt = hub.pull("hwchase17/react")
|
29 |
+
tools = get_tools()
|
30 |
agent = create_react_agent(llm, tools, prompt)
|
31 |
|
32 |
# 3. 定义节点行为
|