Skip to content

Commit

Permalink
Patch Fix and Added new option in web command
Browse files Browse the repository at this point in the history
  • Loading branch information
ZeyoYT committed Sep 8, 2024
1 parent 523e424 commit b8304ea
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 3 deletions.
3 changes: 1 addition & 2 deletions src/main/java/me/ailama/commands/AiCommand.java
Original file line number Diff line number Diff line change
Expand Up @@ -69,9 +69,8 @@ public void handleCommand(SlashCommandInteractionEvent event) {

String userId = event.getUser().getId();

if(modelOption != null && !OllamaManager.getInstance().hasModel(modelOption)) {
if (modelOption != null && !OllamaManager.getInstance().hasModel(modelOption)) {
event.getHook().sendMessage("The model you provided is invalid, please provide a valid model").setEphemeral(true).queue();
return;
}

if(resetSession) {
Expand Down
9 changes: 9 additions & 0 deletions src/main/java/me/ailama/commands/WebCommand.java
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ public SlashCommandData getCommandData() {

.addOption(OptionType.STRING, "search", "The query you want to search for", true)
.addOption(OptionType.BOOLEAN, "for-image", "search for a image", false)
.addOption(OptionType.BOOLEAN, "improve_query", "If you want to improve the query by using ai", false)
.addOption(OptionType.STRING, "instructions", "additional instructions after getting search result", false)
.addOption(OptionType.INTEGER, "limit", "The limit of search results", false)
.addOption(OptionType.BOOLEAN, "ephemeral", "If you want the response to be ephemeral", false)
Expand All @@ -54,6 +55,7 @@ public void handleCommand(SlashCommandInteractionEvent event) {
String modelOption = event.getOption("model") != null ? event.getOption("model").getAsString() : null;
boolean resetSession = event.getOption("reset-session") != null && event.getOption("reset-session").getAsBoolean();
boolean imageOnly = event.getOption("for-image") != null && event.getOption("for-image").getAsBoolean();
boolean improveQuery = event.getOption("improve_query") != null && event.getOption("improve_query").getAsBoolean();

int limitOption = event.getOption("limit") != null ? event.getOption("limit").getAsInt() : 1;

Expand All @@ -73,6 +75,13 @@ public void handleCommand(SlashCommandInteractionEvent event) {
return;
}

if(improveQuery) {
queryOption = OllamaManager.getInstance().createAssistantX(userId).systemMessageProvider(o -> """
You are a helpful assistant! you will be given a query, you need to improve it for getting better search results, your
response should only contain the improved query in plain text and should not contain any other information.
""").build().answer(queryOption);
}

// Get the URL for the content
List<String> urlForContent = SearXNGManager.getInstance().getTopSearchResults(queryOption, limitOption, imageOnly);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -393,7 +393,7 @@ public ChatMemory getChatMemory(String userId) {
return chatMemories.get(userId);
}

// Returns a custom Assistant that uses the provided model, allowing for more customization
// Returns a custom Assistant that uses the provided model, allowing for more customization, has no memory
public AiServices<Assistant> createAssistantX(String modelName) {

String aiModel = modelName != null ? modelName : model;
Expand Down

0 comments on commit b8304ea

Please sign in to comment.