Use langchain instead of custom code
Browse files
agents.py
CHANGED
@@ -6,6 +6,7 @@ from langgraph.prebuilt import tools_condition
|
|
6 |
from langgraph.prebuilt import ToolNode
|
7 |
from langchain_google_genai import ChatGoogleGenerativeAI
|
8 |
from langchain_groq import ChatGroq
|
|
|
9 |
from langchain_huggingface import ChatHuggingFace, HuggingFaceEndpoint, HuggingFaceEmbeddings
|
10 |
from langchain_community.tools.tavily_search import TavilySearchResults
|
11 |
from langchain_community.document_loaders import WikipediaLoader
|
@@ -174,26 +175,11 @@ def build_graph(provider: str = "rwkv"):
|
|
174 |
# --- BEGIN RWKV SETUP ---
|
175 |
title = "rwkv7-g1-0.1b-20250307-ctx4096"
|
176 |
pth = hf_hub_download(repo_id="BlinkDL/rwkv7-g1", filename=f"{title}.pth")
|
177 |
-
|
178 |
-
|
179 |
-
|
180 |
-
|
181 |
-
|
182 |
-
class ChatRWKV:
|
183 |
-
def __init__(self, pipe):
|
184 |
-
self.pipe = pipe
|
185 |
-
def invoke(self, messages):
|
186 |
-
prompt = "\n".join(m.content for m in messages)
|
187 |
-
return self.pipe(
|
188 |
-
prompt,
|
189 |
-
temperature=0.0,
|
190 |
-
top_p=0.95,
|
191 |
-
max_tokens=256,
|
192 |
-
)
|
193 |
-
def bind_tools(self, tools):
|
194 |
-
return self
|
195 |
-
|
196 |
-
llm = ChatRWKV(rwkv_pipe)
|
197 |
# --- END RWKV SETUP ---
|
198 |
else:
|
199 |
raise ValueError("Invalid provider. Choose 'google', 'groq' or 'huggingface'.")
|
|
|
6 |
from langgraph.prebuilt import ToolNode
|
7 |
from langchain_google_genai import ChatGoogleGenerativeAI
|
8 |
from langchain_groq import ChatGroq
|
9 |
+
from langchain.llms import RWKV
|
10 |
from langchain_huggingface import ChatHuggingFace, HuggingFaceEndpoint, HuggingFaceEmbeddings
|
11 |
from langchain_community.tools.tavily_search import TavilySearchResults
|
12 |
from langchain_community.document_loaders import WikipediaLoader
|
|
|
175 |
# --- BEGIN RWKV SETUP ---
|
176 |
title = "rwkv7-g1-0.1b-20250307-ctx4096"
|
177 |
pth = hf_hub_download(repo_id="BlinkDL/rwkv7-g1", filename=f"{title}.pth")
|
178 |
+
model_path = pth.replace(".pth", "")
|
179 |
+
llm = RWKV(
|
180 |
+
model=model_path,
|
181 |
+
strategy="cpu fp32",
|
182 |
+
)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
183 |
# --- END RWKV SETUP ---
|
184 |
else:
|
185 |
raise ValueError("Invalid provider. Choose 'google', 'groq' or 'huggingface'.")
|