-
Notifications
You must be signed in to change notification settings - Fork 15
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
7 changed files
with
239 additions
and
0 deletions.
There are no files selected for viewing
19 changes: 19 additions & 0 deletions
19
examples/java/src/main/java/com/xebia/functional/xef/java/auto/Book.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
package com.xebia.functional.xef.java.auto; | ||
|
||
import java.util.concurrent.ExecutionException; | ||
|
||
public class Book { | ||
|
||
public String title; | ||
public String author; | ||
public String summary; | ||
|
||
public static void main(String[] args) throws ExecutionException, InterruptedException { | ||
try (AIScope scope = new AIScope()) { | ||
scope.prompt("To Kill a Mockingbird by Harper Lee summary.", Book.class) | ||
.thenAccept(book -> System.out.println("To Kill a Mockingbird summary:\n" + book.summary)) | ||
.get(); | ||
} | ||
} | ||
|
||
} |
76 changes: 76 additions & 0 deletions
76
examples/java/src/main/java/com/xebia/functional/xef/java/auto/ChessAI.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,76 @@ | ||
package com.xebia.functional.xef.java.auto; | ||
|
||
import java.util.ArrayList; | ||
import java.util.concurrent.ExecutionException; | ||
import java.util.stream.Collectors; | ||
|
||
public class ChessAI { | ||
|
||
private static class ChessMove { | ||
public String player; | ||
public String move; | ||
|
||
@Override | ||
public String toString() { | ||
return "ChessMove{" + | ||
"player='" + player + '\'' + | ||
", move='" + move + '\'' + | ||
'}'; | ||
} | ||
} | ||
|
||
private static class ChessBoard { | ||
public String board; | ||
} | ||
|
||
private static class GameState { | ||
public Boolean ended; | ||
public String winner; | ||
} | ||
|
||
public static void main(String[] args) throws ExecutionException, InterruptedException { | ||
try (AIScope scope = new AIScope()) { | ||
var moves = new ArrayList<ChessMove>(); | ||
var gameEnded = false; | ||
var winner = ""; | ||
|
||
while (!gameEnded) { | ||
var currentPlayer = ((moves.size() % 2) == 0) ? "Player 1 (White)" : "Player 2 (Black)"; | ||
|
||
var prompt = String.format(""" | ||
|%s, it's your turn. | ||
|Previous moves: %s | ||
|Make your next move:""", | ||
currentPlayer, | ||
moves.stream().map(ChessMove::toString).collect(Collectors.joining(", "))); | ||
|
||
ChessMove move = scope.prompt(prompt, ChessMove.class).get(); | ||
moves.add(move); | ||
|
||
// Update boardState according to move.move | ||
// ... | ||
|
||
var boardPrompt = String.format(""" | ||
Given the following chess moves: %s, | ||
generate a chess board on a table with appropriate emoji representations for each move and piece. | ||
Add a brief description of the move and it's implications""", | ||
moves.stream().map(it -> it.player + ":" + it.move).collect(Collectors.joining(", "))); | ||
|
||
ChessBoard chessBoard= scope.prompt(boardPrompt, ChessBoard.class).get(); | ||
System.out.println("Current board:\n" + chessBoard.board); | ||
|
||
var gameStatePrompt = String.format(""" | ||
Given the following chess moves: %s, | ||
has the game ended (win, draw, or stalemate)?""", | ||
moves.stream().map(ChessMove::toString).collect(Collectors.joining(", "))); | ||
|
||
GameState gameState = scope.prompt(gameStatePrompt, GameState.class).get(); | ||
|
||
gameEnded = gameState.ended; | ||
winner = gameState.winner; | ||
} | ||
|
||
System.out.println("Game over. Final move: " + moves.get(moves.size() - 1) + ", Winner: " + winner); | ||
} | ||
} | ||
} |
17 changes: 17 additions & 0 deletions
17
examples/java/src/main/java/com/xebia/functional/xef/java/auto/Colors.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
package com.xebia.functional.xef.java.auto; | ||
|
||
import java.util.List; | ||
import java.util.concurrent.ExecutionException; | ||
|
||
public class Colors { | ||
|
||
public List<String> colors; | ||
|
||
public static void main(String[] args) throws ExecutionException, InterruptedException { | ||
try (AIScope scope = new AIScope()) { | ||
scope.prompt("a selection of 10 beautiful colors that go well together", Colors.class) | ||
.thenAccept(colors -> System.out.println("Colors:\n" + colors.colors)) | ||
.get(); | ||
} | ||
} | ||
} |
42 changes: 42 additions & 0 deletions
42
examples/java/src/main/java/com/xebia/functional/xef/java/auto/Employee.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
package com.xebia.functional.xef.java.auto; | ||
|
||
import java.util.concurrent.ExecutionException; | ||
|
||
public class Employee { | ||
|
||
public String firstName; | ||
public String lastName; | ||
public Integer age; | ||
public String position; | ||
public Company company; | ||
|
||
private static class Address { | ||
public String street; | ||
public String city; | ||
public String country; | ||
} | ||
|
||
private static class Company { | ||
public String name; | ||
public Address address; | ||
} | ||
|
||
public static String complexPrompt = | ||
"Provide made up information for an Employee that includes their first name, last name, age, position, and their company's name and address (street, city, and country).\n" + | ||
"Use the information provided."; | ||
|
||
public static void main(String[] args) throws ExecutionException, InterruptedException { | ||
try (AIScope scope = new AIScope()) { | ||
scope.prompt(complexPrompt, Employee.class) | ||
.thenAccept(employeeData -> System.out.println( | ||
"Employee Information:\n\n" + | ||
"Name: " + employeeData.firstName + " " + employeeData.lastName + "\n" + | ||
"Age: " + employeeData.age + "\n" + | ||
"Position: " + employeeData.position + "\n" + | ||
"Company: " + employeeData.company.name + "\n" + | ||
"Address: " + employeeData.company.address.street + ", " + employeeData.company.address.city + ", " + employeeData.company.address.country + "." | ||
)) | ||
.get(); | ||
} | ||
} | ||
} |
53 changes: 53 additions & 0 deletions
53
examples/java/src/main/java/com/xebia/functional/xef/java/auto/Fact.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
package com.xebia.functional.xef.java.auto; | ||
|
||
import java.util.concurrent.ExecutionException; | ||
|
||
public class Fact { | ||
|
||
private static class FactClass { | ||
public String topic; | ||
public String content; | ||
|
||
@Override | ||
public String toString() { | ||
return "FactClass{" + | ||
"topic='" + topic + '\'' + | ||
", content='" + content + '\'' + | ||
'}'; | ||
} | ||
} | ||
|
||
private static class Riddle { | ||
public FactClass fact1; | ||
public FactClass fact2; | ||
public String riddle; | ||
|
||
@Override | ||
public String toString() { | ||
return "Riddle{" + | ||
"fact1=" + fact1 + | ||
", fact2=" + fact2 + | ||
", riddle='" + riddle + '\'' + | ||
'}'; | ||
} | ||
} | ||
|
||
|
||
|
||
public static void main(String[] args) throws ExecutionException, InterruptedException { | ||
try (AIScope scope = new AIScope()) { | ||
var fact1 = scope.prompt("A fascinating fact about you", FactClass.class).get(); | ||
var fact2 = scope.prompt("An interesting fact about me", FactClass.class).get(); | ||
|
||
String riddlePrompt = ""+ | ||
"Create a riddle that combines the following facts:\n\n" + | ||
|
||
"Fact 1: " + fact1.content + "\n" + | ||
"Fact 2: " + fact2.content; | ||
|
||
scope.prompt(riddlePrompt, Riddle.class) | ||
.thenAccept(riddle -> System.out.println("Riddle:\n\n" + riddle)).get(); | ||
} | ||
} | ||
|
||
} |
15 changes: 15 additions & 0 deletions
15
examples/java/src/main/java/com/xebia/functional/xef/java/auto/Love.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
package com.xebia.functional.xef.java.auto; | ||
|
||
import java.util.List; | ||
import java.util.concurrent.ExecutionException; | ||
|
||
public class Love { | ||
public List<String> loveList; | ||
public static void main(String[] args) throws ExecutionException, InterruptedException { | ||
try (AIScope scope = new AIScope()) { | ||
scope.prompt("tell me you like me with just emojis", Love.class) | ||
.thenAccept(love -> System.out.println(love.loveList)) | ||
.get(); | ||
} | ||
} | ||
} |
17 changes: 17 additions & 0 deletions
17
examples/java/src/main/java/com/xebia/functional/xef/java/auto/MeaningOfLife.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
package com.xebia.functional.xef.java.auto; | ||
|
||
import java.util.List; | ||
import java.util.concurrent.ExecutionException; | ||
|
||
public class MeaningOfLife { | ||
public List<String> mainTheories; | ||
|
||
public static void main(String[] args) throws ExecutionException, InterruptedException { | ||
try (AIScope scope = new AIScope()) { | ||
scope.prompt("What are the main theories about the meaning of life", MeaningOfLife.class) | ||
.thenAccept(meaningOfLife -> | ||
System.out.println("There are several theories about the meaning of life:\n" + meaningOfLife.mainTheories)) | ||
.get(); | ||
} | ||
} | ||
} |