Skip to content

Commit

Permalink
aa
Browse files Browse the repository at this point in the history
  • Loading branch information
Nutlope committed Jun 12, 2024
1 parent 645940b commit 62da9c4
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 0 deletions.
5 changes: 5 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,11 @@
5. Create a `.env` (use the `.example.env` for reference) and replace the API keys
6. Run `npm install` and `npm run dev` to install dependencies and run locally

## Tasks

- [ ] Add error handling to getAnswer & anywhere else
- [ ] Move back to Together SDK w/ helicone + simpler streaming

## Future tasks

- [ ] Try to parse the sources in a more effecient way to make the app faster overall: Try Serper API
Expand Down
6 changes: 6 additions & 0 deletions app/api/getAnswer/route.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,17 +23,22 @@ export async function POST(request: Request) {
let finalResults = await Promise.all(
sources.map(async (result: any) => {
try {
console.log(`[getAnswer] Fetching source from ${result.url}`);
const response = await fetch(result.url);
const html = await response.text();
console.log(`[getAnswer] Got HTML from ${result.url}`);
const virtualConsole = new jsdom.VirtualConsole();
const dom = new JSDOM(html, { virtualConsole });

const doc = dom.window.document;
console.log(`[getAnswer] Parsing HTML from ${result.url}`);
const parsed = new Readability(doc).parse();
let parsedContent = parsed
? cleanedText(parsed.textContent)
: "Nothing found";

console.log(`[getAnswer] Got parsed content from ${result.url}`);

return {
...result,
fullContent: parsedContent,
Expand All @@ -47,6 +52,7 @@ export async function POST(request: Request) {
}
}),
);
console.log(`[getAnswer] Finished fetching text from source URLs`);

let debug = finalResults.map(
(result, index) => `[[citation:${index}]] ${result.fullContent} \n\n`,
Expand Down

0 comments on commit 62da9c4

Please sign in to comment.