Spaces:
Sleeping
Sleeping
File size: 1,771 Bytes
c869a11 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 |
from typing import Optional, Type, List
from langchain.tools import BaseTool
from pydantic import BaseModel
from app.models import Stories, Comments, Content
from app.functions import get_hn_stories
from app.functions import get_relevant_comments
from app.functions import get_story_content
class StoriesTool(BaseTool):
name = "get_stories"
description = "Gets stories from Hacker News. The stories are described by a 'story_id', a 'title', a 'url' and" \
" a 'score'."
def _run(self, limit: int = 5, keywords: List[str] = None, story_type: str = "top"):
stories = get_hn_stories(limit, keywords, story_type)
return stories
def _arun(self, limit: int = 5, keywords: List[str] = None, story_type: str = "top"):
stories = get_hn_stories(limit, keywords, story_type)
return stories
args_schema: Optional[Type[BaseModel]] = Stories
class CommentsTool(BaseTool):
name = "get_comments"
description = "Gets comments from a specific Hacker News story"
def _run(self, story_id: int, limit: int = 10):
comments = get_relevant_comments(story_id, limit)
return comments
def _arun(self, story_id: int, limit: int = 10):
comments = get_relevant_comments(story_id, limit)
return comments
args_schema: Optional[Type[BaseModel]] = Comments
class ContentTool(BaseTool):
name = "get_content"
description = "Gets the Hacker News story content from a URL"
def _run(self, story_url: str):
story_content = get_story_content(story_url)
return story_content
def _arun(self, story_url: str):
story_content = get_story_content(story_url)
return story_content
args_schema: Optional[Type[BaseModel]] = Content |