test_search.py 712 B

12345678910111213141516171819202122232425
  1. import asyncio
  2. import sys
  3. import io
  4. # 设置 stdout 编码为 UTF-8
  5. sys.stdout = io.TextIOWrapper(sys.stdout.buffer, encoding='utf-8')
  6. sys.path.insert(0, '.')
  7. async def test():
  8. from agent.tools.builtin.search import search_posts
  9. print("Testing search_posts with gzh channel...")
  10. result = await search_posts(keyword='Midjourney v8', channel='gzh', max_count=20)
  11. print(f'Title: {result.title}')
  12. print(f'Has error: {result.error is not None}')
  13. if result.error:
  14. print(f'Error message: {result.error}')
  15. else:
  16. print(f'Output length: {len(result.output)} chars')
  17. print(f'Has images: {len(result.images) > 0}')
  18. if __name__ == '__main__':
  19. asyncio.run(test())