Answers questions asked in a Telegram chat by searching the web, and replies with the answer and the pages it came from.
Uses
OpenAI
Serper
Telegram
Answer Telegram questions from the web, with sources
incomingMessage.When a new message is received. Save it as incomingMessage.subjectsToAnswer to blank.Set subjectsToAnswer to blank.sourcesToUse to 3.Set sourcesToUse to 3.minimumQuestionLength to 12.Set minimumQuestionLength to 12.sourcesWanted to sourcesToUse multiplied by 1.Set sourcesWanted to sourcesToUse multiplied by 1.sourcesWanted is less than 1If sourcesWanted is less than 1Yes
No
No steps
sourcesWanted is greater than 5If sourcesWanted is greater than 5Yes
No
No steps
chatId to incomingMessage.chat_id.Set chatId to incomingMessage.chat_id.chatId is emptyIf chatId is emptyYes
No
No steps
question to blank.Set question to blank.messageErrorIf a step below fails, save the error as messageErrorTry
incomingMessage.text and save it as question.Trim incomingMessage.text and save it as question.On error
question starts with Here is what I foundIf question starts with Here is what I foundYes
No
No steps
questionFloor to minimumQuestionLength multiplied by 1.Set questionFloor to minimumQuestionLength multiplied by 1.question is less than questionFloorIf the length of question is less than questionFloorYes
No
No steps
as the ellipsis (keeping words whole)'. Save it as searchResult.Search Google for '@question truncated to 300 characters using as the ellipsis (keeping words whole)'. Save it as searchResult.searchResults to searchResult.results.Set searchResults to searchResult.results.citationLines.Start an empty list and save it as citationLines.sourceBlocks.Start an empty list and save it as sourceBlocks.sourceNumber to 0.Set sourceNumber to 0.row in searchResults:For each row in searchResults:sourceNumber is greater than or equal to sourcesWantedIf sourceNumber is greater than or equal to sourcesWantedYes
No
No steps
resultLink to blank.Set resultLink to blank.resultTitle to blank.Set resultTitle to blank.resultSnippet to blank.Set resultSnippet to blank.linkErrorIf a step below fails, save the error as linkErrorTry
row.link and save it as resultLink.Trim row.link and save it as resultLink.On error
resultLink is emptyIf resultLink is emptyYes
No
No steps
titleErrorIf a step below fails, save the error as titleErrorTry
row.title and save it as resultTitle.Trim row.title and save it as resultTitle.On error
resultTitle to blank.Change resultTitle to blank.resultTitle is emptyIf resultTitle is emptyYes
resultTitle to Untitled page.Change resultTitle to Untitled page.No
No steps
snippetErrorIf a step below fails, save the error as snippetErrorTry
row.snippet and save it as resultSnippet.Trim row.snippet and save it as resultSnippet.On error
resultSnippet to blank.Change resultSnippet to blank.sourceNumber.Add 1 to sourceNumber.sourceNumber] resultTitle truncated to 110 characters using ... as the ellipsisAdd [sourceNumber] resultTitle truncated to 110 characters using ... as the ellipsis
resultLink truncated to 200 characters using as the ellipsis to the end of citationLines and save it as citationLines.sourceNumber] resultTitleAdd [sourceNumber] resultTitle
resultLink
resultSnippet truncated to 700 characters using ... as the ellipsis to the end of sourceBlocks and save it as sourceBlocks.citationLines is emptyIf citationLines is emptyYes
chatId.Send a message to chat chatId.I searched the web for that but did not get back any result I could cite, so I have not written an answer. Try asking it a different way.No
No steps
promptRole to You are a research assistant answering a question someone asked in a Telegram chat.Set promptRole to You are a research assistant answering a question someone asked in a Telegram chat.
This assistant answers questions about: subjectsToAnswer
.promptRules to Rules you must follow:Set promptRules to Rules you must follow:
- Answer only from the numbered sources below. Do not use anything else you know.
- Never invent a source, a web address, a statistic or a quotation.
- Cite by number in square brackets, like [1], after each claim it supports.
- Do not write out any web address. The addresses are added below your answer for you.promptRulesTwo to - If the sources do not answer the question, say plainly that they do not, and say what they do cover.Set promptRulesTwo to - If the sources do not answer the question, say plainly that they do not, and say what they do cover.
- If the question is outside the subjects above, say so instead of answering it.
- Plain text only, no formatting marks, under 200 words.promptSources to Sources:Set promptSources to Sources:
sourceBlocks joined by a blank line
.answerPrompt to promptRole@promptRules@promptRulesTwo@promptSourcesQuestion:Set answerPrompt to promptRole@promptRules@promptRulesTwo@promptSourcesQuestion:
question
.answerPrompt. Save it as modelResult.Ask OpenAI: answerPrompt. Save it as modelResult.answerText to blank.Set answerText to blank.answerErrorIf a step below fails, save the error as answerErrorTry
modelResult.response_text and save it as answerText.Trim modelResult.response_text and save it as answerText.On error
answerText to blank.Change answerText to blank.answerText is emptyIf answerText is emptyYes
chatId.Send a message to chat chatId.I found sources for that but could not write an answer from them. Here is what the search returned, so you can read it yourself:
citationLines joined by a blank lineNo
No steps
replyHeader to Here is what I found.Set replyHeader to Here is what I found.answerText to 2400 characters (keeping words whole) and save it as replyBody.Shorten answerText to 2400 characters (keeping words whole) and save it as replyBody.replySources to Set replySources to
Sources:
citationLines joined by a blank line.replyText to replyHeader plus replyBody plus replySources.Set replyText to replyHeader plus replyBody plus replySources.chatId.Send a message to chat chatId.replyText