aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorterminaldweller <thabogre@gmail.com>2021-12-01 08:56:31 +0000
committerterminaldweller <thabogre@gmail.com>2021-12-01 08:56:31 +0000
commit797d1b874e6968ee1b38db8efa1ee70249536ed0 (patch)
treea0f01fc15ea151b6368d9dd00a729532e70ba464
parentreqs is working fot text mode. (diff)
downloaddevourer-797d1b874e6968ee1b38db8efa1ee70249536ed0.tar.gz
devourer-797d1b874e6968ee1b38db8efa1ee70249536ed0.zip
added README. /wiki is working now.
-rw-r--r--README.md21
-rw-r--r--devourer.py10
-rwxr-xr-xtests.sh2
3 files changed, 26 insertions, 7 deletions
diff --git a/README.md b/README.md
index 4639f82..cb867f3 100644
--- a/README.md
+++ b/README.md
@@ -3,7 +3,26 @@
[![Code style: black](https://img.shields.io/badge/code%20style-black-000000.svg)](https://github.com/psf/black)
# devourer
-A knowledge aggregator
+devourer is an api server that currently has the following endpoints and does the following things:<br/>
+
+## /summ
+```sh
+https://localhost:19019/mila/summ?url=https://dilipkumar.medium.com/standalone-mongodb-on-kubernetes-cluster-19e7b5896b27&summary=newspaper&audio=true
+```
+The `/summ` endpoint optionally summarizes the article and can also optionally send the article as an audio file.<br/>
+The parameters are `url`,`summary` tells the server which summarization method to use. the last parameter `audio` tells the server whether to just send the text result or an audio equivalent.<br/>
+
+## /wiki
+```sh
+https://localhost:19019/mila/wiki?term=iommu&summary=newspaper&audio=true
+```
+Searches wikipedia for the given `term` parameter. Like other endpoints, can optionally summarize the result and turn it into audio with `summary` and `audio` parameters.<br/>
+
+## /reqs
+```sh
+https://localhost:19019/mila/reqs?url=https://www.ietf.org/rfc/rfc2865.txt&sourcetype=text
+```
+Extracts the requirements from the contents inside a given url. The `sourcetype` parameter tells the server how to interpret the url contents. currently only `text` and `html` are supported as valid values.<br/>
## Usage Example
diff --git a/devourer.py b/devourer.py
index 75f469b..8196050 100644
--- a/devourer.py
+++ b/devourer.py
@@ -242,7 +242,7 @@ def summarizeLinksToAudio(url, summary) -> None:
return result
-def searchWikipedia(search_term: str) -> str:
+def searchWikipedia(search_term: str, summary: str) -> str:
"""Search wikipedia for a string and return the url.
reference: https://www.mediawiki.org/wiki/API:Opensearch
@@ -259,7 +259,7 @@ def searchWikipedia(search_term: str) -> str:
res = getWithParams(os.environ["WIKI_SEARCH_URL"], searchParmas)
# FIXME-handle wiki redirects/disambiguations
source = res[3][0]
- result = summarizeLinkToAudio(source, "none")
+ result = summarizeLinkToAudio(source, summary)
except Exception as e:
logging.exception(e)
finally:
@@ -298,12 +298,12 @@ def extract_reqs_ep(url: str, sourcetype: str = "html"):
@app.get("/mila/wiki")
-def wiki_search_ep(term: str, audio: bool = False):
+def wiki_search_ep(term: str, summary: str = "none", audio: bool = False):
"""search and summarizes from wikipedia"""
- text = searchWikipedia(term)
+ text = searchWikipedia(term, summary)
if audio:
audio_path = textToAudio(text)
- return FastAPI(
+ return APIResponse(
getAudioFromFile(audio_path) if audio_path != "" else "",
media_type="audio/mpeg",
)
diff --git a/tests.sh b/tests.sh
index 37712fd..0fdd19d 100755
--- a/tests.sh
+++ b/tests.sh
@@ -1,5 +1,5 @@
#!/usr/bin/env sh
curl -k -X GET https://localhost:19019/mila/summ?url=https://dilipkumar.medium.com/standalone-mongodb-on-kubernetes-cluster-19e7b5896b27&summary=newspaper&audio=true
-curl -k -X GET https://localhost:19019/mila/wiki?term=iommu
+curl -k -X GET https://localhost:19019/mila/wiki?term=iommu&summary=none&audio=false
curl -k -X GET https://localhost:19019/mila/reqs?url=https://www.ietf.org/rfc/rfc2865.txt&sourcetype=text