Spaces:
Runtime error
Runtime error
Added tool to get article link from Redis cache.
Browse files- assets/text.py +1 -1
- functions/tools.py +29 -0
- rss_server.py +36 -4
assets/text.py
CHANGED
|
@@ -28,5 +28,5 @@ DESCRIPTION = ('''
|
|
| 28 |
3. `find_article()`: Uses vector search on article content to find title of article
|
| 29 |
that user is referring to.
|
| 30 |
4. `get_summary()`: Gets article summary from Redis cache using article title.
|
| 31 |
-
|
| 32 |
''')
|
|
|
|
| 28 |
3. `find_article()`: Uses vector search on article content to find title of article
|
| 29 |
that user is referring to.
|
| 30 |
4. `get_summary()`: Gets article summary from Redis cache using article title.
|
| 31 |
+
5. `get_link()`: Gets article link from Redis cache using article title.
|
| 32 |
''')
|
functions/tools.py
CHANGED
|
@@ -197,3 +197,32 @@ def get_summary(title: str) -> str:
|
|
| 197 |
|
| 198 |
logger.info('Could not find summary for: "%s"', title)
|
| 199 |
return 'No summary found'
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 197 |
|
| 198 |
logger.info('Could not find summary for: "%s"', title)
|
| 199 |
return 'No summary found'
|
| 200 |
+
|
| 201 |
+
|
| 202 |
+
def get_link(title: str) -> str:
|
| 203 |
+
'''Uses article title to get link to content webpage.
|
| 204 |
+
|
| 205 |
+
Args:
|
| 206 |
+
title: title of article to get link for
|
| 207 |
+
|
| 208 |
+
Returns:
|
| 209 |
+
Article webpage URL. Returns "No link found" if link does not exist.
|
| 210 |
+
'''
|
| 211 |
+
|
| 212 |
+
logger = logging.getLogger(__name__ + '.get_link()')
|
| 213 |
+
|
| 214 |
+
redis = Redis(
|
| 215 |
+
url='https://sensible-midge-19304.upstash.io',
|
| 216 |
+
token=os.environ['UPSTASH_REDIS_KEY']
|
| 217 |
+
)
|
| 218 |
+
|
| 219 |
+
cache_key = f'{title} link'
|
| 220 |
+
link = redis.get(cache_key)
|
| 221 |
+
|
| 222 |
+
if link:
|
| 223 |
+
|
| 224 |
+
logger.info('Got link for "%s": %s', title, link)
|
| 225 |
+
return link
|
| 226 |
+
|
| 227 |
+
logger.info('Could not find link for: "%s"', title)
|
| 228 |
+
return 'No summary found'
|
rss_server.py
CHANGED
|
@@ -41,6 +41,7 @@ with gr.Blocks() as demo:
|
|
| 41 |
gr.HTML(text.TITLE)
|
| 42 |
gr.Markdown(text.DESCRIPTION)
|
| 43 |
|
|
|
|
| 44 |
# Log output
|
| 45 |
with gr.Row():
|
| 46 |
dialog_output = gr.Textbox(label='Server logs', lines=7, max_lines=5)
|
|
@@ -53,6 +54,7 @@ with gr.Blocks() as demo:
|
|
| 53 |
show_api=False
|
| 54 |
)
|
| 55 |
|
|
|
|
| 56 |
# Get feed tool
|
| 57 |
gr.Markdown('### 1. `get_feed()`')
|
| 58 |
website_url = gr.Textbox('slashdot', label='Website')
|
|
@@ -69,6 +71,7 @@ with gr.Blocks() as demo:
|
|
| 69 |
api_name='Get RSS feed content'
|
| 70 |
)
|
| 71 |
|
|
|
|
| 72 |
# Vector search tool
|
| 73 |
gr.Markdown('### 2. `context_search()`')
|
| 74 |
|
|
@@ -95,6 +98,7 @@ with gr.Blocks() as demo:
|
|
| 95 |
api_name='Context vector search'
|
| 96 |
)
|
| 97 |
|
|
|
|
| 98 |
# Find article tool
|
| 99 |
gr.Markdown('### 3. `find_article()`')
|
| 100 |
|
|
@@ -104,8 +108,8 @@ with gr.Blocks() as demo:
|
|
| 104 |
)
|
| 105 |
article_search_output = gr.Textbox(
|
| 106 |
label='Article search results',
|
| 107 |
-
lines=
|
| 108 |
-
max_lines=
|
| 109 |
)
|
| 110 |
|
| 111 |
with gr.Row():
|
|
@@ -121,6 +125,7 @@ with gr.Blocks() as demo:
|
|
| 121 |
api_name='Article vector search'
|
| 122 |
)
|
| 123 |
|
|
|
|
| 124 |
# Get summary tool
|
| 125 |
gr.Markdown('### 4. `get_summary()`')
|
| 126 |
|
|
@@ -130,8 +135,8 @@ with gr.Blocks() as demo:
|
|
| 130 |
)
|
| 131 |
article_summary = gr.Textbox(
|
| 132 |
label='Article summary',
|
| 133 |
-
lines=
|
| 134 |
-
max_lines=
|
| 135 |
)
|
| 136 |
|
| 137 |
with gr.Row():
|
|
@@ -148,6 +153,33 @@ with gr.Blocks() as demo:
|
|
| 148 |
)
|
| 149 |
|
| 150 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 151 |
if __name__ == '__main__':
|
| 152 |
|
| 153 |
demo.launch(mcp_server=True)
|
|
|
|
| 41 |
gr.HTML(text.TITLE)
|
| 42 |
gr.Markdown(text.DESCRIPTION)
|
| 43 |
|
| 44 |
+
|
| 45 |
# Log output
|
| 46 |
with gr.Row():
|
| 47 |
dialog_output = gr.Textbox(label='Server logs', lines=7, max_lines=5)
|
|
|
|
| 54 |
show_api=False
|
| 55 |
)
|
| 56 |
|
| 57 |
+
|
| 58 |
# Get feed tool
|
| 59 |
gr.Markdown('### 1. `get_feed()`')
|
| 60 |
website_url = gr.Textbox('slashdot', label='Website')
|
|
|
|
| 71 |
api_name='Get RSS feed content'
|
| 72 |
)
|
| 73 |
|
| 74 |
+
|
| 75 |
# Vector search tool
|
| 76 |
gr.Markdown('### 2. `context_search()`')
|
| 77 |
|
|
|
|
| 98 |
api_name='Context vector search'
|
| 99 |
)
|
| 100 |
|
| 101 |
+
|
| 102 |
# Find article tool
|
| 103 |
gr.Markdown('### 3. `find_article()`')
|
| 104 |
|
|
|
|
| 108 |
)
|
| 109 |
article_search_output = gr.Textbox(
|
| 110 |
label='Article search results',
|
| 111 |
+
lines=3,
|
| 112 |
+
max_lines=3
|
| 113 |
)
|
| 114 |
|
| 115 |
with gr.Row():
|
|
|
|
| 125 |
api_name='Article vector search'
|
| 126 |
)
|
| 127 |
|
| 128 |
+
|
| 129 |
# Get summary tool
|
| 130 |
gr.Markdown('### 4. `get_summary()`')
|
| 131 |
|
|
|
|
| 135 |
)
|
| 136 |
article_summary = gr.Textbox(
|
| 137 |
label='Article summary',
|
| 138 |
+
lines=3,
|
| 139 |
+
max_lines=3
|
| 140 |
)
|
| 141 |
|
| 142 |
with gr.Row():
|
|
|
|
| 153 |
)
|
| 154 |
|
| 155 |
|
| 156 |
+
# Get link tool
|
| 157 |
+
gr.Markdown('### 5. `get_link()`')
|
| 158 |
+
|
| 159 |
+
article_title_link = gr.Textbox(
|
| 160 |
+
'FAA To Eliminate Floppy Disks Used In Air Traffic Control Systems',
|
| 161 |
+
label='Article title'
|
| 162 |
+
)
|
| 163 |
+
article_link = gr.Textbox(
|
| 164 |
+
label='Article link',
|
| 165 |
+
lines=3,
|
| 166 |
+
max_lines=3
|
| 167 |
+
)
|
| 168 |
+
|
| 169 |
+
with gr.Row():
|
| 170 |
+
article_link_submit_button = gr.Button('Submit title')
|
| 171 |
+
article_link_clear_button = gr.ClearButton(
|
| 172 |
+
components=[article_title_link, article_link]
|
| 173 |
+
)
|
| 174 |
+
|
| 175 |
+
article_link_submit_button.click( # pylint: disable=no-member
|
| 176 |
+
fn=tool_funcs.get_link,
|
| 177 |
+
inputs=article_title_link,
|
| 178 |
+
outputs=article_link,
|
| 179 |
+
api_name='Article link search'
|
| 180 |
+
)
|
| 181 |
+
|
| 182 |
+
|
| 183 |
if __name__ == '__main__':
|
| 184 |
|
| 185 |
demo.launch(mcp_server=True)
|