Skip to content

Commit 177d343

Browse files
committed
tweaks
1 parent 4cc1d98 commit 177d343

File tree

1 file changed

+48
-37
lines changed

1 file changed

+48
-37
lines changed

packages/plugin-code-assistant/src/actions/codeAssistant.ts

+48-37
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import {
66
Memory,
77
type Action,
88
State,
9+
generateWebSearch,
910
} from "@elizaos/core";
1011

1112
interface DiscordMessage {
@@ -219,7 +220,7 @@ export const codeAssistantAction: Action = {
219220
}
220221

221222
elizaLogger.log("Processing development guide request:", message);
222-
console.log("***inside handler");
223+
//console.log("***inside handler");
223224
const text = message.content.text.toLowerCase();
224225
const isGithubIssueQuery =
225226
text.includes("latest") &&
@@ -231,7 +232,7 @@ export const codeAssistantAction: Action = {
231232
previousContext: state.previousMessages?.map((m) => m.content.text),
232233
});
233234

234-
// Handle GitHub issue queries directly, bypassing knowledge base
235+
// Only use GitHub API for explicit GitHub queries
235236
if (isGithubIssueQuery) {
236237
try {
237238
elizaLogger.log("Fetching latest GitHub issues...");
@@ -288,47 +289,57 @@ export const codeAssistantAction: Action = {
288289
});
289290
return;
290291
}
291-
}
292-
293-
// Only proceed with knowledge base search for non-GitHub queries
294-
const knowledgeResults = await knowledgeManager.searchKnowledge(
295-
message.content.text
296-
);
292+
} else {
293+
// For non-GitHub queries, prioritize knowledge base search
294+
const knowledgeResults = await knowledgeManager.searchKnowledge(
295+
message.content.text
296+
);
297297

298-
// Then, perform web search
299-
const searchQuery = `${message.content.text} site:elizaos.github.io/eliza OR site:github.com/elizaos/eliza`;
300-
const searchResponse = await generateWebSearch(searchQuery, runtime);
298+
// Then, perform web search with more targeted scope
299+
const searchQuery = `${message.content.text} site:elizaos.github.io/eliza OR site:github.com/elizaos/eliza/docs OR site:github.com/elizaos/eliza/wiki`;
300+
const searchResponse = await generateWebSearch(
301+
searchQuery,
302+
runtime
303+
);
301304

302-
let responseText = "";
305+
let responseText = "";
303306

304-
// If we have knowledge base results, include them first
305-
if (knowledgeResults.length > 0) {
306-
responseText +=
307-
"Here's what I found in our community knowledge:\n\n";
308-
responseText += knowledgeResults.slice(0, 3).join("\n") + "\n\n";
309-
}
307+
// Prioritize knowledge base results
308+
if (knowledgeResults.length > 0) {
309+
responseText +=
310+
"Here's what I found in our community knowledge:\n\n";
311+
responseText +=
312+
knowledgeResults.slice(0, 3).join("\n") + "\n\n";
313+
}
310314

311-
// Add web search results if available
312-
if (searchResponse && searchResponse.results.length) {
313-
responseText += searchResponse.answer
314-
? `Here's what I found in the Eliza documentation:\n\n${searchResponse.answer}\n\n`
315-
: "";
316-
317-
responseText += `Relevant documentation and examples:\n${searchResponse.results
318-
.map(
319-
(result: SearchResult, index: number) =>
320-
`${index + 1}. [${result.title}](${result.url})`
321-
)
322-
.join("\n")}\n\n`;
323-
}
315+
// Add web search results if available and relevant
316+
if (searchResponse && searchResponse.results.length) {
317+
responseText += searchResponse.answer
318+
? `Here's what I found in the Eliza documentation:\n\n${searchResponse.answer}\n\n`
319+
: "";
320+
321+
responseText += `Relevant documentation and examples:\n${searchResponse.results
322+
.map(
323+
(result: SearchResult, index: number) =>
324+
`${index + 1}. [${result.title}](${result.url})`
325+
)
326+
.join("\n")}\n\n`;
327+
}
324328

325-
responseText +=
326-
`If you need more help, consider:\n` +
327-
`- Checking the Getting Started guide\n` +
328-
`- Joining our Discord community\n` +
329-
`- Opening an issue on GitHub`;
329+
// Add helpful suggestions only if few results found
330+
if (
331+
!knowledgeResults.length &&
332+
(!searchResponse || !searchResponse.results.length)
333+
) {
334+
responseText +=
335+
`If you need more help, consider:\n` +
336+
`- Checking the Getting Started guide\n` +
337+
`- Joining our Discord community\n` +
338+
`- Opening an issue on GitHub`;
339+
}
330340

331-
callback({ text: responseText });
341+
callback({ text: responseText });
342+
}
332343
},
333344
examples: [
334345
[

0 commit comments

Comments
 (0)