Spaces:
Runtime error
Runtime error
Updated tool docstrings and simplified return values.
Browse files- functions/tools.py +21 -34
functions/tools.py
CHANGED
|
@@ -28,7 +28,7 @@ def get_feed(website: str, n: int = 3) -> list:
|
|
| 28 |
'''Gets RSS feed content from a given website. Can take a website or RSS
|
| 29 |
feed URL directly, or the name of a website. Will attempt to find RSS
|
| 30 |
feed and return title, summary and link to full article for most recent
|
| 31 |
-
n items in feed. This function is slow
|
| 32 |
the user wants to check a feed for new content, or asks for content from a
|
| 33 |
feed that you have not retrieved yet.
|
| 34 |
|
|
@@ -88,20 +88,19 @@ def get_feed(website: str, n: int = 3) -> list:
|
|
| 88 |
|
| 89 |
|
| 90 |
def context_search(query: str, article_title: str = None) -> list[Tuple[float, str]]:
|
| 91 |
-
'''Searches for context relevant to query
|
| 92 |
-
|
| 93 |
-
|
| 94 |
-
|
| 95 |
-
|
| 96 |
-
currently in the cache.
|
| 97 |
|
| 98 |
Ags:
|
| 99 |
query: user query to find context for
|
| 100 |
article_title: optional, use this argument to search only for
|
| 101 |
-
context from a specific
|
| 102 |
|
| 103 |
Returns:
|
| 104 |
-
|
| 105 |
'''
|
| 106 |
|
| 107 |
logger = logging.getLogger(__name__ + 'context_search')
|
|
@@ -122,25 +121,19 @@ def context_search(query: str, article_title: str = None) -> list[Tuple[float, s
|
|
| 122 |
|
| 123 |
logger.info('Retrieved %s chunks for "%s"', len(results), query)
|
| 124 |
|
| 125 |
-
|
| 126 |
-
|
| 127 |
-
for result in results:
|
| 128 |
-
contexts.append((result.score, result.data))
|
| 129 |
-
|
| 130 |
-
return contexts
|
| 131 |
|
| 132 |
|
| 133 |
def find_article(query: str) -> list[Tuple[float, str]]:
|
| 134 |
'''Uses vector search to find the most likely title of the article
|
| 135 |
referred to by query. Use this function if the user is asking about
|
| 136 |
-
|
| 137 |
|
| 138 |
Args:
|
| 139 |
-
query: query to to find source article for
|
| 140 |
|
| 141 |
Returns:
|
| 142 |
-
|
| 143 |
-
[(relevance score, 'article title')]
|
| 144 |
'''
|
| 145 |
|
| 146 |
logger = logging.getLogger(__name__ + 'context_search')
|
|
@@ -161,23 +154,17 @@ def find_article(query: str) -> list[Tuple[float, str]]:
|
|
| 161 |
|
| 162 |
logger.info('Retrieved %s chunks for "%s"', len(results), query)
|
| 163 |
|
| 164 |
-
|
| 165 |
-
|
| 166 |
-
for result in results:
|
| 167 |
-
contexts.append((result.score, result.metadata['namespace']))
|
| 168 |
-
|
| 169 |
-
return contexts
|
| 170 |
|
| 171 |
|
| 172 |
def get_summary(title: str) -> str:
|
| 173 |
-
'''Uses article title to
|
| 174 |
|
| 175 |
Args:
|
| 176 |
-
title: title of article
|
| 177 |
|
| 178 |
Returns:
|
| 179 |
-
Short summary of article content.
|
| 180 |
-
if summary does not exist.
|
| 181 |
'''
|
| 182 |
|
| 183 |
logger = logging.getLogger(__name__ + '.get_summary()')
|
|
@@ -196,17 +183,17 @@ def get_summary(title: str) -> str:
|
|
| 196 |
return summary
|
| 197 |
|
| 198 |
logger.info('Could not find summary for: "%s"', title)
|
| 199 |
-
return 'No
|
| 200 |
|
| 201 |
|
| 202 |
def get_link(title: str) -> str:
|
| 203 |
-
'''Uses article title to
|
| 204 |
|
| 205 |
Args:
|
| 206 |
-
title: title of article
|
| 207 |
|
| 208 |
Returns:
|
| 209 |
-
Article webpage URL.
|
| 210 |
'''
|
| 211 |
|
| 212 |
logger = logging.getLogger(__name__ + '.get_link()')
|
|
@@ -225,4 +212,4 @@ def get_link(title: str) -> str:
|
|
| 225 |
return link
|
| 226 |
|
| 227 |
logger.info('Could not find link for: "%s"', title)
|
| 228 |
-
return 'No
|
|
|
|
| 28 |
'''Gets RSS feed content from a given website. Can take a website or RSS
|
| 29 |
feed URL directly, or the name of a website. Will attempt to find RSS
|
| 30 |
feed and return title, summary and link to full article for most recent
|
| 31 |
+
n items in feed. This function is slow and resource heavy, only call it when
|
| 32 |
the user wants to check a feed for new content, or asks for content from a
|
| 33 |
feed that you have not retrieved yet.
|
| 34 |
|
|
|
|
| 88 |
|
| 89 |
|
| 90 |
def context_search(query: str, article_title: str = None) -> list[Tuple[float, str]]:
|
| 91 |
+
'''Searches for context relevant to query. Use this Function to search
|
| 92 |
+
for additional general information if needed before answering the user's question
|
| 93 |
+
about an article. If article_title is provided the search will only return
|
| 94 |
+
results from that article. If article_title is omitted, the search will
|
| 95 |
+
include all articles currently in the cache.
|
|
|
|
| 96 |
|
| 97 |
Ags:
|
| 98 |
query: user query to find context for
|
| 99 |
article_title: optional, use this argument to search only for
|
| 100 |
+
context from a specific article, defaults to None
|
| 101 |
|
| 102 |
Returns:
|
| 103 |
+
Text relevant to the query
|
| 104 |
'''
|
| 105 |
|
| 106 |
logger = logging.getLogger(__name__ + 'context_search')
|
|
|
|
| 121 |
|
| 122 |
logger.info('Retrieved %s chunks for "%s"', len(results), query)
|
| 123 |
|
| 124 |
+
return results[0].data
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 125 |
|
| 126 |
|
| 127 |
def find_article(query: str) -> list[Tuple[float, str]]:
|
| 128 |
'''Uses vector search to find the most likely title of the article
|
| 129 |
referred to by query. Use this function if the user is asking about
|
| 130 |
+
an article, but it is not clear what the exact title of the article is.
|
| 131 |
|
| 132 |
Args:
|
| 133 |
+
query: query to to find source article tile for
|
| 134 |
|
| 135 |
Returns:
|
| 136 |
+
Article title
|
|
|
|
| 137 |
'''
|
| 138 |
|
| 139 |
logger = logging.getLogger(__name__ + 'context_search')
|
|
|
|
| 154 |
|
| 155 |
logger.info('Retrieved %s chunks for "%s"', len(results), query)
|
| 156 |
|
| 157 |
+
return results[0].metadata['namespace']
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 158 |
|
| 159 |
|
| 160 |
def get_summary(title: str) -> str:
|
| 161 |
+
'''Uses article title to retrieve summary of article content.
|
| 162 |
|
| 163 |
Args:
|
| 164 |
+
title: exact title of article
|
| 165 |
|
| 166 |
Returns:
|
| 167 |
+
Short summary of article content.
|
|
|
|
| 168 |
'''
|
| 169 |
|
| 170 |
logger = logging.getLogger(__name__ + '.get_summary()')
|
|
|
|
| 183 |
return summary
|
| 184 |
|
| 185 |
logger.info('Could not find summary for: "%s"', title)
|
| 186 |
+
return f'No article called "{title}". Make sure you have the correct title.'
|
| 187 |
|
| 188 |
|
| 189 |
def get_link(title: str) -> str:
|
| 190 |
+
'''Uses article title to look up direct link to article content webpage.
|
| 191 |
|
| 192 |
Args:
|
| 193 |
+
title: exact title of article
|
| 194 |
|
| 195 |
Returns:
|
| 196 |
+
Article webpage URL.
|
| 197 |
'''
|
| 198 |
|
| 199 |
logger = logging.getLogger(__name__ + '.get_link()')
|
|
|
|
| 212 |
return link
|
| 213 |
|
| 214 |
logger.info('Could not find link for: "%s"', title)
|
| 215 |
+
return f'No article called "{title}". Make sure you have the correct title.'
|