-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #18 from ittia-research/dev
change API response to stream
- Loading branch information
Showing
9 changed files
with
126 additions
and
36 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
from .homepage import get_homepage | ||
from .html import html_browser |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
import utils | ||
from settings import settings | ||
|
||
def get_homepage(): | ||
# get tech stack | ||
stack = utils.get_stack() | ||
md = f"## Tech stack\n" | ||
lines = [md] | ||
lines.extend([f"**{key}**: {value}" for key, value in stack.items()]) | ||
md = "\n\n".join(lines) | ||
|
||
md = f"""# Fact-check API | ||
**Usage**: {settings.PROJECT_HOSTING_BASE_URL}/YOUR_FACT_CHECK_QUERY | ||
**Source**: https://github.com/ittia-research/check | ||
{md} | ||
""" | ||
return md |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
""" | ||
The return of requests from browser. | ||
It will fetch the same url with markdown header and process content in the streams as markdown. | ||
If `stage` in the stream in `wait`, this stream will be skipped. | ||
Purpose of this setup: | ||
- Render multiple stages as markdown. | ||
- Avoid CloudFlare 524 error when use CloudFlare as CDN. | ||
""" | ||
html_browser = """ | ||
<!DOCTYPE html> | ||
<html lang="en"> | ||
<head> | ||
<meta charset="UTF-8"> | ||
<meta name="viewport" content="width=device-width, initial-scale=1.0"> | ||
<title>Fact-check</title> | ||
</head> | ||
<body> | ||
<div id="content"></div> | ||
<script src="https://cdn.jsdelivr.net/npm/marked/marked.min.js"></script> | ||
<script> | ||
async function fetchData() { | ||
const response = await fetch(window.location.href, { | ||
headers: { | ||
"Accept": "text/markdown" | ||
} | ||
}); | ||
const reader = response.body.getReader(); | ||
const decoder = new TextDecoder(); | ||
let buffer = ''; | ||
while (true) { | ||
const { done, value } = await reader.read(); | ||
if (done) break; | ||
let part = decoder.decode(value, { stream: true }); | ||
console.log(part) | ||
try { | ||
const message = JSON.parse(part); | ||
if (message.stage != "wait") { | ||
document.getElementById('content').innerHTML = marked.parse(message.content); | ||
} | ||
} catch (e) { | ||
console.error("Error parsing JSON:", e); | ||
} | ||
} | ||
} | ||
fetchData(); | ||
</script> | ||
</body> | ||
</html> | ||
""" |
File renamed without changes.