Ahmud commited on
Commit
3edd2ff
·
verified ·
1 Parent(s): b9d997e

Update agent.py

Browse files
Files changed (1) hide show
  1. agent.py +6 -22
agent.py CHANGED
@@ -19,28 +19,12 @@ from langchain_core.runnables import RunnableConfig # for LangSmith tracking
19
  langsmith_api_key = os.getenv("LANGSMITH_API_KEY")
20
  langsmith_tracing = os.getenv("LANGSMITH_TRACING")
21
 
22
- def get_llm():
23
- api_keys = [os.getenv("OPENROUTER_API_KEY"), os.getenv("OPENROUTER_API_KEY_1")]
24
- last_exception = None
25
- for key in api_keys:
26
- if not key:
27
- continue
28
- try:
29
- llm = ChatOpenAI(
30
- base_url="https://openrouter.ai/api/v1",
31
- api_key=key,
32
- model="moonshotai/kimi-k2:free",
33
- temperature=1
34
- )
35
- # Optionally, test the key with a trivial call to ensure it's valid
36
- # llm.invoke([SystemMessage(content="ping")])
37
- return llm
38
- except Exception as e:
39
- last_exception = e
40
- continue
41
- raise RuntimeError(f"All OpenRouter API keys failed: {last_exception}")
42
-
43
- llm = get_llm()
44
  python_tool = PythonAstREPLTool()
45
  search_tool = BraveSearch.from_api_key(
46
  api_key=os.getenv("BRAVE_SEARCH_API"),
 
19
  langsmith_api_key = os.getenv("LANGSMITH_API_KEY")
20
  langsmith_tracing = os.getenv("LANGSMITH_TRACING")
21
 
22
+ llm = ChatOpenAI(
23
+ base_url="https://openrouter.ai/api/v1",
24
+ api_key=os.getenv("OPENROUTER_API_KEY"),
25
+ model="moonshotai/kimi-k2:free", # Model must support function calling in OpenRouter
26
+ temperature=1
27
+ )
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
28
  python_tool = PythonAstREPLTool()
29
  search_tool = BraveSearch.from_api_key(
30
  api_key=os.getenv("BRAVE_SEARCH_API"),