Skip to content

Commit

Permalink
Fix summarization bug on the web-browsing function
Browse files Browse the repository at this point in the history
  • Loading branch information
wladpaiva committed Oct 23, 2023
1 parent 56eb06e commit 2250784
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 7 deletions.
5 changes: 5 additions & 0 deletions .changeset/dirty-penguins-jump.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'aibitat': patch
---

Fix summarization bug on the `web-browsing` function
16 changes: 9 additions & 7 deletions src/plugins/web-browsing.ts
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ async function search(
* @param url
* @returns
*/
async function scrape(url: string) {
export async function scrape(url: string) {
console.log('🔥 Scraping website...', url)

const headers = {
Expand Down Expand Up @@ -99,10 +99,9 @@ async function scrape(url: string) {
* @param content The content to summarize.
* @returns The summarized content.
*/
async function summarize(content: string): Promise<string> {
export async function summarize(content: string): Promise<string> {
const llm = new ChatOpenAI({
temperature: 0,
// openAIApiKey
modelName: 'gpt-3.5-turbo-16k-0613',
})

Expand All @@ -118,21 +117,24 @@ async function summarize(content: string): Promise<string> {
"{text}"
SUMMARY:
`

const mapPromptTemplate = new PromptTemplate({
template: mapPrompt,
inputVariables: ['text'],
})

const summaryChain = loadSummarizationChain(llm, {
// This convenience function creates a document chain prompted to summarize a set of documents.
const chain = loadSummarizationChain(llm, {
type: 'map_reduce',
combinePrompt: mapPromptTemplate,
combineMapPrompt: mapPromptTemplate,
verbose: true,
})
const res = await chain.call({
input_documents: docs,
})

const output = await summaryChain.run({inputDocuments: docs})

return output
return res.text
}

export function experimental_webBrowsing({}: {} = {}) {
Expand Down

0 comments on commit 2250784

Please sign in to comment.