feat(search): Add searchUrl to message
This commit is contained in:
parent
641968cf6a
commit
bdace57cfd
5 changed files with 51 additions and 10 deletions
|
|
@ -56,6 +56,7 @@ class MetaSearchAgent implements MetaSearchAgentType {
|
|||
private config: Config;
|
||||
private strParser = new StringOutputParser();
|
||||
private searchQuery?: string;
|
||||
private searxngUrl?: string;
|
||||
|
||||
constructor(config: Config) {
|
||||
this.config = config;
|
||||
|
|
@ -81,6 +82,7 @@ class MetaSearchAgent implements MetaSearchAgentType {
|
|||
let question = this.config.summarizer
|
||||
? await questionOutputParser.parse(input)
|
||||
: input;
|
||||
console.log('question', question);
|
||||
|
||||
if (question === 'not_needed') {
|
||||
return { query: '', docs: [] };
|
||||
|
|
@ -206,12 +208,15 @@ class MetaSearchAgent implements MetaSearchAgentType {
|
|||
} else {
|
||||
question = question.replace(/<think>.*?<\/think>/g, '');
|
||||
|
||||
const res = await searchSearxng(question, {
|
||||
const searxngResult = await searchSearxng(question, {
|
||||
language: 'en',
|
||||
engines: this.config.activeEngines,
|
||||
});
|
||||
|
||||
const documents = res.results.map(
|
||||
// Store the SearXNG URL for later use in emitting to the client
|
||||
this.searxngUrl = searxngResult.searchUrl;
|
||||
|
||||
const documents = searxngResult.results.map(
|
||||
(result) =>
|
||||
new Document({
|
||||
pageContent:
|
||||
|
|
@ -447,9 +452,7 @@ class MetaSearchAgent implements MetaSearchAgentType {
|
|||
event.event === 'on_chain_end' &&
|
||||
event.name === 'FinalSourceRetriever'
|
||||
) {
|
||||
// Add searchQuery to the sources data if it exists
|
||||
const sourcesData = event.data.output;
|
||||
// @ts-ignore - we added searchQuery property
|
||||
if (this.searchQuery) {
|
||||
emitter.emit(
|
||||
'data',
|
||||
|
|
@ -457,6 +460,7 @@ class MetaSearchAgent implements MetaSearchAgentType {
|
|||
type: 'sources',
|
||||
data: sourcesData,
|
||||
searchQuery: this.searchQuery,
|
||||
searchUrl: this.searxngUrl,
|
||||
}),
|
||||
);
|
||||
} else {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue