hanshan1988 commited on
Commit
da6f6e6
·
verified ·
1 Parent(s): 1cde839

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +9 -2
app.py CHANGED
@@ -129,13 +129,14 @@ ask_wiki(query: str) -> str:
129
  A single string containing the retrieved article from Wikipedia.
130
 
131
  youtube_transcript(url: str) -> str:
 
132
  Args:
133
  url: input youtube url.
134
  Returns:
135
  A single string containing the transcript of the youtube videos.
136
  """
137
  sys_msg = SystemMessage(
138
- content=f"You are a helpful assistant at answering user questions. You can access provided tools:\n{textual_description_of_tool}\n"
139
  )
140
 
141
  return {
@@ -161,6 +162,11 @@ builder.add_conditional_edges(
161
  builder.add_edge("tools", "assistant")
162
  agent_graph = builder.compile()
163
 
 
 
 
 
 
164
 
165
  class BasicAgent:
166
  def __init__(self):
@@ -182,7 +188,8 @@ class BasicAgent:
182
  ]
183
  response = await agent_graph.ainvoke({"messages": messages}, config={"recursion_limit": 5})
184
  response_text = response['messages'][-1].content
185
- return response_text.split('</think>')[-1]
 
186
 
187
 
188
  async def run_and_submit_all( profile: gr.OAuthProfile | None):
 
129
  A single string containing the retrieved article from Wikipedia.
130
 
131
  youtube_transcript(url: str) -> str:
132
+ Fetch the transcript of a youtube video.
133
  Args:
134
  url: input youtube url.
135
  Returns:
136
  A single string containing the transcript of the youtube videos.
137
  """
138
  sys_msg = SystemMessage(
139
+ content=f"You are a helpful assistant at answering user questions. Your final answer will be between <answers> tags. You can access provided tools:\n{textual_description_of_tool}\n"
140
  )
141
 
142
  return {
 
162
  builder.add_edge("tools", "assistant")
163
  agent_graph = builder.compile()
164
 
165
+ def extract_answer(text):
166
+ match = re.search(r'<answer>(.*?)</answer>', text, re.DOTALL)
167
+ if match:
168
+ return match.group(1).strip()
169
+ return 'None'
170
 
171
  class BasicAgent:
172
  def __init__(self):
 
188
  ]
189
  response = await agent_graph.ainvoke({"messages": messages}, config={"recursion_limit": 5})
190
  response_text = response['messages'][-1].content
191
+ # return response_text.split('</think>')[-1]
192
+ return extract_answer(response_text)
193
 
194
 
195
  async def run_and_submit_all( profile: gr.OAuthProfile | None):