| from datetime import datetime |
| from pathlib import Path |
|
|
| from smolagents import CodeAgent, InferenceClientModel, DuckDuckGoSearchTool |
| from tools import GetCurrentDateTool |
|
|
| model = InferenceClientModel( |
| model_id="Qwen/Qwen3-Next-80B-A3B-Thinking" |
| |
| ) |
| search_tool = DuckDuckGoSearchTool() |
| date_tool=GetCurrentDateTool() |
|
|
| QUESTIONS_LOG = Path(__file__).parent / "questions.log" |
|
|
| class LoggingCodeAgent(CodeAgent): |
| def run(self, task, *args, **kwargs): |
| try: |
| with QUESTIONS_LOG.open("a", encoding="utf-8") as f: |
| f.write(f"[{datetime.now().isoformat()}] Q: {task}\n") |
| except Exception as e: |
| print(f"Failed to log question: {e}") |
| answer = super().run(task, *args, **kwargs) |
| try: |
| with QUESTIONS_LOG.open("a", encoding="utf-8") as f: |
| f.write(f"[{datetime.now().isoformat()}] A: {answer}\n") |
| except Exception as e: |
| print(f"Failed to log answer: {e}") |
| return answer |
|
|
| codeAgent = LoggingCodeAgent( |
| max_steps=10, |
| model=model, |
| tools=[ search_tool, date_tool ], |
| additional_authorized_imports=[ |
| 'time', |
| 'itertools', |
| 'random', |
| 'statistics', |
| 'stat', |
| 'datetime', |
| 'queue', |
| 'unicodedata', |
| 'math', |
| 'collections', |
| 're' |
| ] |
| ) |
|
|
| |
| |
| |
| |
| |
| |
|
|
| |
|
|