Spaces:
Running
Running
Refactor API key
Browse files- agent/agent.py +7 -4
agent/agent.py
CHANGED
|
@@ -1,5 +1,5 @@
|
|
| 1 |
import streamlit as st
|
| 2 |
-
import sys
|
| 3 |
from langchain_openai import ChatOpenAI
|
| 4 |
from langchain.agents import create_openai_tools_agent, AgentExecutor
|
| 5 |
from langchain_core.prompts import ChatPromptTemplate, MessagesPlaceholder
|
|
@@ -7,6 +7,9 @@ from langchain_core.tools import tool
|
|
| 7 |
from langchain_experimental.tools.python.tool import PythonREPLTool
|
| 8 |
from . import utils
|
| 9 |
|
|
|
|
|
|
|
|
|
|
| 10 |
|
| 11 |
python_repl = PythonREPLTool(python_path=sys.executable)
|
| 12 |
|
|
@@ -119,13 +122,13 @@ def initialize_agent():
|
|
| 119 |
|
| 120 |
try:
|
| 121 |
gemini_client = ChatOpenAI(
|
| 122 |
-
api_key=
|
| 123 |
base_url="https://generativelanguage.googleapis.com/v1beta/openai/",
|
| 124 |
model="gemini-2.5-flash",
|
| 125 |
temperature=0.2
|
| 126 |
)
|
| 127 |
except (KeyError, FileNotFoundError):
|
| 128 |
-
st.error("GOOGLE_API_KEY not found.
|
| 129 |
st.stop()
|
| 130 |
|
| 131 |
# --- Tool Definitions ---
|
|
@@ -186,4 +189,4 @@ def initialize_agent():
|
|
| 186 |
main_agent = create_openai_tools_agent(llm=gemini_client, tools=tools, prompt=ma_prompt)
|
| 187 |
agent_executor = AgentExecutor(agent=main_agent, tools=tools, verbose=True, return_intermediate_steps=True)
|
| 188 |
|
| 189 |
-
return agent_executor
|
|
|
|
| 1 |
import streamlit as st
|
| 2 |
+
import sys, os
|
| 3 |
from langchain_openai import ChatOpenAI
|
| 4 |
from langchain.agents import create_openai_tools_agent, AgentExecutor
|
| 5 |
from langchain_core.prompts import ChatPromptTemplate, MessagesPlaceholder
|
|
|
|
| 7 |
from langchain_experimental.tools.python.tool import PythonREPLTool
|
| 8 |
from . import utils
|
| 9 |
|
| 10 |
+
GEMINI_API_KEY = os.environ["GEMINI_API_KEY"]
|
| 11 |
+
|
| 12 |
+
|
| 13 |
|
| 14 |
python_repl = PythonREPLTool(python_path=sys.executable)
|
| 15 |
|
|
|
|
| 122 |
|
| 123 |
try:
|
| 124 |
gemini_client = ChatOpenAI(
|
| 125 |
+
api_key=GEMINI_API_KEY,
|
| 126 |
base_url="https://generativelanguage.googleapis.com/v1beta/openai/",
|
| 127 |
model="gemini-2.5-flash",
|
| 128 |
temperature=0.2
|
| 129 |
)
|
| 130 |
except (KeyError, FileNotFoundError):
|
| 131 |
+
st.error("GOOGLE_API_KEY not found.")
|
| 132 |
st.stop()
|
| 133 |
|
| 134 |
# --- Tool Definitions ---
|
|
|
|
| 189 |
main_agent = create_openai_tools_agent(llm=gemini_client, tools=tools, prompt=ma_prompt)
|
| 190 |
agent_executor = AgentExecutor(agent=main_agent, tools=tools, verbose=True, return_intermediate_steps=True)
|
| 191 |
|
| 192 |
+
return agent_executor
|