Spaces:
Sleeping
Sleeping
Update agent.py
Browse files
agent.py
CHANGED
|
@@ -12,11 +12,10 @@ from langchain_community.document_loaders import ArxivLoader
|
|
| 12 |
|
| 13 |
from langchain_core.messages import SystemMessage, HumanMessage
|
| 14 |
from langchain_core.tools import tool
|
| 15 |
-
|
| 16 |
|
| 17 |
from langchain_google_genai import ChatGoogleGenerativeAI
|
| 18 |
|
| 19 |
-
from langchain.llms import HuggingFaceHub
|
| 20 |
#load_dotenv()
|
| 21 |
google_api_key = os.environ["GOOGLE_API_KEY"]
|
| 22 |
hf_api_key = os.environ["HF_TOKEN"]
|
|
@@ -107,19 +106,13 @@ def build_graph(provider: str = "google"):
|
|
| 107 |
if provider == "google":
|
| 108 |
# Google Gemini
|
| 109 |
llm = ChatGoogleGenerativeAI(model="gemini-2.0-flash", temperature=0,api_key=google_api_key)
|
| 110 |
-
elif provider == "huggingface":
|
| 111 |
-
llm = HuggingFaceHub(
|
| 112 |
-
repo_id="meta-llama/Llama-2-7b-chat-hf",
|
| 113 |
-
huggingfacehub_api_token=hf_api_key,
|
| 114 |
-
model_kwargs={"temperature": 0}
|
| 115 |
-
)
|
| 116 |
# Bind tools to LLM
|
| 117 |
llm_with_tools = llm.bind_tools(tools)
|
| 118 |
|
| 119 |
def assistant(state: MessagesState):
|
| 120 |
""" Use the tools to answer the query. you have add,subtract,multiply,divide,web_search,wikipedia_search,arxiv_search tools."""
|
| 121 |
response = llm_with_tools.invoke([system_message]+state["messages"])
|
| 122 |
-
|
| 123 |
return {"messages": state["messages"] + [response]}
|
| 124 |
|
| 125 |
|
|
|
|
| 12 |
|
| 13 |
from langchain_core.messages import SystemMessage, HumanMessage
|
| 14 |
from langchain_core.tools import tool
|
| 15 |
+
|
| 16 |
|
| 17 |
from langchain_google_genai import ChatGoogleGenerativeAI
|
| 18 |
|
|
|
|
| 19 |
#load_dotenv()
|
| 20 |
google_api_key = os.environ["GOOGLE_API_KEY"]
|
| 21 |
hf_api_key = os.environ["HF_TOKEN"]
|
|
|
|
| 106 |
if provider == "google":
|
| 107 |
# Google Gemini
|
| 108 |
llm = ChatGoogleGenerativeAI(model="gemini-2.0-flash", temperature=0,api_key=google_api_key)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 109 |
# Bind tools to LLM
|
| 110 |
llm_with_tools = llm.bind_tools(tools)
|
| 111 |
|
| 112 |
def assistant(state: MessagesState):
|
| 113 |
""" Use the tools to answer the query. you have add,subtract,multiply,divide,web_search,wikipedia_search,arxiv_search tools."""
|
| 114 |
response = llm_with_tools.invoke([system_message]+state["messages"])
|
| 115 |
+
time.sleep(4) # 무료 티어의 한계
|
| 116 |
return {"messages": state["messages"] + [response]}
|
| 117 |
|
| 118 |
|