fix: handle JSON serialization error and update text length limit in directFetchTool
Browse files
agent.py
CHANGED
|
@@ -15,7 +15,9 @@ from llama_index.llms.nebius import NebiusLLM
|
|
| 15 |
import tools
|
| 16 |
|
| 17 |
"""
|
| 18 |
-
TODO:
|
|
|
|
|
|
|
| 19 |
TODO: 4. Run HF Space and submit answers to the scoring server.
|
| 20 |
TODO: 5. Get a certificate for the course.
|
| 21 |
"""
|
|
@@ -70,11 +72,16 @@ class BasicAgent:
|
|
| 70 |
print(f"Agent received question (first 50 chars): {question[:50]}...")
|
| 71 |
|
| 72 |
if self.verbose:
|
| 73 |
-
|
|
|
|
|
|
|
|
|
|
| 74 |
|
| 75 |
answer = await self.workflow.run(user_msg=question)
|
| 76 |
print(f"Agent returning answer: {answer}")
|
| 77 |
-
|
|
|
|
|
|
|
| 78 |
|
| 79 |
def call_sync(self, question: str) -> str:
|
| 80 |
"""Synchronous wrapper for __call__ method (for compatibility with sync code)"""
|
|
|
|
| 15 |
import tools
|
| 16 |
|
| 17 |
"""
|
| 18 |
+
TODO: 3. Fix submission error 'Agent finished. Submitting 13 answers for user 'agsagds'...
|
| 19 |
+
Submitting 13 answers to: https://agents-course-unit4-scoring.hf.space/submit
|
| 20 |
+
An unexpected error occurred during submission: Object of type AgentOutput is not JSON serializable'
|
| 21 |
TODO: 4. Run HF Space and submit answers to the scoring server.
|
| 22 |
TODO: 5. Get a certificate for the course.
|
| 23 |
"""
|
|
|
|
| 72 |
print(f"Agent received question (first 50 chars): {question[:50]}...")
|
| 73 |
|
| 74 |
if self.verbose:
|
| 75 |
+
answer = await self.stream_answers(question)
|
| 76 |
+
if answer is None:
|
| 77 |
+
return ''
|
| 78 |
+
return str(answer)
|
| 79 |
|
| 80 |
answer = await self.workflow.run(user_msg=question)
|
| 81 |
print(f"Agent returning answer: {answer}")
|
| 82 |
+
if answer is None:
|
| 83 |
+
return ''
|
| 84 |
+
return str(answer)
|
| 85 |
|
| 86 |
def call_sync(self, question: str) -> str:
|
| 87 |
"""Synchronous wrapper for __call__ method (for compatibility with sync code)"""
|
tools.py
CHANGED
|
@@ -79,7 +79,7 @@ async def directFetchTool(url: str, offset: int = 0) -> str:
|
|
| 79 |
offset: position from start of the web page content. Default = 0
|
| 80 |
Returns:
|
| 81 |
The extracted meaningful text content of the webpage as a string.
|
| 82 |
-
If result length more then
|
| 83 |
If an error occurs, returns an empty string.
|
| 84 |
|
| 85 |
Example:
|
|
@@ -117,8 +117,8 @@ async def directFetchTool(url: str, offset: int = 0) -> str:
|
|
| 117 |
lines = [line.strip() for line in text.split('\n') if line.strip()]
|
| 118 |
text = '\n'.join(lines)
|
| 119 |
|
| 120 |
-
if len(text)>
|
| 121 |
-
return f"Result is too big: {len(text)} chars. Return only slice ${offset}:${offset+
|
| 122 |
|
| 123 |
return text
|
| 124 |
except httpx.HTTPStatusError as e:
|
|
|
|
| 79 |
offset: position from start of the web page content. Default = 0
|
| 80 |
Returns:
|
| 81 |
The extracted meaningful text content of the webpage as a string.
|
| 82 |
+
If result length more then 10000 symbols than return only first 10000. Use `offset` option to show another part of the web page content.
|
| 83 |
If an error occurs, returns an empty string.
|
| 84 |
|
| 85 |
Example:
|
|
|
|
| 117 |
lines = [line.strip() for line in text.split('\n') if line.strip()]
|
| 118 |
text = '\n'.join(lines)
|
| 119 |
|
| 120 |
+
if len(text)>10000:
|
| 121 |
+
return f"Result is too big: {len(text)} chars. Return only slice ${offset}:${offset+10000}: \n\n" + text[offset:offset+10000]
|
| 122 |
|
| 123 |
return text
|
| 124 |
except httpx.HTTPStatusError as e:
|