Skip to content

Commit

Permalink
open ai, pojo, actions , refactoring
Browse files Browse the repository at this point in the history
  • Loading branch information
vishalmysore committed Apr 10, 2024
1 parent 1ab6f52 commit 8ad2164
Show file tree
Hide file tree
Showing 24 changed files with 120 additions and 49 deletions.
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
<dependency>
<groupId>io.github.vishalmysore</groupId>
<artifactId>tools4ai</artifactId>
<version>0.9.4</version>
<version>0.9.5</version>
</dependency>
<dependency>
<groupId>ch.qos.logback</groupId>
Expand Down
1 change: 1 addition & 0 deletions src/main/java/org/example/ComplexActionExample.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import com.t4a.processor.AIProcessingException;
import com.t4a.processor.ActionProcessor;
import lombok.extern.java.Log;
import org.example.actions.AddRestaurantAction;

/**
* This will create the Player Pojo in real time and call the action
Expand Down
24 changes: 1 addition & 23 deletions src/main/java/org/example/Main.java
Original file line number Diff line number Diff line change
@@ -1,31 +1,9 @@
package org.example;

import com.google.cloud.vertexai.VertexAI;
import com.google.cloud.vertexai.api.Content;
import com.google.cloud.vertexai.api.FunctionDeclaration;
import com.google.cloud.vertexai.api.GenerateContentResponse;
import com.google.cloud.vertexai.api.Tool;
import com.google.cloud.vertexai.generativeai.*;
import com.t4a.action.BlankAction;
import com.t4a.api.AIAction;
import com.t4a.api.JavaMethodExecutor;
import com.t4a.predict.Predict;
import com.t4a.predict.PredictionLoader;
import com.t4a.processor.AIProcessingException;
import com.t4a.processor.ActionProcessor;
import com.t4a.processor.OpenAiActionProcessor;
import io.swagger.v3.oas.models.OpenAPI;
import io.swagger.v3.oas.models.PathItem;
import io.swagger.v3.parser.converter.SwaggerConverter;
import lombok.extern.java.Log;
import org.springframework.beans.factory.config.BeanDefinition;
import org.springframework.context.annotation.ClassPathScanningCandidateComponentProvider;
import org.springframework.core.io.support.PathMatchingResourcePatternResolver;
import org.springframework.core.type.filter.AnnotationTypeFilter;

import java.io.IOException;
import java.lang.reflect.InvocationTargetException;
import java.util.*;
import org.example.actions.GoogleSearchAction;

@Log
public class Main {
Expand Down
34 changes: 34 additions & 0 deletions src/main/java/org/example/OpenAIActionExample.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
package org.example;

import com.t4a.processor.AIProcessingException;
import com.t4a.processor.OpenAiActionProcessor;
import lombok.extern.java.Log;
import org.example.actions.AddRestaurantAction;

@Log
public class OpenAIActionExample {
public static void main(String[] args) throws AIProcessingException {
OpenAiActionProcessor processor = new OpenAiActionProcessor();
String promptTxt ="Sachin Tendulkar is very good cricket player, " +
"he joined the sports on 24032022, he has played 300 matches " +
"and his max score is 400. Can you send him a congratulations email";
String response = (String)processor.processSingleAction(promptTxt);
response = processor.query(promptTxt,response);
log.info(response);


promptTxt = "Sachin Tendulkar is very good cricket player, \" +\n" +
" \"he joined the sports on 24032022, he has played 300 matches \" +\n" +
" \"and his max score is 400." +
"can you book Maharaja restaurant in " +
"Toronto for Sachin Tendulkar and 4 people on 12th may. Please notify him and the restaurant ";
response = (String)processor.processSingleAction(promptTxt);
log.info(response);

promptTxt ="Maharaja restaurant in \" +\n" +
" \"Toronto for Sachin Tendulkar and 4 people on 12th may";
response = (String)processor.processSingleAction(promptTxt, new AddRestaurantAction());
log.info(response);

}
}
2 changes: 2 additions & 0 deletions src/main/java/org/example/PojoExample.java
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@
import com.t4a.predict.PromptTransformer;
import com.t4a.processor.AIProcessingException;
import lombok.extern.java.Log;
import org.example.pojo.Player;
import org.example.pojo.RestaurantPojo;
import org.example.util.DateDeserializer;

import java.util.Date;
Expand Down
14 changes: 14 additions & 0 deletions src/main/java/org/example/TranslationPojoExample.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
package org.example;

import com.t4a.predict.OpenAIPromptTransformer;
import com.t4a.processor.AIProcessingException;
import org.example.pojo.MyTranslatePojo;

public class TranslationPojoExample {
public static void main(String[] args) throws AIProcessingException {
OpenAIPromptTransformer tra = new OpenAIPromptTransformer();
String promptTxt = "paneer is so good";
MyTranslatePojo myp = (MyTranslatePojo)tra.transformIntoPojo(promptTxt,MyTranslatePojo.class.getName());
System.out.println(myp);
}
}
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
package org.example;
package org.example.actions;

import com.t4a.annotations.Predict;
import com.t4a.api.JavaMethodAction;
import com.t4a.predict.Predict;

import lombok.extern.java.Log;
import org.example.pojo.RestaurantPojo;

@Log
@Predict(actionName = "addRestaurantDetails",description = "saves the information in local file")
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package org.example;
package org.example.actions;
import com.t4a.annotations.Predict;
import com.t4a.api.JavaMethodAction;
import com.t4a.predict.Predict;

import lombok.extern.java.Log;

import java.io.File;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
package org.example;
package org.example.actions;

import com.t4a.annotations.Predict;
import com.t4a.api.JavaMethodAction;
import com.t4a.predict.Predict;

import com.t4a.predict.PredictionLoader;
import kong.unirest.core.HttpResponse;
import kong.unirest.core.Unirest;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
package org.example;
package org.example.actions;

import com.t4a.annotations.Predict;
import com.t4a.api.JavaMethodAction;
import com.t4a.predict.Predict;

import lombok.extern.java.Log;
import org.example.pojo.Player;

@Log
@Predict(actionName = "notifyPlayer",description = "send email to player")
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
package org.example;
package org.example.actions;

import com.t4a.annotations.Predict;
import com.t4a.api.JavaMethodAction;
import com.t4a.api.JavaMethodAction;
import com.t4a.predict.Predict;

import lombok.extern.java.Log;
import org.example.pojo.Player;
import org.example.pojo.RestaurantPojo;

@Log
@Predict(actionName = "notifyPlayerAndRestaurant",description = "send email to player")
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
package org.example;
package org.example.actions;

import com.t4a.annotations.Predict;
import com.t4a.api.AIAction;
import com.t4a.api.ActionType;
import com.t4a.api.JavaMethodAction;
import com.t4a.predict.Predict;


@Predict(actionName ="whatFoodDoesThisPersonLike", description = "Provide persons name and then find out what does that person like")
public class SimpleAction implements JavaMethodAction {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
package org.example;
package org.example.actions;

import com.t4a.annotations.Predict;
import com.t4a.api.AIAction;
import com.t4a.api.ActionType;
import com.t4a.api.JavaMethodAction;
import com.t4a.predict.Predict;

import lombok.extern.java.Log;
import org.json.JSONArray;
import org.json.JSONObject;
Expand Down
21 changes: 21 additions & 0 deletions src/main/java/org/example/pojo/MyTranslatePojo.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
package org.example.pojo;

import com.t4a.annotations.Prompt;
import lombok.Getter;
import lombok.NoArgsConstructor;
import lombok.Setter;
import lombok.ToString;

@Setter
@Getter
@NoArgsConstructor
@ToString
public class MyTranslatePojo {
@Prompt(describe = "translate to Hindi")
String answerInHindi;
@Prompt(describe = "translate to Punjabi")
String answerInPunJabi;

@Prompt(describe = "translate to Tamil")
String answerInTamil;
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package org.example;
package org.example.pojo;

import com.t4a.annotations.Prompt;
import lombok.*;
import lombok.extern.java.Log;

Expand All @@ -16,6 +17,7 @@ public class Player {
int maxScore;
String firstName;
String lastName;
@Prompt(dateFormat = "ddMMyyyy")
Date dateJoined;


Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package org.example;
package org.example.pojo;

public class RestaurantDetails {
String name;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
package org.example;
package org.example.pojo;

import org.example.pojo.RestaurantDetails;

public class RestaurantPojo {
String name;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
package org.example.script.actions;

import com.t4a.annotations.Predict;
import com.t4a.api.JavaMethodAction;
import com.t4a.predict.Predict;


@Predict(actionName = "reserveFlight", description = "book the flight for customer")
public class BookFlightAction implements JavaMethodAction {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
package org.example.script.actions;

import com.t4a.annotations.Predict;
import com.t4a.api.JavaMethodAction;
import com.t4a.predict.Predict;


@Predict(actionName = "checkLogs", description = " Finds a particular text in Logs")
public class CheckLogsAction implements JavaMethodAction {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
package org.example.script.actions;

import com.t4a.annotations.Predict;
import com.t4a.api.JavaMethodAction;
import com.t4a.predict.Predict;


@Predict(actionName = "reserveRentalCar", description = "book the rental car")
public class RentalCarAction implements JavaMethodAction {
Expand Down
3 changes: 2 additions & 1 deletion src/main/java/org/example/script/actions/SeleniumAction.java
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
package org.example.script.actions;

import com.t4a.annotations.Predict;
import com.t4a.api.JavaMethodAction;
import com.t4a.predict.Predict;


@Predict(actionName = "", description = "")
public class SeleniumAction implements JavaMethodAction {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
package org.example.script.actions;

import com.t4a.annotations.Predict;
import com.t4a.api.ActionRisk;
import com.t4a.api.JavaMethodAction;
import com.t4a.predict.Predict;


/**
* Making the risk level as HIGH to demonstrate it cannot be called without explicit mention by Human Operator
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
package org.example.script.actions;

import com.t4a.annotations.Predict;
import com.t4a.api.JavaMethodAction;
import com.t4a.predict.Predict;


@Predict(actionName = "reserveSightSeeing", description = "book sight seeing action")
public class SightSeeingAction implements JavaMethodAction {
Expand Down
3 changes: 2 additions & 1 deletion src/main/java/org/example/script/actions/TibcoAction.java
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
package org.example.script.actions;

import com.t4a.annotations.Predict;
import com.t4a.api.JavaMethodAction;
import com.t4a.predict.Predict;


@Predict(actionName = "notifyApplications", description = "notify all the downstream applications")
public class TibcoAction implements JavaMethodAction {
Expand Down

0 comments on commit 8ad2164

Please sign in to comment.