hallucinationList;
16 | }
17 |
--------------------------------------------------------------------------------
/src/main/java/com/t4a/detect/DetectValues.java:
--------------------------------------------------------------------------------
1 | package com.t4a.detect;
2 |
3 | import lombok.*;
4 |
5 | @NoArgsConstructor
6 | @AllArgsConstructor
7 | @Getter
8 | @Setter
9 | @EqualsAndHashCode
10 | @ToString
11 | public class DetectValues {
12 | private String prompt;
13 | private String context;
14 | private String response;
15 | private String additionalData;
16 | }
17 |
--------------------------------------------------------------------------------
/src/main/java/com/t4a/detect/ExplainDecision.java:
--------------------------------------------------------------------------------
1 | package com.t4a.detect;
2 | /**
3 | * The {@code ExplainDecision} interface represents a mechanism for AI to explain decisions
4 | * regarding a particular prompt text, method name, and reason. AI will call this back
5 | *
6 | * This interface defines a method {@link #explain(String, String, String)} that can be used
7 | * to provide an explanation by AI to a human regarding a decision made based on a prompt text,
8 | * method name, and reason.
9 | *
10 | */
11 | public interface ExplainDecision {
12 | public String explain(String promptText, String methodName, String reason) ;
13 | }
14 |
--------------------------------------------------------------------------------
/src/main/java/com/t4a/detect/FactDetector.java:
--------------------------------------------------------------------------------
1 | package com.t4a.detect;
2 |
3 | import com.t4a.api.ActionType;
4 | import com.t4a.api.DetectorAction;
5 | import com.t4a.api.GuardRailException;
6 |
7 | public class FactDetector implements DetectorAction {
8 | @Override
9 | public ActionType getActionType() {
10 | return ActionType.FACT;
11 | }
12 |
13 | @Override
14 | public String getDescription() {
15 | return "Fact Check in response";
16 | }
17 |
18 | @Override
19 | public DetectValueRes execute(DetectValues dd) throws GuardRailException {
20 | return null;
21 | }
22 | }
23 |
--------------------------------------------------------------------------------
/src/main/java/com/t4a/detect/FeedbackLoop.java:
--------------------------------------------------------------------------------
1 | package com.t4a.detect;
2 |
3 | public interface FeedbackLoop {
4 | boolean isAIResponseValid();
5 | }
6 |
--------------------------------------------------------------------------------
/src/main/java/com/t4a/detect/HallucinationDetectorType.java:
--------------------------------------------------------------------------------
1 | package com.t4a.detect;
2 |
3 | public enum HallucinationDetectorType {
4 | GOOGLE,
5 | SELF
6 | }
7 |
--------------------------------------------------------------------------------
/src/main/java/com/t4a/detect/HallucinationQA.java:
--------------------------------------------------------------------------------
1 | package com.t4a.detect;
2 |
3 | import lombok.AllArgsConstructor;
4 | import lombok.Getter;
5 | import lombok.NoArgsConstructor;
6 | import lombok.Setter;
7 |
8 | @NoArgsConstructor
9 | @AllArgsConstructor
10 | @Getter
11 | @Setter
12 | public class HallucinationQA {
13 | private String question;
14 | private String answer;
15 | private String context;
16 | private String truthPercentage;
17 |
18 |
19 | public double calculateTruthPercent() {
20 | String numberString = truthPercentage.replaceAll("[^\\d.]", "");
21 | double doublePer = Double.parseDouble(numberString);
22 | return doublePer;
23 | }
24 | }
25 |
--------------------------------------------------------------------------------
/src/main/java/com/t4a/detect/HumanInLoop.java:
--------------------------------------------------------------------------------
1 | package com.t4a.detect;
2 |
3 | import java.util.Map;
4 |
5 | /**
6 | * The {@code HumanInLoop} interface represents a mechanism for allowing human involvement
7 | * in a feedback loop process.
8 | *
9 | * This interface defines a method {@link #allow(String, String, Map)} that can be used
10 | * to request human input for a given prompt text and method name with optional parameters.
11 | *
12 | */
13 | public interface HumanInLoop {
14 | public FeedbackLoop allow(String promptText, String methodName, Map params) ;
15 | public FeedbackLoop allow(String promptText, String methodName, String params) ;
16 |
17 | default void setCallback(ActionCallback callback) {
18 |
19 | }
20 | default ActionCallback getCallback() {
21 | return null;
22 | }
23 | }
24 |
--------------------------------------------------------------------------------
/src/main/java/com/t4a/predict/ConfigManager.java:
--------------------------------------------------------------------------------
1 | package com.t4a.predict;
2 |
3 | import lombok.extern.slf4j.Slf4j;
4 |
5 | import java.io.IOException;
6 | import java.io.InputStream;
7 | import java.util.Properties;
8 |
9 | @Slf4j
10 | public class ConfigManager {
11 | private Properties properties;
12 |
13 | public ConfigManager() {
14 | loadProperties("prompt.properties");
15 | }
16 |
17 | private void loadProperties(String fileName) {
18 | properties = new Properties();
19 | try (InputStream inputStream = PredictionLoader.class.getClassLoader().getResourceAsStream(fileName)) {
20 | if (inputStream != null) {
21 | properties.load(inputStream);
22 | } else {
23 | log.warn(fileName + " properties not found will use default values");
24 | }
25 | } catch (IOException e) {
26 | log.warn("Failed to load properties: " + e.getMessage());
27 | }
28 | }
29 |
30 | public String getProperty(String key, String defaultValue) {
31 | return properties.getProperty(key, defaultValue);
32 | }
33 | }
34 |
35 |
--------------------------------------------------------------------------------
/src/main/java/com/t4a/predict/ExtendedPredictionLoader.java:
--------------------------------------------------------------------------------
1 | package com.t4a.predict;
2 |
3 | import com.t4a.action.ExtendedPredictedAction;
4 |
5 | import java.util.Map;
6 |
7 | public interface ExtendedPredictionLoader {
8 | public Map getExtendedActions() throws LoaderException;
9 | }
10 |
--------------------------------------------------------------------------------
/src/main/java/com/t4a/predict/LoaderException.java:
--------------------------------------------------------------------------------
1 | package com.t4a.predict;
2 |
3 | /**
4 | * LoaderException is a custom exception class that extends Exception. Its thrown when a config file
5 | * is not being parsed correctly.
6 |
7 | */
8 | public class LoaderException extends Exception {
9 | public LoaderException() {
10 | }
11 |
12 | public LoaderException(String message) {
13 | super(message);
14 | }
15 |
16 | public LoaderException(String message, Throwable cause) {
17 | super(message, cause);
18 | }
19 |
20 | public LoaderException(Throwable cause) {
21 | super(cause);
22 | }
23 |
24 | public LoaderException(String message, Throwable cause, boolean enableSuppression, boolean writableStackTrace) {
25 | super(message, cause, enableSuppression, writableStackTrace);
26 | }
27 | }
28 |
--------------------------------------------------------------------------------
/src/main/java/com/t4a/processor/AIProcessingException.java:
--------------------------------------------------------------------------------
1 | package com.t4a.processor;
2 |
3 | public class AIProcessingException extends Exception {
4 | public AIProcessingException(Exception e){
5 | super(e);
6 | }
7 | public AIProcessingException(String e) {
8 | super(e);
9 | }
10 | }
11 |
--------------------------------------------------------------------------------
/src/main/java/com/t4a/processor/LogginggExplainDecision.java:
--------------------------------------------------------------------------------
1 | package com.t4a.processor;
2 |
3 | import com.t4a.detect.ExplainDecision;
4 | import lombok.extern.slf4j.Slf4j;
5 |
6 | @Slf4j
7 | public class LogginggExplainDecision implements ExplainDecision {
8 | @Override
9 | public String explain(String promptText, String methodName, String reason) {
10 | log.debug("promptText {} , reason {} ",promptText, reason);
11 | return reason;
12 | }
13 | }
14 |
--------------------------------------------------------------------------------
/src/main/java/com/t4a/processor/chain/Prompt.java:
--------------------------------------------------------------------------------
1 | package com.t4a.processor.chain;
2 |
3 | import java.util.List;
4 |
5 | public class Prompt {
6 | private List prmpt;
7 |
8 | public List getPrmpt() {
9 | return prmpt;
10 | }
11 |
12 | public void setPrmpt(List prmpt) {
13 | this.prmpt = prmpt;
14 | }
15 |
16 | @Override
17 | public String toString() {
18 | return "Prompt{" +
19 | "prmpt=" + prmpt +
20 | '}';
21 | }
22 | }
23 |
--------------------------------------------------------------------------------
/src/main/java/com/t4a/processor/scripts/BaseScriptProcessor.java:
--------------------------------------------------------------------------------
1 | package com.t4a.processor.scripts;
2 |
3 | public interface BaseScriptProcessor {
4 |
5 | public ScriptResult process(String fileName);
6 |
7 | public ScriptResult process(String fileName, ScriptCallback callback);
8 |
9 | default void processWebAction(String line,SeleniumCallback callback,int retryCount){};
10 | }
11 |
--------------------------------------------------------------------------------
/src/main/java/com/t4a/processor/scripts/LoggingSeleniumCallback.java:
--------------------------------------------------------------------------------
1 | package com.t4a.processor.scripts;
2 |
3 | import lombok.extern.slf4j.Slf4j;
4 | import org.openqa.selenium.WebDriver;
5 |
6 | @Slf4j
7 | public class LoggingSeleniumCallback implements SeleniumCallback{
8 | @Override
9 | public boolean beforeWebAction(String lineToBeProcessed,WebDriver driver) {
10 | log.info("Before Web Action: " + driver.getCurrentUrl());
11 | return true; // Return true to continue processing the line
12 | }
13 |
14 | @Override
15 | public void afterWebAction(String lineProcssed,WebDriver driver) {
16 | log.info("After Web Action: " + driver.getCurrentUrl());
17 | }
18 |
19 | @Override
20 | public String handleError(String line, String errorMessage, WebDriver driver, int retryCount) {
21 | log.info("Error during web action: " + errorMessage);
22 | return null;
23 | }
24 |
25 |
26 | }
27 |
--------------------------------------------------------------------------------
/src/main/java/com/t4a/processor/scripts/ScriptCallback.java:
--------------------------------------------------------------------------------
1 | package com.t4a.processor.scripts;
2 |
3 | public interface ScriptCallback {
4 | public String lineResult(String result);
5 | }
6 |
--------------------------------------------------------------------------------
/src/main/java/com/t4a/processor/scripts/ScriptLineResult.java:
--------------------------------------------------------------------------------
1 | package com.t4a.processor.scripts;
2 |
3 |
4 | import lombok.*;
5 |
6 | @Getter
7 | @Setter
8 | @NoArgsConstructor
9 | @AllArgsConstructor
10 | @ToString
11 | public class ScriptLineResult {
12 | private String line;
13 | private String result;
14 | }
15 |
--------------------------------------------------------------------------------
/src/main/java/com/t4a/processor/scripts/ScriptResult.java:
--------------------------------------------------------------------------------
1 | package com.t4a.processor.scripts;
2 |
3 | import lombok.Getter;
4 | import lombok.Setter;
5 |
6 | import java.util.ArrayList;
7 | import java.util.List;
8 |
9 | @Setter
10 | @Getter
11 | public class ScriptResult {
12 | private List results;
13 | public ScriptResult() {
14 | results = new ArrayList<>();
15 | }
16 |
17 | public void addResult(ScriptLineResult result) {
18 | results.add(result);
19 | }
20 |
21 | public void addResult(String line, String resultStr) {
22 | ScriptLineResult result = new ScriptLineResult(line,resultStr);
23 | results.add(result);
24 | }
25 | }
26 |
--------------------------------------------------------------------------------
/src/main/java/com/t4a/processor/scripts/SeleniumCallback.java:
--------------------------------------------------------------------------------
1 | package com.t4a.processor.scripts;
2 |
3 | import org.openqa.selenium.WebDriver;
4 |
5 | public interface SeleniumCallback {
6 | boolean beforeWebAction(String lineToBeProcessed, WebDriver driver);
7 | void afterWebAction(String lineProcessed,WebDriver driver);
8 |
9 | String handleError(String line, String errorMessage, WebDriver driver, int retryCount);
10 | }
11 |
--------------------------------------------------------------------------------
/src/main/java/com/t4a/processor/selenium/DriverActions.java:
--------------------------------------------------------------------------------
1 | package com.t4a.processor.selenium;
2 |
3 | import com.t4a.annotations.Prompt;
4 | import lombok.Getter;
5 | import lombok.NoArgsConstructor;
6 | import lombok.Setter;
7 | import lombok.ToString;
8 |
9 | @Setter
10 | @Getter
11 | @NoArgsConstructor
12 | @ToString
13 | public class DriverActions {
14 | @Prompt(describe = "What method should i invoke on org.openqa.selenium.WebDriver " +
15 | "{navigate, get," +
16 | "click, " +
17 | "takescreenshot, sendKeys,clear,submit,getText," +
18 | "isDisplayed,isEnabled," +
19 | "isSelected,getAttribute,switchTo,selectByVisibleText," +
20 | "selectByValue,selectByIndex" +
21 | "}" +
22 | "")
23 | String typeOfActionToTakeOnWebDriver;
24 |
25 | }
26 |
--------------------------------------------------------------------------------
/src/main/java/com/t4a/processor/selenium/SeleniumAction.java:
--------------------------------------------------------------------------------
1 | package com.t4a.processor.selenium;
2 |
3 | import com.t4a.annotations.Action;
4 | import com.t4a.annotations.Agent;
5 | import lombok.Getter;
6 | import lombok.Setter;
7 | import lombok.extern.java.Log;
8 |
9 | @Log
10 | @Setter
11 | @Getter
12 | @Agent(groupName = "Selenium", groupDescription = "Selenium actions")
13 | public class SeleniumAction {
14 |
15 | @Action(description = "Perform action on web page")
16 | public DriverActions webPageAction(DriverActions webDriverActions) {
17 | if (webDriverActions == null) {
18 | return null;
19 | }
20 | DriverActions copy = new DriverActions();
21 | copy.setTypeOfActionToTakeOnWebDriver(webDriverActions.getTypeOfActionToTakeOnWebDriver());
22 | return copy;
23 | }
24 | }
25 |
--------------------------------------------------------------------------------
/src/main/java/com/t4a/processor/selenium/URLSafety.java:
--------------------------------------------------------------------------------
1 | package com.t4a.processor.selenium;
2 |
3 | import lombok.Getter;
4 | import lombok.Setter;
5 |
6 | @Getter
7 | @Setter
8 | public class URLSafety {
9 | private boolean isThisURLSafe;
10 | }
11 |
--------------------------------------------------------------------------------
/src/main/java/com/t4a/processor/selenium/WebDriverAction.java:
--------------------------------------------------------------------------------
1 | package com.t4a.processor.selenium;
2 |
3 | public enum WebDriverAction {
4 | GET,
5 | FINDELEMENT,
6 | FINDELEMENTS,
7 | CLICK,
8 | SENDKEYS,
9 | CLEAR,
10 | SUBMIT,
11 | GETTEXT,
12 | ISDISPLAYED,
13 | ISENABLED,
14 | ISSELECTED,
15 | GETATTRIBUTE,
16 | SWITCHTO,
17 | SELECTBYVISIBLETEXT,
18 | SELECTBYVALUE,
19 | SELECTBYINDEX,
20 | NAVIGATE,
21 | TAKESCREENSHOT;
22 |
23 |
24 | }
25 |
26 |
--------------------------------------------------------------------------------
/src/main/java/com/t4a/processor/spring/SpringAnthropicProcessor.java:
--------------------------------------------------------------------------------
1 | package com.t4a.processor.spring;
2 |
3 | import com.t4a.predict.PredictionLoader;
4 | import com.t4a.processor.AnthropicActionProcessor;
5 | import org.springframework.context.ApplicationContext;
6 |
7 | public class SpringAnthropicProcessor extends AnthropicActionProcessor {
8 | public SpringAnthropicProcessor(ApplicationContext context) {
9 | PredictionLoader.getInstance(context);
10 |
11 | }
12 | }
13 |
--------------------------------------------------------------------------------
/src/main/java/com/t4a/processor/spring/SpringGeminiProcessor.java:
--------------------------------------------------------------------------------
1 | package com.t4a.processor.spring;
2 |
3 | import com.t4a.predict.PredictionLoader;
4 | import com.t4a.processor.GeminiV2ActionProcessor;
5 | import org.springframework.context.ApplicationContext;
6 |
7 | /**
8 | * This will ensure that the action classes are loaded from Spring Applicaiton Context rather than
9 | * creating the new one , the advantage of that is we can maintain spring dependency injection for all the beans
10 | * Uses Gemini for processing
11 | */
12 | public class SpringGeminiProcessor extends GeminiV2ActionProcessor {
13 |
14 | public SpringGeminiProcessor(ApplicationContext context) {
15 | PredictionLoader.getInstance(context);
16 |
17 | }
18 | }
19 |
--------------------------------------------------------------------------------
/src/main/java/com/t4a/processor/spring/SpringOpenAIProcessor.java:
--------------------------------------------------------------------------------
1 | package com.t4a.processor.spring;
2 |
3 | import com.t4a.predict.PredictionLoader;
4 | import com.t4a.processor.OpenAiActionProcessor;
5 | import org.springframework.context.ApplicationContext;
6 | /**
7 | * This will ensure that the action classes are loaded from Spring Applicaiton Context rather than
8 | * creating the new one , the advantage of that is we can maintain spring dependency injection for all the beans
9 | * Uses OpenAI for processing
10 | */
11 | public class SpringOpenAIProcessor extends OpenAiActionProcessor {
12 | public SpringOpenAIProcessor(ApplicationContext context) {
13 | PredictionLoader.getInstance(context);
14 | }
15 | }
16 |
--------------------------------------------------------------------------------
/src/test/java/com/t4a/examples/ArrayAction.java:
--------------------------------------------------------------------------------
1 | package com.t4a.examples;
2 |
3 |
4 | import com.t4a.annotations.Action;
5 | import com.t4a.annotations.Agent;
6 | import com.t4a.examples.actions.Customer;
7 | import lombok.Getter;
8 | import lombok.Setter;
9 |
10 | @Getter
11 | @Setter
12 | @Agent
13 | public class ArrayAction {
14 |
15 |
16 | @Action(description = "Add all the customers")
17 | public Customer[] addCustomers(Customer[] allCustomers) {
18 |
19 |
20 | return allCustomers;
21 | }
22 | }
23 |
--------------------------------------------------------------------------------
/src/test/java/com/t4a/examples/OpenShiftActionExample.java:
--------------------------------------------------------------------------------
1 | package com.t4a.examples;
2 |
3 | import com.t4a.processor.AIProcessingException;
4 | import com.t4a.deperecated.GeminiActionProcessor;
5 | import lombok.extern.java.Log;
6 |
7 | @Log
8 | public class OpenShiftActionExample {
9 | public static void main(String[] args) throws AIProcessingException {
10 | GeminiActionProcessor processor = new GeminiActionProcessor();
11 | log.info(processor.processSingleAction("can you provide me list of core V1 component status for the kubernetes cluster").toString());
12 | }
13 | }
14 |
--------------------------------------------------------------------------------
/src/test/java/com/t4a/examples/SerperTester.java:
--------------------------------------------------------------------------------
1 | package com.t4a.examples;
2 |
3 | import com.t4a.processor.AIProcessingException;
4 | import com.t4a.deperecated.GeminiActionProcessor;
5 |
6 | import java.util.Properties;
7 |
8 | public class SerperTester {
9 | public static void main(String[] args) throws AIProcessingException {
10 |
11 | Properties p = System.getProperties();
12 |
13 | GeminiActionProcessor processor = new GeminiActionProcessor();
14 | String news = (String)processor.processSingleAction("Can you get me book with id 189");
15 |
16 |
17 | }
18 | }
19 |
--------------------------------------------------------------------------------
/src/test/java/com/t4a/examples/ShowActionsExample.java:
--------------------------------------------------------------------------------
1 | package com.t4a.examples;
2 |
3 | import com.google.gson.Gson;
4 | import com.t4a.api.GroupInfo;
5 | import com.t4a.predict.PredictionLoader;
6 | import lombok.extern.slf4j.Slf4j;
7 |
8 | import java.util.Map;
9 |
10 | @Slf4j
11 | public class ShowActionsExample {
12 |
13 | public ShowActionsExample() throws Exception {
14 |
15 | }
16 | public static void main(String[] args) throws Exception {
17 |
18 | ShowActionsExample sample = new ShowActionsExample();
19 | sample.showActionList();
20 |
21 | Map ga = PredictionLoader.getInstance().getActionGroupList().getGroupActions();
22 | ga.forEach((key, value) -> {
23 | System.out.println("Key: " + key + ", Value: " + value);
24 | });
25 | Gson gsr = new Gson();
26 | String groupInfo = gsr.toJson(PredictionLoader.getInstance().getActionGroupList().getGroupInfo());
27 | System.out.println(groupInfo);
28 | }
29 |
30 | private void showActionList() {
31 | log.debug(PredictionLoader.getInstance().getActionNameList().toString());
32 | }
33 | }
34 |
--------------------------------------------------------------------------------
/src/test/java/com/t4a/examples/SingletonResetter.java:
--------------------------------------------------------------------------------
1 | package com.t4a.examples;
2 |
3 | import java.lang.reflect.Constructor;
4 | import java.lang.reflect.Field;
5 |
6 | public class SingletonResetter {
7 |
8 | public static void resetSingleton(Class> singletonClass) throws Exception {
9 | // Access the private constructor
10 | Constructor> constructor = singletonClass.getDeclaredConstructor();
11 | constructor.setAccessible(true);
12 |
13 | // Reset the instance to null
14 | Field instanceField = singletonClass.getDeclaredField("predictionLoader");
15 | instanceField.setAccessible(true);
16 | instanceField.set(null, null);
17 | }
18 | }
19 |
20 |
21 |
--------------------------------------------------------------------------------
/src/test/java/com/t4a/examples/actions/ArrayOfObjectAction.java:
--------------------------------------------------------------------------------
1 | package com.t4a.examples.actions;
2 |
3 | import com.t4a.annotations.Action;
4 | import com.t4a.annotations.Agent;
5 | import lombok.Getter;
6 | import lombok.Setter;
7 |
8 | @Agent
9 | @Getter
10 | @Setter
11 | public class ArrayOfObjectAction {
12 | @Action(description = "All the customers")
13 | public String[] allTheDates(String[] allTheDates) {
14 |
15 |
16 | return allTheDates;
17 | }
18 | }
19 |
--------------------------------------------------------------------------------
/src/test/java/com/t4a/examples/actions/ComplexAction.java:
--------------------------------------------------------------------------------
1 | package com.t4a.examples.actions;
2 |
3 | import com.t4a.annotations.Action;
4 | import com.t4a.annotations.Agent;
5 |
6 | @Agent(groupName = "customer support", groupDescription = "actions related to customer support")
7 | public class ComplexAction {
8 |
9 | public static int COUNTER = 0;
10 | public ComplexAction() {
11 | COUNTER++;
12 | }
13 | @Action(description = "Customer has problem create ticket for him")
14 | public String computerRepair(Customer customer) {
15 | return customer.toString();
16 | }
17 | }
--------------------------------------------------------------------------------
/src/test/java/com/t4a/examples/actions/CookingAction.java:
--------------------------------------------------------------------------------
1 | package com.t4a.examples.actions;
2 |
3 | import com.t4a.annotations.Action;
4 | import com.t4a.annotations.Agent;
5 | import com.t4a.annotations.Prompt;
6 |
7 | @Agent(groupName = "food" ,groupDescription = "all the tasks related to cooking")
8 | public class CookingAction {
9 |
10 | @Action(description = "This will be used for cooking dishes")
11 | public String cookThisForLunch(@Prompt(describe = "this should be comma separated") String ingredients) {
12 | return ingredients+" can be used to make spicy stuffed paratha";
13 | }
14 |
15 | }
16 |
--------------------------------------------------------------------------------
/src/test/java/com/t4a/examples/actions/Customer.java:
--------------------------------------------------------------------------------
1 | package com.t4a.examples.actions;
2 |
3 | import com.t4a.annotations.Prompt;
4 | import lombok.*;
5 |
6 | import java.util.Date;
7 |
8 | @NoArgsConstructor
9 | @AllArgsConstructor
10 | @Getter
11 | @Setter
12 | @ToString
13 | @EqualsAndHashCode
14 | public class Customer {
15 | private String firstName;
16 | private String lastName;
17 | @Prompt(describe = "convert this to Hindi")
18 | private String reasonForCalling;
19 | @Prompt(ignore = true)
20 | private String location;
21 | @Prompt(dateFormat = "yyyy-MM-dd" ,describe = "if you dont find date provide todays date in fieldValue")
22 | private Date dateJoined;
23 | }
24 |
--------------------------------------------------------------------------------
/src/test/java/com/t4a/examples/actions/CustomerWithQueryAction.java:
--------------------------------------------------------------------------------
1 | package com.t4a.examples.actions;
2 |
3 | import com.t4a.annotations.Action;
4 | import com.t4a.annotations.Agent;
5 | import com.t4a.annotations.Prompt;
6 |
7 | import java.util.Date;
8 |
9 | @Agent(groupName = "customer support", groupDescription = "actions related to customer support")
10 | public class CustomerWithQueryAction {
11 |
12 | @Action(description = "Customer has problem create ticket for him")
13 | public String computerRepairWithDetails(Customer customer, @Prompt(dateFormat = "yyyy-MM-dd") Date dateOfComp , @Prompt(describe = "this is customer complaint") String query) {
14 | return customer.toString();
15 | }
16 | }
--------------------------------------------------------------------------------
/src/test/java/com/t4a/examples/actions/ListAction.java:
--------------------------------------------------------------------------------
1 | package com.t4a.examples.actions;
2 |
3 | import com.t4a.annotations.Action;
4 | import com.t4a.annotations.Agent;
5 | import com.t4a.examples.pojo.Organization;
6 | import lombok.Getter;
7 | import lombok.Setter;
8 | import lombok.ToString;
9 |
10 | @Getter
11 | @Setter
12 | @ToString
13 | @Agent(groupName = "Organization", groupDescription = "Organization actions")
14 | public class ListAction {
15 |
16 | @Action(description = "add new orgranization")
17 | public Organization addOrganization(Organization org) {
18 |
19 | System.out.println(org);
20 | return org;
21 | }
22 | }
23 |
--------------------------------------------------------------------------------
/src/test/java/com/t4a/examples/actions/MapAction.java:
--------------------------------------------------------------------------------
1 | package com.t4a.examples.actions;
2 |
3 | import com.t4a.annotations.Action;
4 | import com.t4a.annotations.MapKeyType;
5 | import com.t4a.annotations.MapValueType;
6 | import com.t4a.annotations.Agent;
7 | import lombok.Getter;
8 | import lombok.Setter;
9 |
10 | import java.util.Map;
11 |
12 | @Getter
13 | @Setter
14 | @Agent
15 | public class MapAction {
16 |
17 |
18 |
19 | @Action(description = "add new Sports into the map")
20 | public Map addSports(@MapKeyType(Integer.class) @MapValueType(String.class) Map mapOfSportsName) {
21 |
22 | return mapOfSportsName;
23 | }
24 | }
25 |
--------------------------------------------------------------------------------
/src/test/java/com/t4a/examples/actions/MyDiaryAction.java:
--------------------------------------------------------------------------------
1 | package com.t4a.examples.actions;
2 |
3 | import com.t4a.annotations.Action;
4 | import com.t4a.annotations.Agent;
5 | import com.t4a.examples.pojo.MyDiary;
6 |
7 | @Agent
8 | public class MyDiaryAction {
9 | @Action(description = "This is my diary details")
10 | public MyDiary buildMyDiary(MyDiary diary) {
11 | //take whatever action you want to take
12 | return diary;
13 | }
14 | }
15 |
--------------------------------------------------------------------------------
/src/test/java/com/t4a/examples/actions/Player.java:
--------------------------------------------------------------------------------
1 | package com.t4a.examples.actions;
2 |
3 | import lombok.*;
4 |
5 | @NoArgsConstructor
6 | @AllArgsConstructor
7 | @Getter
8 | @Setter
9 | @EqualsAndHashCode
10 | @ToString
11 | public class Player {
12 | int matches;
13 | int maxScore;
14 | String firstName;
15 | String lastName;
16 |
17 |
18 |
19 | }
20 |
--------------------------------------------------------------------------------
/src/test/java/com/t4a/examples/actions/PlayerWithRestaurant.java:
--------------------------------------------------------------------------------
1 | package com.t4a.examples.actions;
2 |
3 | import com.t4a.annotations.Action;
4 | import com.t4a.annotations.Agent;
5 | import com.t4a.examples.basic.RestaurantPojo;
6 | import lombok.Getter;
7 | import lombok.extern.slf4j.Slf4j;
8 |
9 | @Slf4j
10 | @Agent
11 | public class PlayerWithRestaurant {
12 | @Getter
13 | private Player player;
14 | @Getter
15 | private RestaurantPojo restaurantPojo;
16 | @Action( description = "add restaurant and player details")
17 | public String notifyPlayerAndRestaurant(Player player, RestaurantPojo restaurantPojo) {
18 | log.debug(player.toString());
19 | log.debug(restaurantPojo.toString());
20 | this.player = player;
21 | this.restaurantPojo = restaurantPojo;
22 | return "yes i have notified";
23 | }
24 | }
25 |
--------------------------------------------------------------------------------
/src/test/java/com/t4a/examples/actions/ServerRestartAction.java:
--------------------------------------------------------------------------------
1 | package com.t4a.examples.actions;
2 |
3 | import com.t4a.annotations.Action;
4 | import com.t4a.annotations.Agent;
5 | import com.t4a.api.ActionRisk;
6 |
7 | @Agent(groupName = "server support", groupDescription = "actions related to server support")
8 | public class ServerRestartAction {
9 | @Action(riskLevel = ActionRisk.HIGH, description = "Restart the ECOM server")
10 | public String restartTheECOMServer(String reasonForRestart, String requestedBy) {
11 | return " Server has been restarted by "+requestedBy+" due to following reason "+reasonForRestart;
12 | }
13 | }
14 |
--------------------------------------------------------------------------------
/src/test/java/com/t4a/examples/actions/SimpleAction.java:
--------------------------------------------------------------------------------
1 | package com.t4a.examples.actions;
2 |
3 | import com.t4a.annotations.Action;
4 | import com.t4a.annotations.Agent;
5 |
6 | @Agent
7 | public class SimpleAction {
8 |
9 | @Action( description = "what is the food preference of this person")
10 | public String whatFoodDoesThisPersonLike(String name) {
11 | if("vishal".equalsIgnoreCase(name))
12 | return "Paneer Butter Masala";
13 | else if ("vinod".equalsIgnoreCase(name)) {
14 | return "aloo kofta";
15 | }else
16 | return "something yummy";
17 | }
18 |
19 | }
20 |
--------------------------------------------------------------------------------
/src/test/java/com/t4a/examples/actions/TrafficViolation.java:
--------------------------------------------------------------------------------
1 | package com.t4a.examples.actions;
2 |
3 | import com.t4a.annotations.Action;
4 | import com.t4a.annotations.Agent;
5 |
6 | @Agent
7 | public class TrafficViolation {
8 | @Action(description = "Traffic violation detected")
9 | public String trafficViolation(String typeOfViolation, String carColor) {
10 | System.out.println("car color "+carColor);
11 | return typeOfViolation+" has been detected there will penalty";
12 | }
13 | }
14 |
--------------------------------------------------------------------------------
/src/test/java/com/t4a/examples/actions/db/MongoAction.java:
--------------------------------------------------------------------------------
1 | package com.t4a.examples.actions.db;
2 |
3 | import com.t4a.annotations.Action;
4 | import com.t4a.annotations.Agent;
5 |
6 | /**
7 | * This is an action class for MongoDB it takes a prompt and inject the values into MongoDatabase
8 | *
9 | */
10 | @Agent(groupName = "MongoDB", groupDescription = "MongoDB related actions")
11 | public class MongoAction {
12 |
13 | @Action(description = "Inserts a customer complaint into the database")
14 | public Object createTable() {
15 |
16 | return "creatre table";
17 | }
18 |
19 |
20 |
21 | }
22 |
--------------------------------------------------------------------------------
/src/test/java/com/t4a/examples/actions/tibco/TibcoAction.java:
--------------------------------------------------------------------------------
1 | package com.t4a.examples.actions.tibco;
2 |
3 | import com.t4a.annotations.Action;
4 | import com.t4a.annotations.Agent;
5 |
6 | @Agent(groupName = "Tibco", groupDescription = "Tibco related actions")
7 | public class TibcoAction {
8 |
9 | @Action(description = "Send a message to a Tibco queue")
10 | public Object sendMessageToQueue() {
11 | return null;
12 |
13 | }
14 |
15 | }
16 |
--------------------------------------------------------------------------------
/src/test/java/com/t4a/examples/agriculture/EnvironmentConditions.java:
--------------------------------------------------------------------------------
1 | package com.t4a.examples.agriculture;
2 |
3 | import lombok.Getter;
4 | import lombok.NoArgsConstructor;
5 | import lombok.Setter;
6 | import lombok.ToString;
7 |
8 | @NoArgsConstructor
9 | @Getter
10 | @Setter
11 | @ToString
12 | public class EnvironmentConditions {
13 | private double waterPercentage;
14 | private double soilPercentage;
15 | private double sunlightPercentage;
16 | private double temperature;
17 | private boolean hasFrost;
18 | private boolean hasHeatWave;
19 | private boolean hasDrought;
20 | private boolean hasFlood;
21 | }
--------------------------------------------------------------------------------
/src/test/java/com/t4a/examples/agriculture/HealthStatus.java:
--------------------------------------------------------------------------------
1 | package com.t4a.examples.agriculture;
2 |
3 | import com.t4a.annotations.Prompt;
4 | import lombok.Getter;
5 | import lombok.NoArgsConstructor;
6 | import lombok.Setter;
7 | import lombok.ToString;
8 |
9 | @NoArgsConstructor
10 | @Getter
11 | @Setter
12 | @ToString
13 | public class HealthStatus {
14 | @Prompt(describe ="if it looks healthy then give 100% else give a percentage")
15 | private double healthPercentage;
16 | private boolean hasPest;
17 | private boolean hasDisease;
18 | private boolean hasNutrientDeficiency;
19 | private boolean doesItHaveAnyDisease;
20 | @Prompt(describe ="based on picture do you think the plant has any disease, if none then return NONE")
21 | private String typeOfDisease;
22 | }
--------------------------------------------------------------------------------
/src/test/java/com/t4a/examples/agriculture/Plant.java:
--------------------------------------------------------------------------------
1 | package com.t4a.examples.agriculture;
2 |
3 | import com.t4a.annotations.Prompt;
4 | import lombok.Getter;
5 | import lombok.NoArgsConstructor;
6 | import lombok.Setter;
7 | import lombok.ToString;
8 |
9 | @NoArgsConstructor
10 | @Getter
11 | @Setter
12 | @ToString
13 | public class Plant {
14 | @Prompt(describe ="what type is it CROP or FRUIT or VEGETABLE or FLOWER or TREE or SHRUB or GRASS or WEED or OTHER")
15 | private String platType;
16 | private String plantName;
17 | private HealthStatus healthStatus;
18 | private EnvironmentConditions environmentConditions;
19 | private boolean hasWaterDeficiency = false;;
20 | private boolean hasSunlightDeficiency = false;;
21 | private boolean hasSoilDeficiency = false;;
22 | private boolean hasTemperatureDeficiency = false;;
23 | }
24 |
25 |
--------------------------------------------------------------------------------
/src/test/java/com/t4a/examples/basic/DateDeserializer.java:
--------------------------------------------------------------------------------
1 | package com.t4a.examples.basic;
2 |
3 | import com.google.gson.JsonDeserializationContext;
4 | import com.google.gson.JsonDeserializer;
5 | import com.google.gson.JsonElement;
6 | import com.google.gson.JsonParseException;
7 |
8 | import java.lang.reflect.Type;
9 | import java.text.DateFormat;
10 | import java.text.ParseException;
11 | import java.text.SimpleDateFormat;
12 | import java.util.Date;
13 | import java.util.Locale;
14 |
15 | public class DateDeserializer implements JsonDeserializer {
16 | private final DateFormat dateFormat;
17 |
18 | public DateDeserializer(String format) {
19 | this.dateFormat = new SimpleDateFormat(format, Locale.ENGLISH);
20 | }
21 |
22 | @Override
23 | public Date deserialize(JsonElement json, Type typeOfT, JsonDeserializationContext context) throws JsonParseException {
24 | try {
25 | return dateFormat.parse(json.getAsString().replaceAll("(st|nd|rd|th),", ","));
26 | } catch (ParseException e) {
27 | return new Date();
28 | }
29 | }
30 | }
31 |
--------------------------------------------------------------------------------
/src/test/java/com/t4a/examples/basic/JsonBuilder.java:
--------------------------------------------------------------------------------
1 | package com.t4a.examples.basic;
2 |
3 | import com.t4a.deperecated.GeminiPromptTransformer;
4 | import com.t4a.processor.AIProcessingException;
5 | import lombok.extern.slf4j.Slf4j;
6 |
7 | @Slf4j
8 | public class JsonBuilder {
9 | public static void main(String[] args) throws AIProcessingException {
10 | GeminiPromptTransformer builder = new GeminiPromptTransformer();
11 | String jsonString = "{\"name\":\"String\",\"age\":\"number\",\"address\":{\"street\":\"String\",\"city\":\"String\",\"zip\":\"int\"},\"contacts\":[{\"type\":\"string\",\"value\":\"String\"},{\"type\":\"string\",\"value\":\"string\"}]}";
12 | String prompt = "Can you make sure you add this info about my friend John Doe, aged 30, lives at 123 Main St in New York, zip code 10001. He can be reached via email at john@example.com or by phone at 555-1234.";
13 | jsonString = builder.transformIntoJson(jsonString,prompt,"MyFriend","get friend details");
14 | log.debug(jsonString);
15 | }
16 | }
17 |
--------------------------------------------------------------------------------
/src/test/java/com/t4a/examples/basic/NonPredictionAction.java:
--------------------------------------------------------------------------------
1 | package com.t4a.examples.basic;
2 |
3 | import com.t4a.annotations.Action;
4 | import lombok.extern.slf4j.Slf4j;
5 |
6 | @Slf4j
7 | public class NonPredictionAction {
8 |
9 |
10 | @Action(description = "provide the food name here to check if it is good ")
11 | public String checkIfFoodisGoodForYou(String foodName) {
12 | log.debug(foodName);
13 | return foodName + " has too much sugar";
14 | }
15 |
16 |
17 | }
18 |
19 |
--------------------------------------------------------------------------------
/src/test/java/com/t4a/examples/basic/RestaurantDetails.java:
--------------------------------------------------------------------------------
1 | package com.t4a.examples.basic;
2 |
3 | public class RestaurantDetails {
4 | String name;
5 | //@Prompt(describe = "convert location to hindi")
6 | String location;
7 |
8 | public String getLocation() {
9 | return location;
10 | }
11 |
12 | public void setLocation(String location) {
13 | this.location = location;
14 | }
15 |
16 | @Override
17 | public String toString() {
18 | return "RestaurantDetails{" +
19 | "name='" + name + '\'' +
20 | ", location='" + location + '\'' +
21 | '}';
22 | }
23 |
24 | public String getName() {
25 | return name;
26 | }
27 |
28 | public void setName(String name) {
29 | this.name = name;
30 | }
31 | }
32 |
--------------------------------------------------------------------------------
/src/test/java/com/t4a/examples/pojo/Activity.java:
--------------------------------------------------------------------------------
1 | package com.t4a.examples.pojo;
2 |
3 | import lombok.Getter;
4 | import lombok.NoArgsConstructor;
5 | import lombok.Setter;
6 | import lombok.ToString;
7 |
8 | @Getter
9 | @Setter
10 | @NoArgsConstructor
11 | @ToString
12 | public class Activity {
13 | String dayOfTheWeek;
14 | String activityName;
15 | }
16 |
--------------------------------------------------------------------------------
/src/test/java/com/t4a/examples/pojo/AutoRepairScreen.java:
--------------------------------------------------------------------------------
1 | package com.t4a.examples.pojo;
2 |
3 | import lombok.*;
4 |
5 | @Getter
6 | @Setter
7 | @ToString
8 | @NoArgsConstructor
9 | @AllArgsConstructor
10 | public class AutoRepairScreen {
11 | double fullInspectionValue;
12 | double tireRotationValue;
13 | double oilChangeValue;
14 | Integer phoneNumber;
15 | String email;
16 | String[] customerReviews;
17 |
18 | }
19 |
--------------------------------------------------------------------------------
/src/test/java/com/t4a/examples/pojo/Dictionary.java:
--------------------------------------------------------------------------------
1 | package com.t4a.examples.pojo;
2 |
3 | import com.t4a.annotations.MapKeyType;
4 | import com.t4a.annotations.MapValueType;
5 | import lombok.AllArgsConstructor;
6 | import lombok.Getter;
7 | import lombok.NoArgsConstructor;
8 | import lombok.Setter;
9 |
10 | import java.util.Map;
11 |
12 | @Setter
13 | @Getter
14 | @NoArgsConstructor
15 | @AllArgsConstructor
16 | public class Dictionary {
17 | String nameOfDictionary;
18 | @MapValueType(String.class)
19 | @MapKeyType(String.class)
20 | Map wordMeanings;
21 | String locations[];
22 | }
23 |
--------------------------------------------------------------------------------
/src/test/java/com/t4a/examples/pojo/Employee.java:
--------------------------------------------------------------------------------
1 | package com.t4a.examples.pojo;
2 |
3 | import com.t4a.annotations.Prompt;
4 | import lombok.*;
5 |
6 | import java.util.Date;
7 |
8 | @Getter
9 | @Setter
10 | @NoArgsConstructor
11 | @AllArgsConstructor
12 | @ToString
13 | public class Employee {
14 | private String name;
15 | @Prompt(ignore = true)
16 | private int id;
17 | private String department;
18 | private double salary;
19 | private String location;
20 | @Prompt(dateFormat = "ddMMyyyy" ,describe = "convert to actual date")
21 | private Date dateJoined;
22 | private String[] tasks;
23 | }
24 |
--------------------------------------------------------------------------------
/src/test/java/com/t4a/examples/pojo/MyDiary.java:
--------------------------------------------------------------------------------
1 | package com.t4a.examples.pojo;
2 |
3 | import com.t4a.annotations.Prompt;
4 | import com.t4a.examples.actions.Customer;
5 | import lombok.Getter;
6 | import lombok.NoArgsConstructor;
7 | import lombok.Setter;
8 | import lombok.ToString;
9 |
10 | import java.util.Date;
11 |
12 | @Getter
13 | @Setter
14 | @NoArgsConstructor
15 | @ToString
16 | public class MyDiary {
17 | @Prompt(dateFormat = "ddMMyyyy")
18 | Date[] allTheDatesOfAppointment;
19 | String[] friendsNames;
20 | Customer customer;
21 | Employee employee;
22 | }
23 |
--------------------------------------------------------------------------------
/src/test/java/com/t4a/examples/pojo/MyGymSchedule.java:
--------------------------------------------------------------------------------
1 | package com.t4a.examples.pojo;
2 |
3 | import com.t4a.annotations.ListType;
4 | import lombok.Getter;
5 | import lombok.NoArgsConstructor;
6 | import lombok.Setter;
7 | import lombok.ToString;
8 |
9 | import java.util.List;
10 |
11 | @Getter
12 | @Setter
13 | @NoArgsConstructor
14 | @ToString
15 | public class MyGymSchedule {
16 | @ListType(Activity.class)
17 | List myWeeklyActivity;
18 |
19 | }
20 |
--------------------------------------------------------------------------------
/src/test/java/com/t4a/examples/pojo/Organization.java:
--------------------------------------------------------------------------------
1 | package com.t4a.examples.pojo;
2 |
3 | import com.t4a.annotations.ListType;
4 | import com.t4a.examples.actions.Customer;
5 | import lombok.*;
6 |
7 | import java.util.List;
8 |
9 | @Getter
10 | @Setter
11 | @NoArgsConstructor
12 | @AllArgsConstructor
13 | @ToString
14 | public class Organization {
15 | String name;
16 | @ListType(Employee.class)
17 | List em;
18 | @ListType(String.class)
19 | List locations;
20 | Customer[] customers;
21 | }
22 |
--------------------------------------------------------------------------------
/src/test/java/com/t4a/regression/TestHelperOpenAI.java:
--------------------------------------------------------------------------------
1 | package com.t4a.regression;
2 |
3 | import com.t4a.predict.PredictionLoader;
4 | import dev.langchain4j.model.chat.ChatLanguageModel;
5 | import lombok.extern.slf4j.Slf4j;
6 |
7 | @Slf4j
8 | public class TestHelperOpenAI {
9 |
10 |
11 | private ChatLanguageModel openAiChatModel;
12 | private static TestHelperOpenAI testAIHelper;
13 |
14 | private void initProp() {
15 | openAiChatModel = PredictionLoader.getInstance().getOpenAiChatModel();
16 | }
17 |
18 | private TestHelperOpenAI() {
19 | initProp();
20 | }
21 |
22 | public static TestHelperOpenAI getInstance() {
23 | if (testAIHelper == null)
24 | testAIHelper = new TestHelperOpenAI();
25 | return testAIHelper;
26 | }
27 |
28 | public String sendMessage(String msg) {
29 | return openAiChatModel.generate(msg);
30 | }
31 | }
--------------------------------------------------------------------------------
/src/test/java/com/t4a/test/AIProcessingExceptionTest.java:
--------------------------------------------------------------------------------
1 | package com.t4a.test;
2 |
3 |
4 |
5 | import com.t4a.processor.AIProcessingException;
6 | import org.junit.jupiter.api.Test;
7 |
8 | import static org.junit.jupiter.api.Assertions.assertEquals;
9 |
10 | public class AIProcessingExceptionTest {
11 |
12 | @Test
13 | public void testAIProcessingException() {
14 | String message = "Test exception message";
15 | AIProcessingException exception = new AIProcessingException(message);
16 |
17 | assertEquals(message, exception.getMessage());
18 | }
19 | }
--------------------------------------------------------------------------------
/src/test/java/com/t4a/test/ActionKeyTest.java:
--------------------------------------------------------------------------------
1 | package com.t4a.test;
2 |
3 | import com.t4a.api.ActionKey;
4 | import org.junit.jupiter.api.Test;
5 |
6 | import static org.junit.jupiter.api.Assertions.assertNotEquals;
7 |
8 | public class ActionKeyTest {
9 | @Test
10 | void testEqualsAndHashCode() {
11 | // Create two identical AIAction objects
12 | MockAction action1 = new MockAction();
13 |
14 |
15 | MockAction action2 = new MockAction();
16 |
17 |
18 | // Create two ActionKey objects using the identical AIAction objects
19 | ActionKey key1 = new ActionKey(action1);
20 | ActionKey key2 = new ActionKey(action2);
21 |
22 |
23 | assertNotEquals(key1, key2);
24 |
25 |
26 | assertNotEquals(key1.hashCode(), key2.hashCode());
27 |
28 |
29 | ActionKey key3 = new ActionKey(action1);
30 |
31 |
32 | assertNotEquals(key1, key3);
33 |
34 | // The hash codes of the first ActionKey object and the third ActionKey object should noy be the same
35 | assertNotEquals(key1.hashCode(), key3.hashCode());
36 | }
37 | }
38 |
--------------------------------------------------------------------------------
/src/test/java/com/t4a/test/BiasDetectorTest.java:
--------------------------------------------------------------------------------
1 | package com.t4a.test;
2 |
3 | import com.t4a.api.ActionType;
4 | import com.t4a.api.GuardRailException;
5 | import com.t4a.detect.BiasDetector;
6 | import org.junit.jupiter.api.BeforeEach;
7 | import org.junit.jupiter.api.Test;
8 |
9 | import static org.junit.jupiter.api.Assertions.*;
10 |
11 | public class BiasDetectorTest {
12 |
13 | private BiasDetector biasDetector;
14 |
15 | @BeforeEach
16 | public void setup() {
17 | biasDetector = new BiasDetector();
18 | }
19 |
20 | @Test
21 | public void testGetActionType() {
22 | assertEquals(ActionType.BIAS, biasDetector.getActionType());
23 | }
24 |
25 | @Test
26 | public void testGetDescription() {
27 | assertEquals("Detect Bias in response", biasDetector.getDescription());
28 | }
29 |
30 | @Test
31 | public void testExecute() throws GuardRailException {
32 | assertNull(biasDetector.execute(null));
33 | assertNotNull(biasDetector.getActionName());
34 | assertEquals("execute", biasDetector.getActionName());
35 |
36 | }
37 | }
--------------------------------------------------------------------------------
/src/test/java/com/t4a/test/DriverActionsTest.java:
--------------------------------------------------------------------------------
1 | package com.t4a.test;
2 |
3 | import com.t4a.processor.selenium.DriverActions;
4 | import org.junit.jupiter.api.BeforeEach;
5 | import org.junit.jupiter.api.Test;
6 |
7 | import static org.junit.jupiter.api.Assertions.assertEquals;
8 |
9 | public class DriverActionsTest {
10 | private DriverActions driverActions;
11 |
12 | @BeforeEach
13 | public void setUp() {
14 | driverActions = new DriverActions();
15 | }
16 |
17 | @Test
18 | public void testTypeOfActionToTakeOnWebDriver() {
19 | String expectedAction = "navigate";
20 | driverActions.setTypeOfActionToTakeOnWebDriver(expectedAction);
21 | String actualAction = driverActions.getTypeOfActionToTakeOnWebDriver();
22 | assertEquals(expectedAction, actualAction, "The action should be navigate");
23 | }
24 | }
--------------------------------------------------------------------------------
/src/test/java/com/t4a/test/ExtendedInputParameterTest.java:
--------------------------------------------------------------------------------
1 | package com.t4a.test;
2 |
3 |
4 |
5 |
6 |
7 | import com.t4a.action.ExtendedInputParameter;
8 | import org.junit.jupiter.api.Test;
9 |
10 | import static org.junit.jupiter.api.Assertions.assertEquals;
11 | import static org.junit.jupiter.api.Assertions.assertNull;
12 |
13 | public class ExtendedInputParameterTest {
14 |
15 | @Test
16 | public void testExtendedInputParameter() {
17 | // Create an instance of ExtendedInputParameter
18 | ExtendedInputParameter inputParameter = new ExtendedInputParameter("TestName", "TestValue");
19 |
20 | // Test the methods of ExtendedInputParameter
21 | assertEquals("TestName", inputParameter.getName());
22 | assertEquals(false, inputParameter.hasDefaultValue());
23 | assertEquals("TestValue", inputParameter.getType());
24 | assertNull(inputParameter.getDefaultValueStr());
25 | }
26 | }
--------------------------------------------------------------------------------
/src/test/java/com/t4a/test/FactDetectorTest.java:
--------------------------------------------------------------------------------
1 | package com.t4a.test;
2 |
3 | import com.t4a.api.ActionType;
4 | import com.t4a.api.GuardRailException;
5 | import com.t4a.detect.DetectValues;
6 | import com.t4a.detect.FactDetector;
7 | import org.junit.jupiter.api.BeforeEach;
8 | import org.junit.jupiter.api.Test;
9 |
10 | import static org.junit.jupiter.api.Assertions.*;
11 |
12 | class FactDetectorTest {
13 |
14 | private FactDetector factDetector;
15 |
16 | @BeforeEach
17 | public void setup() {
18 | factDetector = new FactDetector();
19 | }
20 |
21 | @Test
22 | void testGetActionType() {
23 | assertEquals(ActionType.FACT, factDetector.getActionType());
24 | }
25 |
26 | @Test
27 | void testGetDescription() {
28 | assertEquals("Fact Check in response", factDetector.getDescription());
29 | }
30 |
31 | @Test
32 | void testExecute() throws GuardRailException {
33 | assertNull(factDetector.execute(new DetectValues()));
34 | }
35 | }
--------------------------------------------------------------------------------
/src/test/java/com/t4a/test/GeminiGuardRailsTest.java:
--------------------------------------------------------------------------------
1 | package com.t4a.test;
2 |
3 | import com.t4a.api.GeminiGuardRails;
4 | import com.t4a.api.GuardRailException;
5 | import org.junit.jupiter.api.Assertions;
6 | import org.junit.jupiter.api.BeforeEach;
7 | import org.junit.jupiter.api.Test;
8 |
9 | public class GeminiGuardRailsTest {
10 |
11 | private GeminiGuardRails geminiGuardRails;
12 |
13 | @BeforeEach
14 | public void setUp() {
15 | geminiGuardRails = new GeminiGuardRails();
16 |
17 | }
18 |
19 | @Test
20 | public void testMethod1() throws GuardRailException {
21 | Assertions.assertFalse(geminiGuardRails.validateRequest("test"));
22 | }
23 |
24 | }
25 |
--------------------------------------------------------------------------------
/src/test/java/com/t4a/test/GuardRailExceptionTest.java:
--------------------------------------------------------------------------------
1 | package com.t4a.test;
2 |
3 |
4 | import com.t4a.api.GuardRailException;
5 | import org.junit.jupiter.api.Test;
6 |
7 | import static org.junit.jupiter.api.Assertions.assertThrows;
8 |
9 | public class GuardRailExceptionTest {
10 |
11 | @Test
12 | public void testGuardRailException() {
13 | assertThrows(GuardRailException.class, () -> {
14 | throw new GuardRailException("Test exception");
15 | });
16 | }
17 | }
18 |
--------------------------------------------------------------------------------
/src/test/java/com/t4a/test/HallucinationDetectorTypeTest.java:
--------------------------------------------------------------------------------
1 | package com.t4a.test;
2 |
3 | import com.t4a.detect.HallucinationDetectorType;
4 | import org.junit.jupiter.api.Test;
5 |
6 | import static org.junit.jupiter.api.Assertions.*;
7 |
8 | public class HallucinationDetectorTypeTest {
9 |
10 | @Test
11 | public void testEnumValues() {
12 | assertEquals(2, HallucinationDetectorType.values().length);
13 | assertEquals(HallucinationDetectorType.GOOGLE, HallucinationDetectorType.values()[0]);
14 | assertEquals(HallucinationDetectorType.SELF, HallucinationDetectorType.values()[1]);
15 | }
16 | }
17 |
--------------------------------------------------------------------------------
/src/test/java/com/t4a/test/InputParameterTest.java:
--------------------------------------------------------------------------------
1 | package com.t4a.test;
2 |
3 |
4 |
5 | import com.t4a.action.http.InputParameter;
6 | import org.junit.jupiter.api.Test;
7 |
8 | import static org.junit.jupiter.api.Assertions.*;
9 |
10 | public class InputParameterTest {
11 |
12 | @Test
13 | public void testInputParameter() {
14 | String name = "Test name";
15 | String type = "Test type";
16 | String description = "Test description";
17 | InputParameter inputParameter = new InputParameter(name, type, description);
18 |
19 | assertEquals(name, inputParameter.getName());
20 | assertEquals(type, inputParameter.getType());
21 | assertEquals(description, inputParameter.getDescription());
22 | }
23 |
24 | @Test
25 | public void testHasDefaultValue() {
26 | InputParameter inputParameter = new InputParameter();
27 | assertFalse(inputParameter.hasDefaultValue());
28 |
29 | inputParameter.setDefaultValue("Default value");
30 | assertTrue(inputParameter.hasDefaultValue());
31 | }
32 | }
33 |
--------------------------------------------------------------------------------
/src/test/java/com/t4a/test/LogginggExplainDecisionTest.java:
--------------------------------------------------------------------------------
1 | package com.t4a.test;
2 |
3 | import com.t4a.processor.LogginggExplainDecision;
4 | import org.junit.jupiter.api.Assertions;
5 | import org.junit.jupiter.api.Test;
6 |
7 | public class LogginggExplainDecisionTest {
8 |
9 | @Test
10 | void testExplain() {
11 |
12 | LogginggExplainDecision decision = new LogginggExplainDecision();
13 |
14 | String promptText = "promptText";
15 | String methodName = "methodName";
16 | String reason = "reason";
17 |
18 | Assertions.assertEquals(reason,decision.explain(promptText, methodName, reason));
19 |
20 |
21 | }
22 | }
23 |
--------------------------------------------------------------------------------
/src/test/java/com/t4a/test/MimeTypeTest.java:
--------------------------------------------------------------------------------
1 | package com.t4a.test;
2 |
3 | import com.t4a.api.MimeType;
4 | import org.junit.jupiter.api.Assertions;
5 | import org.junit.jupiter.api.Test;
6 |
7 | public class MimeTypeTest {
8 | @Test
9 | void testGetMimeType() {
10 | Assertions.assertEquals("image/jpeg", MimeType.JPEG.getMimeType());
11 | Assertions.assertEquals("image/png", MimeType.PNG.getMimeType());
12 | Assertions.assertEquals("image/gif", MimeType.GIF.getMimeType());
13 | Assertions.assertEquals("text/html", MimeType.HTML.getMimeType());
14 | Assertions.assertEquals("text/plain", MimeType.TEXT.getMimeType());
15 | Assertions.assertEquals("application/pdf", MimeType.PDF.getMimeType());
16 | Assertions.assertEquals("application/msword", MimeType.MS_WORD.getMimeType());
17 | Assertions.assertEquals("application/vnd.oasis.opendocument.text", MimeType.OPEN_DOCUMENT_TEXT.getMimeType());
18 | }
19 | }
20 |
--------------------------------------------------------------------------------
/src/test/java/com/t4a/test/MockAction.java:
--------------------------------------------------------------------------------
1 | package com.t4a.test;
2 |
3 | import com.t4a.api.ActionRisk;
4 | import com.t4a.api.ActionType;
5 | import com.t4a.api.JavaMethodAction;
6 |
7 | public class MockAction implements JavaMethodAction {
8 |
9 | public Person p;
10 | public String name;
11 | @Override
12 | public String getActionName() {
13 | return "mockAction";
14 | }
15 |
16 | public String mockAction(String mockName,Person mockPerson) {
17 | p = mockPerson;
18 | name = mockName;
19 | return mockName;
20 | }
21 |
22 | @Override
23 | public String getDescription() {
24 | return "mockActionDescription";
25 | }
26 |
27 |
28 |
29 |
30 | }
31 |
--------------------------------------------------------------------------------
/src/test/java/com/t4a/test/Person.java:
--------------------------------------------------------------------------------
1 | package com.t4a.test;
2 |
3 | import lombok.Getter;
4 | import lombok.NoArgsConstructor;
5 | import lombok.Setter;
6 | import lombok.ToString;
7 |
8 | @Getter
9 | @Setter
10 | @ToString
11 | @NoArgsConstructor
12 | public class Person {
13 | public String name;
14 | public int age;
15 |
16 | public Person(String name, int age) {
17 | this.name = name;
18 | this.age = age;
19 | }
20 |
21 | // getters and setters
22 | }
23 |
--------------------------------------------------------------------------------
/src/test/java/com/t4a/test/PromptInjectionValidatorTest.java:
--------------------------------------------------------------------------------
1 | package com.t4a.test;
2 |
3 | import com.t4a.detect.PromptInjectionValidator;
4 | import org.junit.jupiter.api.BeforeEach;
5 | import org.junit.jupiter.api.Test;
6 |
7 | import static org.junit.jupiter.api.Assertions.assertFalse;
8 | import static org.junit.jupiter.api.Assertions.assertTrue;
9 |
10 | class PromptInjectionValidatorTest {
11 |
12 | private PromptInjectionValidator promptInjectionValidator;
13 |
14 | @BeforeEach
15 | public void setup() {
16 | promptInjectionValidator = new PromptInjectionValidator();
17 | }
18 |
19 | @Test
20 | public void testIsValidPrompt() {
21 | assertTrue(promptInjectionValidator.isValidPrompt("This is a safe prompt."));
22 | assertFalse(promptInjectionValidator.isValidPrompt("This prompt contains a threat: delete"));
23 | assertFalse(promptInjectionValidator.isValidPrompt("This prompt contains a disallowed character: #"));
24 | }
25 | }
26 |
--------------------------------------------------------------------------------
/src/test/java/com/t4a/test/PromptTest.java:
--------------------------------------------------------------------------------
1 | package com.t4a.test;
2 | import com.t4a.processor.chain.Prompt;
3 | import com.t4a.processor.chain.SubPrompt;
4 | import org.junit.jupiter.api.Test;
5 |
6 | import java.util.Arrays;
7 | import java.util.List;
8 |
9 | import static org.junit.jupiter.api.Assertions.assertEquals;
10 |
11 | public class PromptTest {
12 |
13 | @Test
14 | public void testPrompt() {
15 | // Arrange
16 | SubPrompt subPrompt1 = new SubPrompt();
17 | subPrompt1.setId("1");
18 | subPrompt1.setSubprompt("SubPrompt 1");
19 | subPrompt1.setDepend_on("Depend 1");
20 |
21 | SubPrompt subPrompt2 = new SubPrompt();
22 | subPrompt2.setId("2");
23 | subPrompt2.setSubprompt("SubPrompt 2");
24 | subPrompt2.setDepend_on("Depend 2");
25 |
26 | List subPrompts = Arrays.asList(subPrompt1, subPrompt2);
27 |
28 | // Act
29 | Prompt prompt = new Prompt();
30 | prompt.setPrmpt(subPrompts);
31 |
32 | // Assert
33 | assertEquals(subPrompts, prompt.getPrmpt());
34 | }
35 | }
--------------------------------------------------------------------------------
/src/test/java/com/t4a/test/ToolsConstantsTest.java:
--------------------------------------------------------------------------------
1 | package com.t4a.test;
2 |
3 | import com.t4a.api.ToolsConstants;
4 | import org.junit.jupiter.api.Test;
5 |
6 | import static org.junit.jupiter.api.Assertions.*;
7 |
8 | public class ToolsConstantsTest {
9 |
10 | @Test
11 | public void testConstants() {
12 | assertEquals("BlankAction", ToolsConstants.BLANK_ACTION);
13 | assertEquals("SeleniumAction", ToolsConstants.SELENIUM_ACTION);
14 | assertEquals("AIProcessor", ToolsConstants.AI_PROCESSOR);
15 | assertEquals("Agent", ToolsConstants.PREDICT);
16 | assertEquals("No Group", ToolsConstants.GROUP_NAME);
17 | assertEquals("tasks which are not categorized", ToolsConstants.GROUP_DESCRIPTION);
18 | }
19 | }
--------------------------------------------------------------------------------
/src/test/resources/auto.PNG:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/vishalmysore/Tools4AI/f4789d6336d653f11b250f60046c51acae130651/src/test/resources/auto.PNG
--------------------------------------------------------------------------------
/src/test/resources/fitness.PNG:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/vishalmysore/Tools4AI/f4789d6336d653f11b250f60046c51acae130651/src/test/resources/fitness.PNG
--------------------------------------------------------------------------------
/src/test/resources/logback.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 | %msg%n
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
--------------------------------------------------------------------------------
/src/test/resources/prompt.properties:
--------------------------------------------------------------------------------
1 | openai.pre_action=here is my prompt -
2 | openai.action=- what action do you think we should take out of these - {
3 | openai.post_action= } - reply back with
4 | openai.num_action= action only. Make sure Action matches exactly from this list
5 | openai.method_to_json=- if you find the field named fieldValue, populate the field else and return the json as is
--------------------------------------------------------------------------------
/src/test/resources/test.action:
--------------------------------------------------------------------------------
1 | I need to search Indian Recipe on the internet
2 | save these indian recipe names to a file
--------------------------------------------------------------------------------
/src/test/resources/testApplicationContext.xml:
--------------------------------------------------------------------------------
1 |
2 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
--------------------------------------------------------------------------------
/src/test/resources/test_script.cmd:
--------------------------------------------------------------------------------
1 | @echo off
2 | echo Arguments passed to the script:
3 | echo %*
--------------------------------------------------------------------------------
/src/test/resources/tools4ai.properties:
--------------------------------------------------------------------------------
1 | ##Gemini related settings
2 | gemini.modelName=gemini-1.0-pro
3 | #gemini.modelName=test
4 | #gemini.modelName=gemini-1.5-pro-preview-0409
5 | gemini.location=us-central1
6 | gemini.projectId=cookgptserver
7 | #gemini.projectId=test
8 | gemini.vision.modelName=gemini-1.0-pro-vision
9 |
10 | ##Anthropic related settings
11 | anthropic.modelName=claude-3-haiku-20240307
12 | anthropic.logRequests=true
13 | anthropic.logResponse=true
14 |
15 | #set it here or use -DclaudeKey parameter
16 | claudeKey=
17 |
18 | ##Open AI Key
19 | #set it here or use -DopenAiKey parameter
20 | openAiKey=
21 | ##Open AI Base URL keep it empty or set it here or in vm option
22 | openAiBaseURL=
23 |
24 | openAiModelName=grok-2-1212
25 |
26 | ##Serper Key for google search or hallucination detection
27 | serperKey=
--------------------------------------------------------------------------------
/src/test/resources/web.action:
--------------------------------------------------------------------------------
1 | go to website https://the-internet.herokuapp.com
2 | click on A/B Testing
3 | save screenshot as "the-internet.herokuapp.com.png"
4 | go to website https://the-internet.herokuapp.com
5 | click on Add/Remove Elements
6 | click on Add Element
7 | save screenshot as "the-internet.herokuapp.com_2.png"
8 |
--------------------------------------------------------------------------------
/the-internet.herokuapp.com.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/vishalmysore/Tools4AI/f4789d6336d653f11b250f60046c51acae130651/the-internet.herokuapp.com.png
--------------------------------------------------------------------------------
/tools4ai.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/vishalmysore/Tools4AI/f4789d6336d653f11b250f60046c51acae130651/tools4ai.png
--------------------------------------------------------------------------------
/tools4ai_old.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/vishalmysore/Tools4AI/f4789d6336d653f11b250f60046c51acae130651/tools4ai_old.png
--------------------------------------------------------------------------------
/uploadnumber.sh:
--------------------------------------------------------------------------------
1 | #!/bin/bash
2 |
3 | # Assuming Maven generates XML test reports in the "target/surefire-reports" directory
4 | TEST_REPORT_DIR="target/surefire-reports"
5 | # Print current directory
6 | echo "Current directory: $(pwd)"
7 |
8 | xml_files=$(find "$(pwd)" -name "TEST-*.xml")
9 |
10 | # Concatenate all XML files and count the occurrences of " /dev/null
26 | exec 2>&1
27 |
28 | # Create or update the Gist with the test count
29 | curl -s -X PATCH \
30 | -H "Authorization: token $GIST_TOKEN" \
31 | -H "Content-Type: application/vnd.github+json" \
32 | -d '{"files":{"test.json":{"content": "{\"schemaVersion\": 1,\"label\": \"testcount\", \"message\": \"'$test_count'\", \"color\":\"orange\"}" }}}' \
33 | "https://api.github.com/gists/$GIST_ID"
--------------------------------------------------------------------------------