Romain Fayoux
commited on
Commit
·
f087af6
1
Parent(s):
b831214
Test langchain agent
Browse files- langchain_agent.py +17 -1
- requirements.txt +1 -0
langchain_agent.py
CHANGED
|
@@ -1,7 +1,16 @@
|
|
|
|
|
|
|
|
|
|
|
| 1 |
from langchain.agents import create_agent
|
|
|
|
| 2 |
from langgraph.checkpoint.memory import InMemorySaver
|
| 3 |
from langchain_community.tools import DuckDuckGoSearchRun
|
|
|
|
|
|
|
|
|
|
| 4 |
|
|
|
|
|
|
|
| 5 |
|
| 6 |
system_prompt = """finish your answer with the following template: FINAL ANSWER: [YOUR FINAL ANSWER].
|
| 7 |
YOUR FINAL ANSWER should be a number OR as few words as possible OR a comma separated list of numbers and/or strings.
|
|
@@ -11,8 +20,15 @@ If you are asked for a comma separated list, apply the above rules depending of
|
|
| 11 |
|
| 12 |
|
| 13 |
agent = create_agent(
|
| 14 |
-
model="
|
| 15 |
tools=[DuckDuckGoSearchRun()],
|
| 16 |
system_prompt=system_prompt,
|
| 17 |
checkpointer=InMemorySaver(),
|
| 18 |
)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import os
|
| 2 |
+
from dotenv import load_dotenv
|
| 3 |
+
from gradio.external import load_blocks_from_huggingface
|
| 4 |
from langchain.agents import create_agent
|
| 5 |
+
from langchain_community.tools.ddg_search.tool import DuckDuckGoSearchResults
|
| 6 |
from langgraph.checkpoint.memory import InMemorySaver
|
| 7 |
from langchain_community.tools import DuckDuckGoSearchRun
|
| 8 |
+
from google.ai.generativelanguage_v1beta.types import Tool as GenAITool
|
| 9 |
+
from langchain.messages import HumanMessage, AIMessage, SystemMessage
|
| 10 |
+
from numpy import load
|
| 11 |
|
| 12 |
+
load_dotenv()
|
| 13 |
+
os.environ["GOOGLE_API_KEY"] = os.getenv("GEMINI_API_KEY")
|
| 14 |
|
| 15 |
system_prompt = """finish your answer with the following template: FINAL ANSWER: [YOUR FINAL ANSWER].
|
| 16 |
YOUR FINAL ANSWER should be a number OR as few words as possible OR a comma separated list of numbers and/or strings.
|
|
|
|
| 20 |
|
| 21 |
|
| 22 |
agent = create_agent(
|
| 23 |
+
model="google_genai:gemini-2.5-flash",
|
| 24 |
tools=[DuckDuckGoSearchRun()],
|
| 25 |
system_prompt=system_prompt,
|
| 26 |
checkpointer=InMemorySaver(),
|
| 27 |
)
|
| 28 |
+
|
| 29 |
+
response = agent.invoke(
|
| 30 |
+
{"messages": [{"role": "user", "content": "what is the weather in sf"}]},
|
| 31 |
+
{"configurable": {"thread_id": "1"}},
|
| 32 |
+
)
|
| 33 |
+
|
| 34 |
+
print(response)
|
requirements.txt
CHANGED
|
@@ -16,3 +16,4 @@ langchain
|
|
| 16 |
langchain-google-genai
|
| 17 |
duckduckgo-search
|
| 18 |
langchain-community
|
|
|
|
|
|
| 16 |
langchain-google-genai
|
| 17 |
duckduckgo-search
|
| 18 |
langchain-community
|
| 19 |
+
python-dotenv
|