Antoine101 commited on
Commit
2fae9eb
·
verified ·
1 Parent(s): 4e5e09b

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +25 -15
app.py CHANGED
@@ -15,6 +15,8 @@ from langchain_groq import ChatGroq
15
  from langchain_huggingface import HuggingFaceEndpoint, ChatHuggingFace
16
  from langchain_huggingface.llms import HuggingFacePipeline
17
  from langchain_ollama import ChatOllama
 
 
18
  from smolagents import (
19
  InferenceClientModel, LiteLLMModel, OpenAIServerModel, TransformersModel,
20
  CodeAgent,
@@ -64,28 +66,34 @@ HF_TOKEN = os.getenv("HF_TOKEN")
64
  #chat = ChatHuggingFace(llm=llm, verbose=True)
65
  #chat = ChatOllama(llm=hf_pipe).bind(skip_prompt=True)
66
 
67
- #tools = []
68
- #chat_with_tools = chat.bind_tools(tools)
69
 
70
- openai_api_key = os.getenv("OPENAI_API_KEY")
71
-
72
- model = OpenAIServerModel(
73
- api_key=openai_api_key,
74
- model_id="gpt-4.1"
 
 
 
 
 
 
 
 
 
 
75
  )
76
- tools = [
77
- DuckDuckGoSearchTool(),
78
- PythonInterpreterTool(),
79
- ]
80
 
81
  # load the system prompt from the file
82
  with open("system_prompt.txt", "r", encoding="utf-8") as f:
83
  system_prompt = f.read()
84
 
85
  print(system_prompt)
86
-
87
- # System message
88
- sys_msg = SystemMessage(content=system_prompt)
89
 
90
  def assistant(state: MessagesState):
91
  return {
@@ -106,7 +114,9 @@ class BasicAgent:
106
 
107
  def __call__(self, question: str) -> str:
108
  print(f"Agent received question (first 50 chars): {question[:50]}...")
109
- messages = [HumanMessage(content=question)]
 
 
110
  response = self.graph.invoke({"messages": messages})
111
  print(f"RESPONSE {response}")
112
  response = response['messages'][-1].content
 
15
  from langchain_huggingface import HuggingFaceEndpoint, ChatHuggingFace
16
  from langchain_huggingface.llms import HuggingFacePipeline
17
  from langchain_ollama import ChatOllama
18
+ from langchain_google_genai import ChatGoogleGenerativeAI
19
+ from langchain_core.rate_limiters import InMemoryRateLimiter
20
  from smolagents import (
21
  InferenceClientModel, LiteLLMModel, OpenAIServerModel, TransformersModel,
22
  CodeAgent,
 
66
  #chat = ChatHuggingFace(llm=llm, verbose=True)
67
  #chat = ChatOllama(llm=hf_pipe).bind(skip_prompt=True)
68
 
69
+ #openai_api_key = os.getenv("OPENAI_API_KEY")
 
70
 
71
+ #model = OpenAIServerModel(
72
+ # api_key=openai_api_key,
73
+ # model_id="gpt-4.1"
74
+ #)
75
+ #tools = [
76
+ # DuckDuckGoSearchTool(),
77
+ # PythonInterpreterTool(),
78
+ #]
79
+
80
+ rate_limiter = InMemoryRateLimiter(
81
+ # <-- Super slow! We can only make a request once every 4 seconds!!
82
+ requests_per_second=15/60,
83
+ # Wake up every 100 ms to check whether allowed to make a request,
84
+ check_every_n_seconds=0.1,
85
+ max_bucket_size=10, # Controls the maximum burst size.
86
  )
87
+
88
+ chat = ChatGoogleGenerativeAI(model="gemini-2.0-flash", temperature=0, rate_limiter=rate_limiter)
89
+ tools = []
90
+ chat_with_tools = chat.bind_tools(tools)
91
 
92
  # load the system prompt from the file
93
  with open("system_prompt.txt", "r", encoding="utf-8") as f:
94
  system_prompt = f.read()
95
 
96
  print(system_prompt)
 
 
 
97
 
98
  def assistant(state: MessagesState):
99
  return {
 
114
 
115
  def __call__(self, question: str) -> str:
116
  print(f"Agent received question (first 50 chars): {question[:50]}...")
117
+ messages = [
118
+ SystemMessage(content=system_prompt),
119
+ HumanMessage(content=question)]
120
  response = self.graph.invoke({"messages": messages})
121
  print(f"RESPONSE {response}")
122
  response = response['messages'][-1].content