Skip to content

Commit

Permalink
Path and Fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
ZeyoYT committed Nov 24, 2024
1 parent dc8b815 commit 5f40f3e
Show file tree
Hide file tree
Showing 3 changed files with 67 additions and 25 deletions.
Original file line number Diff line number Diff line change
@@ -1,17 +1,26 @@
package me.ailama.commands.contextcommands;

import me.ailama.handler.commandhandler.EventManager;
import me.ailama.handler.commandhandler.OllamaManager;
import me.ailama.handler.enums.EventCategoryEnum;
import me.ailama.handler.interfaces.AiLamaEvent;
import me.ailama.handler.interfaces.AiLamaMessageContextCommand;
import me.ailama.handler.interfaces.Assistant;
import me.ailama.main.AiLama;
import net.dv8tion.jda.api.entities.Message;
import net.dv8tion.jda.api.events.interaction.ModalInteractionEvent;
import net.dv8tion.jda.api.events.interaction.command.MessageContextInteractionEvent;
import net.dv8tion.jda.api.interactions.IntegrationType;
import net.dv8tion.jda.api.interactions.InteractionContextType;
import net.dv8tion.jda.api.interactions.commands.DefaultMemberPermissions;
import net.dv8tion.jda.api.interactions.commands.build.CommandData;
import net.dv8tion.jda.api.interactions.commands.build.Commands;
import net.dv8tion.jda.api.interactions.components.ActionRow;
import net.dv8tion.jda.api.interactions.components.text.TextInput;
import net.dv8tion.jda.api.interactions.components.text.TextInputStyle;
import net.dv8tion.jda.api.interactions.modals.Modal;

public class AiContextCommand implements AiLamaMessageContextCommand {
public class AiContextCommand implements AiLamaMessageContextCommand, AiLamaEvent {

@Override
public CommandData getCommandData() {
Expand All @@ -24,9 +33,33 @@ public CommandData getCommandData() {

@Override
public void handleCommand(MessageContextInteractionEvent event) {
event.deferReply().queue();

String message = event.getTarget().getContentRaw();
if(event.getTarget().getContentRaw().isEmpty()) {
event.getHook().sendMessage("Please provide a message to get response, no embeds, images or files").queue();
return;
}

Modal m = Modal.create(event.getId(), "AI Formatter")
.addComponents(
ActionRow.of(TextInput.create("ephemeral", "Ephemeral ( 1 for yes )", TextInputStyle.SHORT).setMaxLength(1).setRequired(true).build())
)
.build();

EventManager.getEventManager().addEventWithData(event.getUser().getId(), m.getId(), EventCategoryEnum.ModalEvent, this, event.getTarget());

event.replyModal(m).queue();
}

@Override
public void handleModalEvent(ModalInteractionEvent event) {

boolean ephemeral = event.getValue("ephemeral").getAsString().equals("1");

event.deferReply(ephemeral).queue();

Message messageData = (Message)(EventManager.getEventManager().getEventData(event.getUser().getId(), event.getModalId()));
String message = messageData.getContentRaw();

String SystemMessage = """
You are a helpful ai assistant that will generate response for users query.
Expand Down
49 changes: 28 additions & 21 deletions src/main/java/me/ailama/commands/contextcommands/ReplyCommand.java
Original file line number Diff line number Diff line change
Expand Up @@ -41,11 +41,16 @@ public CommandData getCommandData() {
@Override
public void handleCommand(MessageContextInteractionEvent event) {

if(event.getTarget().getContentRaw().isEmpty()) {
event.getHook().sendMessage("Please provide a message to get response, no embeds, images or files").queue();
return;
}

Modal m = Modal.create(event.getId(), "Reply Formatter")
.addComponents(
ActionRow.of(TextInput.create("reply_tone", "Reply Tone", TextInputStyle.SHORT).setRequired(true).build()),
ActionRow.of(TextInput.create("reply_requirements", "Reply Requirements", TextInputStyle.SHORT).setRequired(true).build()),
ActionRow.of(TextInput.create("custom_system_message", "Custom System Message", TextInputStyle.PARAGRAPH).setRequired(false).build())
)
)
.build();

EventManager.getEventManager().addEventWithData(event.getUser().getId(), m.getId(), EventCategoryEnum.ModalEvent, this, event.getTarget());
Expand All @@ -57,21 +62,21 @@ public void handleModalEvent(ModalInteractionEvent event) {

event.deferReply().queue();

String tone = event.getValue("reply_tone").getAsString();
String tone = event.getValue("reply_requirements").getAsString();
String customSystemMessage;

if(event.getValue("custom_system_message") != null) {
customSystemMessage = event.getValue("custom_system_message").getAsString();

customSystemMessage += "\n\n" + """
As your knowledge base was cut off, you may use the following information in json for crafting the reply:
As your knowledge base was cut off, you may use the following information for sending the response:
- %s
User requirements for the reply:
- Tone : %s
Craft the reply for the following message:
User requirements for the response:
- %s
Craft the response for the following message:
- " %s "
""";
} else {
customSystemMessage = null;
Expand All @@ -81,26 +86,28 @@ public void handleModalEvent(ModalInteractionEvent event) {

String message = eventData.getContentRaw();
String SystemMessage = """
Act as a helpful and concise assistant. When generating responses to user messages,
do not enclose them in quotation marks. Format your responses according to the provided
JSON and user requirements.
You will craft a reply for the message that user provides, but craft it in a way that it is a reply to the user's message.
Here's how you'll receive information:
Rules :
- don't enclose the message in quotes and make it copy paste ready.
- you may use markdown to format your messages.
- Reply should look like a reply to a friend.
- use common slang and abbreviations.
- must be short and concise.
- don't use too many emojis.
- A message from the user (without quotation marks)
- User requirements for the response format
- Your task: Craft a response for the given message following the user's requirements
As your knowledge base was cut off, you may use the following information in json for crafting the reply:
- %s
Message from User:
- " %s "
User requirements for the reply:
- Tone : %s
User requirements for the response:
- %s
Craft the reply for the following message:
As your knowledge base was cut off, you may use the following information in json for response:
- %s
Now, please assist the user with their request while adhering to these guidelines. Ensure
that your responses do not include quotation marks or any additional characters around the
response message.
""";

String finalCustomSystemMessage = customSystemMessage;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -546,7 +546,9 @@ public Assistant urlAssistant(List<String> url, String model, String userId, boo
try {

String webUrl = AiLama.getInstance().fixUrl(u);
String textOnly = Jsoup.connect(webUrl).get().body().text();
String textOnly = Jsoup.connect(webUrl)
.userAgent("Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/56.0.2924.87 Safari/537.36")
.get().body().text();
Document document = Document.from(textOnly);

documents.add(document);
Expand Down

0 comments on commit 5f40f3e

Please sign in to comment.