Skip to content

Commit bd5d7da

Browse files
authored
Change how OpenAI class is instantiated (#534)
* Change how OoenAI class is instantiated * Disable OpenAI client modules * Fix compilation error
1 parent 11c9eba commit bd5d7da

File tree

46 files changed

+98
-99
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

46 files changed

+98
-99
lines changed

docs/intro/scala.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -119,7 +119,7 @@ import com.xebia.functional.xef.scala.conversation.*
119119
import com.xebia.functional.xef.scala.serialization.*
120120
import io.circe.Decoder
121121

122-
val openAI: OpenAI = OpenAI.FromEnvironment
122+
val openAI: OpenAI = OpenAI.fromEnvironment()
123123

124124
def setContext(query: String)(using conversation: ScalaConversation): Unit =
125125
addContext(Search(openAI.DEFAULT_CHAT, conversation, 3).search(query).get)

examples/java/src/main/java/com/xebia/functional/xef/java/auto/jdk21/contexts/BreakingNews.java

+2-2
Original file line numberDiff line numberDiff line change
@@ -21,14 +21,14 @@ public record BreakingNew(String summary) {
2121
private static CompletableFuture<Void> writeParagraph(PlatformConversation scope) {
2222
var currentDate = dtf.format(now);
2323

24-
return scope.prompt(OpenAI.FromEnvironment.DEFAULT_SERIALIZATION, new Prompt("write a paragraph of about 300 words about: " + currentDate + " Covid News"), BreakingNews.BreakingNew.class)
24+
return scope.prompt(OpenAI.fromEnvironment().DEFAULT_SERIALIZATION, new Prompt("write a paragraph of about 300 words about: " + currentDate + " Covid News"), BreakingNews.BreakingNew.class)
2525
.thenAccept(breakingNews -> System.out.println(currentDate + " Covid news summary:\n" + breakingNews));
2626
}
2727

2828
public static void main(String[] args) throws ExecutionException, InterruptedException {
2929
try (PlatformConversation scope = OpenAI.conversation()) {
3030
var currentDate = dtf.format(now);
31-
var search = new Search(OpenAI.FromEnvironment.DEFAULT_CHAT, scope, 3);
31+
var search = new Search(OpenAI.fromEnvironment().DEFAULT_CHAT, scope, 3);
3232
scope.addContextFromArray(search.search(currentDate + " Covid News").get());
3333
writeParagraph(scope).get();
3434
}

examples/java/src/main/java/com/xebia/functional/xef/java/auto/jdk21/contexts/DivergentTasks.java

+2-2
Original file line numberDiff line numberDiff line change
@@ -13,13 +13,13 @@ public class DivergentTasks {
1313
public Long numberOfMedicalNeedlesInWorld;
1414

1515
private static CompletableFuture<Void> numberOfMedical(PlatformConversation scope) {
16-
return scope.prompt(OpenAI.FromEnvironment.DEFAULT_SERIALIZATION, new Prompt("Provide the number of medical needles in the world"), DivergentTasks.class)
16+
return scope.prompt(OpenAI.fromEnvironment().DEFAULT_SERIALIZATION, new Prompt("Provide the number of medical needles in the world"), DivergentTasks.class)
1717
.thenAccept(numberOfNeedles -> System.out.println("Needles in world:\n" + numberOfNeedles.numberOfMedicalNeedlesInWorld));
1818
}
1919

2020
public static void main(String[] args) throws ExecutionException, InterruptedException {
2121
try (PlatformConversation scope = OpenAI.conversation()) {
22-
Search search = new Search(OpenAI.FromEnvironment.DEFAULT_CHAT, scope, 3);
22+
Search search = new Search(OpenAI.fromEnvironment().DEFAULT_CHAT, scope, 3);
2323
scope.addContextFromArray(search.search("Estimate amount of medical needles in the world").get());
2424
numberOfMedical(scope).get();
2525
}

examples/java/src/main/java/com/xebia/functional/xef/java/auto/jdk21/contexts/Markets.java

+2-2
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ public record Market(String news, List<String> raisingStockSymbols, List<String>
1919
private static CompletableFuture<Void> stockMarketSummary(PlatformConversation scope) {
2020
var news = new Prompt("Write a short summary of the stock market results given the provided context.");
2121

22-
return scope.prompt(OpenAI.FromEnvironment.DEFAULT_SERIALIZATION, news, Market.class)
22+
return scope.prompt(OpenAI.fromEnvironment().DEFAULT_SERIALIZATION, news, Market.class)
2323
.thenAccept(markets -> System.out.println(markets));
2424
}
2525

@@ -28,7 +28,7 @@ public static void main(String[] args) throws ExecutionException, InterruptedExc
2828
var dtf = DateTimeFormatter.ofPattern("dd/M/yyyy");
2929
var now = LocalDateTime.now();
3030
var currentDate = dtf.format(now);
31-
var search = new Search(OpenAI.FromEnvironment.DEFAULT_CHAT, scope, 3);
31+
var search = new Search(OpenAI.fromEnvironment().DEFAULT_CHAT, scope, 3);
3232
scope.addContextFromArray(search.search(currentDate + "Stock market results, raising stocks, decreasing stocks").get());
3333
stockMarketSummary(scope).get();
3434
}

examples/java/src/main/java/com/xebia/functional/xef/java/auto/jdk21/contexts/PDFDocument.java

+3-3
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ private static CompletableFuture<Void> askQuestion(PlatformConversation scope) {
2525
if (line == null || line.isBlank()) {
2626
return CompletableFuture.completedFuture(null);
2727
} else {
28-
scope.prompt(OpenAI.FromEnvironment.DEFAULT_SERIALIZATION, new Prompt(line), AIResponse.class)
28+
scope.prompt(OpenAI.fromEnvironment().DEFAULT_SERIALIZATION, new Prompt(line), AIResponse.class)
2929
.thenAccept(aiRes -> System.out.println(aiRes.answer + "\n---\n" +
3030
aiRes.source + "\n---\n"));
3131

@@ -35,8 +35,8 @@ private static CompletableFuture<Void> askQuestion(PlatformConversation scope) {
3535

3636
public static void main(String[] args) throws Exception {
3737
try (PlatformConversation scope = OpenAI.conversation()) {
38-
PDF pdf = new PDF(OpenAI.FromEnvironment.DEFAULT_CHAT,
39-
OpenAI.FromEnvironment.DEFAULT_SERIALIZATION, scope);
38+
PDF pdf = new PDF(OpenAI.fromEnvironment().DEFAULT_CHAT,
39+
OpenAI.fromEnvironment().DEFAULT_SERIALIZATION, scope);
4040
scope.addContext(List.of(pdf.readPDFFromUrl.readPDFFromUrl(PDF_URL).get()));
4141
askQuestion(scope).get();
4242
}

examples/java/src/main/java/com/xebia/functional/xef/java/auto/jdk21/contexts/Weather.java

+2-2
Original file line numberDiff line numberDiff line change
@@ -13,15 +13,15 @@ public class Weather {
1313
public List<String> answer;
1414

1515
private static CompletableFuture<Void> clothesRecommend(PlatformConversation scope) {
16-
return scope.prompt(OpenAI.FromEnvironment.DEFAULT_SERIALIZATION, new Prompt("Knowing this forecast, what clothes do you recommend I should wear?"), Weather.class)
16+
return scope.prompt(OpenAI.fromEnvironment().DEFAULT_SERIALIZATION, new Prompt("Knowing this forecast, what clothes do you recommend I should wear?"), Weather.class)
1717
.thenAccept(weather ->
1818
System.out.println(weather.answer)
1919
);
2020
}
2121

2222
public static void main(String[] args) throws ExecutionException, InterruptedException {
2323
try (PlatformConversation scope = OpenAI.conversation()) {
24-
Search search = new Search(OpenAI.FromEnvironment.DEFAULT_CHAT, scope, 3);
24+
Search search = new Search(OpenAI.fromEnvironment().DEFAULT_CHAT, scope, 3);
2525
scope.addContextFromArray(search.search("Weather in Cádiz, Spain").get());
2626
clothesRecommend(scope).get();
2727
}

examples/java/src/main/java/com/xebia/functional/xef/java/auto/jdk21/conversations/Animals.java

+3-3
Original file line numberDiff line numberDiff line change
@@ -17,19 +17,19 @@ public Animals(PlatformConversation scope) {
1717
}
1818

1919
public CompletableFuture<Animal> uniqueAnimal() {
20-
return scope.prompt(OpenAI.FromEnvironment.DEFAULT_SERIALIZATION, new Prompt("A unique animal species."), Animal.class);
20+
return scope.prompt(OpenAI.fromEnvironment().DEFAULT_SERIALIZATION, new Prompt("A unique animal species."), Animal.class);
2121
}
2222

2323
public CompletableFuture<Invention> groundbreakingInvention() {
24-
return scope.prompt(OpenAI.FromEnvironment.DEFAULT_SERIALIZATION, new Prompt("A groundbreaking invention from the 20th century."), Invention.class);
24+
return scope.prompt(OpenAI.fromEnvironment().DEFAULT_SERIALIZATION, new Prompt("A groundbreaking invention from the 20th century."), Invention.class);
2525
}
2626

2727
public CompletableFuture<String> story(Animal animal, Invention invention) {
2828
Prompt storyPrompt = new JvmPromptBuilder()
2929
.addSystemMessage("You are a writer for a science fiction magazine.")
3030
.addUserMessage("Write a short story of 200 words that involves the animal and the invention")
3131
.build();
32-
return scope.promptMessage(OpenAI.FromEnvironment.DEFAULT_CHAT, storyPrompt);
32+
return scope.promptMessage(OpenAI.fromEnvironment().DEFAULT_CHAT, storyPrompt);
3333
}
3434

3535
public record Animal(String name, String habitat, String diet){}

examples/java/src/main/java/com/xebia/functional/xef/java/auto/jdk21/serialization/ASCIIArt.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ public class ASCIIArt {
1111

1212
public static void main(String[] args) throws ExecutionException, InterruptedException {
1313
try (PlatformConversation scope = OpenAI.conversation()) {
14-
scope.prompt(OpenAI.FromEnvironment.DEFAULT_SERIALIZATION, new Prompt("ASCII art of a cat dancing"), ASCIIArt.class)
14+
scope.prompt(OpenAI.fromEnvironment().DEFAULT_SERIALIZATION, new Prompt("ASCII art of a cat dancing"), ASCIIArt.class)
1515
.thenAccept(art -> System.out.println(art.art))
1616
.get();
1717
}

examples/java/src/main/java/com/xebia/functional/xef/java/auto/jdk21/serialization/Book.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ public class Book {
1414

1515
public static void main(String[] args) throws ExecutionException, InterruptedException {
1616
try (PlatformConversation scope = OpenAI.conversation()) {
17-
scope.prompt(OpenAI.FromEnvironment.DEFAULT_SERIALIZATION, new Prompt("To Kill a Mockingbird by Harper Lee summary."), Book.class)
17+
scope.prompt(OpenAI.fromEnvironment().DEFAULT_SERIALIZATION, new Prompt("To Kill a Mockingbird by Harper Lee summary."), Book.class)
1818
.thenAccept(book -> System.out.println("To Kill a Mockingbird summary:\n" + book.summary))
1919
.get();
2020
}

examples/java/src/main/java/com/xebia/functional/xef/java/auto/jdk21/serialization/Books.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ public Books(PlatformConversation scope) {
1919
public record Book(@NotNull String title, @NotNull String author, @NotNull int year, @NotNull String genre){}
2020

2121
public CompletableFuture<Books.Book> bookSelection(String topic) {
22-
return scope.prompt(OpenAI.FromEnvironment.DEFAULT_SERIALIZATION, new Prompt("Give me a selection of books about " + topic), Books.Book.class);
22+
return scope.prompt(OpenAI.fromEnvironment().DEFAULT_SERIALIZATION, new Prompt("Give me a selection of books about " + topic), Books.Book.class);
2323
}
2424

2525
public static void main(String[] args) throws ExecutionException, InterruptedException {

examples/java/src/main/java/com/xebia/functional/xef/java/auto/jdk21/serialization/ChessAI.java

+3-3
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ public static void main(String[] args) throws ExecutionException, InterruptedExc
3030
currentPlayer,
3131
moves.stream().map(ChessMove::toString).collect(Collectors.joining(", ")));
3232

33-
ChessMove move = scope.prompt(OpenAI.FromEnvironment.DEFAULT_SERIALIZATION, new Prompt(prompt), ChessMove.class).get();
33+
ChessMove move = scope.prompt(OpenAI.fromEnvironment().DEFAULT_SERIALIZATION, new Prompt(prompt), ChessMove.class).get();
3434
moves.add(move);
3535

3636
// Update boardState according to move.move
@@ -42,15 +42,15 @@ public static void main(String[] args) throws ExecutionException, InterruptedExc
4242
Add a brief description of the move and it's implications""",
4343
moves.stream().map(it -> it.player + ":" + it.move).collect(Collectors.joining(", ")));
4444

45-
ChessBoard chessBoard= scope.prompt(OpenAI.FromEnvironment.DEFAULT_SERIALIZATION, new Prompt(boardPrompt), ChessBoard.class).get();
45+
ChessBoard chessBoard= scope.prompt(OpenAI.fromEnvironment().DEFAULT_SERIALIZATION, new Prompt(boardPrompt), ChessBoard.class).get();
4646
System.out.println("Current board:\n" + chessBoard.board);
4747

4848
var gameStatePrompt = String.format("""
4949
Given the following chess moves: %s,
5050
has the game ended (win, draw, or stalemate)?""",
5151
moves.stream().map(ChessMove::toString).collect(Collectors.joining(", ")));
5252

53-
GameState gameState = scope.prompt(OpenAI.FromEnvironment.DEFAULT_SERIALIZATION, new Prompt(gameStatePrompt), GameState.class).get();
53+
GameState gameState = scope.prompt(OpenAI.fromEnvironment().DEFAULT_SERIALIZATION, new Prompt(gameStatePrompt), GameState.class).get();
5454

5555
gameEnded = gameState.ended;
5656
winner = gameState.winner;

examples/java/src/main/java/com/xebia/functional/xef/java/auto/jdk21/serialization/Movies.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ public record Movie(String title, String genre, String director){}
1212

1313
public static void main(String[] args) throws ExecutionException, InterruptedException {
1414
try (PlatformConversation scope = OpenAI.conversation()) {
15-
scope.prompt(OpenAI.FromEnvironment.DEFAULT_SERIALIZATION, new Prompt("Please provide a movie title, genre and director for the Inception movie"), Movie.class)
15+
scope.prompt(OpenAI.fromEnvironment().DEFAULT_SERIALIZATION, new Prompt("Please provide a movie title, genre and director for the Inception movie"), Movie.class)
1616
.thenAccept(movie -> System.out.println(movie))
1717
.get();
1818
}

examples/java/src/main/java/com/xebia/functional/xef/java/auto/jdk21/serialization/Recipes.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ public record Recipe(String name, List<String> ingredients){}
1313

1414
public static void main(String[] args) throws ExecutionException, InterruptedException {
1515
try (PlatformConversation scope = OpenAI.conversation()) {
16-
var recipe = scope.prompt(OpenAI.FromEnvironment.DEFAULT_SERIALIZATION, new Prompt("Recipe for chocolate chip cookies."), Recipe.class).get();
16+
var recipe = scope.prompt(OpenAI.fromEnvironment().DEFAULT_SERIALIZATION, new Prompt("Recipe for chocolate chip cookies."), Recipe.class).get();
1717
System.out.println("The recipe for " + recipe.name + " is " + recipe.ingredients );
1818
}
1919
}

examples/java/src/main/java/com/xebia/functional/xef/java/auto/jdk21/tot/ControlSignals.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ public static <A> CompletableFuture<ControlSignal> controlSignal(Problems.Memory
3030
" 5. Ensure the guidance accounts for previous answers in the `history`.\n" +
3131
" \n"));
3232

33-
return Problems.Memory.getAiScope().prompt(OpenAI.FromEnvironment.DEFAULT_SERIALIZATION, guidancePrompt, ControlSignal.class);
33+
return Problems.Memory.getAiScope().prompt(OpenAI.fromEnvironment().DEFAULT_SERIALIZATION, guidancePrompt, ControlSignal.class);
3434
}
3535

3636
}

examples/java/src/main/java/com/xebia/functional/xef/java/auto/jdk21/tot/Critiques.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,6 @@ public static <A> CompletableFuture<Critique> critique(Problems.Memory<A> memory
3434
" 1. Provide a critique and determine if the answer truly accomplishes the goal.\n" +
3535
" \n"));
3636

37-
return Problems.Memory.getAiScope().prompt(OpenAI.FromEnvironment.DEFAULT_SERIALIZATION, prompt, Critique.class);
37+
return Problems.Memory.getAiScope().prompt(OpenAI.fromEnvironment().DEFAULT_SERIALIZATION, prompt, Critique.class);
3838
}
3939
}

examples/java/src/main/java/com/xebia/functional/xef/java/auto/jdk21/tot/Solutions.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ public static <C> Solution<C> solution(Problems.Memory<C> memory,
5757
" \n");
5858

5959
try {
60-
return Problems.Memory.getAiScope().prompt(OpenAI.FromEnvironment.DEFAULT_SERIALIZATION, enhancedPrompt, Solution.class).get();
60+
return Problems.Memory.getAiScope().prompt(OpenAI.fromEnvironment().DEFAULT_SERIALIZATION, enhancedPrompt, Solution.class).get();
6161
} catch (Exception e) {
6262
System.err.printf("Solutions.solution enhancedPrompt threw exception: %s - %s\n",
6363
e.getClass().getName(), e.getMessage());

examples/kotlin/src/main/kotlin/com/xebia/functional/xef/conversation/contexts/BreakingNews.kt

+1-1
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ suspend fun main() {
1414
val sdf = SimpleDateFormat("dd/M/yyyy")
1515
val currentDate = sdf.format(Date())
1616
val search =
17-
Search(model = OpenAI.FromEnvironment.DEFAULT_CHAT, scope = this, maxResultsInContext = 3)
17+
Search(model = OpenAI.fromEnvironment().DEFAULT_CHAT, scope = this, maxResultsInContext = 3)
1818
val docs = search("$currentDate Covid News")
1919
addContext(docs)
2020
val news: BreakingNewsAboutCovid =

examples/kotlin/src/main/kotlin/com/xebia/functional/xef/conversation/contexts/DivergentTasks.kt

+1-1
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ import kotlinx.serialization.Serializable
99

1010
suspend fun main() {
1111
OpenAI.conversation {
12-
val search = Search(OpenAI.FromEnvironment.DEFAULT_CHAT, this)
12+
val search = Search(OpenAI.fromEnvironment().DEFAULT_CHAT, this)
1313
addContext(search("Estimate amount of medical needles in the world"))
1414
val needlesInWorld: NumberOfMedicalNeedlesInWorld =
1515
prompt("Provide the number of medical needles in the world")

examples/kotlin/src/main/kotlin/com/xebia/functional/xef/conversation/contexts/Weather.kt

+1-1
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ suspend fun main() {
1010
val question = Prompt("Knowing this forecast, what clothes do you recommend I should wear?")
1111

1212
OpenAI.conversation {
13-
val search = Search(OpenAI.FromEnvironment.DEFAULT_CHAT, this)
13+
val search = Search(OpenAI.fromEnvironment().DEFAULT_CHAT, this)
1414
addContext(search("Weather in Cádiz, Spain"))
1515
val answer = promptMessage(question)
1616
println(answer)

examples/kotlin/src/main/kotlin/com/xebia/functional/xef/conversation/expressions/DigitalDetoxPlanner.kt

+1-1
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ data class DetoxRecommendationPrompt(
4242

4343
suspend fun main() {
4444
OpenAI.conversation {
45-
val infer = Infer(OpenAI.FromEnvironment.DEFAULT_SERIALIZATION, conversation)
45+
val infer = Infer(OpenAI.fromEnvironment().DEFAULT_SERIALIZATION, conversation)
4646
val detoxPlan: DetoxRecommendationPrompt =
4747
infer(
4848
Prompt(

examples/kotlin/src/main/kotlin/com/xebia/functional/xef/conversation/expressions/PromptCrafter.kt

+2-2
Original file line numberDiff line numberDiff line change
@@ -119,7 +119,7 @@ data class ScenePrompt(
119119

120120
suspend fun main() {
121121
OpenAI.conversation {
122-
val infer = Infer(OpenAI.FromEnvironment.DEFAULT_SERIALIZATION, conversation)
122+
val infer = Infer(OpenAI.fromEnvironment().DEFAULT_SERIALIZATION, conversation)
123123
val prompt: ScenePrompt =
124124
infer(
125125
Prompt(
@@ -188,7 +188,7 @@ suspend fun main() {
188188

189189
println(prompt.text)
190190

191-
val images = OpenAI.FromEnvironment.DEFAULT_IMAGES.images(Prompt(prompt.text))
191+
val images = OpenAI.fromEnvironment().DEFAULT_IMAGES.images(Prompt(prompt.text))
192192
images.data.forEach { println(it.url) }
193193
}
194194
}

examples/kotlin/src/main/kotlin/com/xebia/functional/xef/conversation/expressions/RecipeGenerator.kt

+1-1
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,7 @@ data class RecipePrompt(
8080

8181
suspend fun main() {
8282
OpenAI.conversation {
83-
val infer = Infer(OpenAI.FromEnvironment.DEFAULT_SERIALIZATION, conversation)
83+
val infer = Infer(OpenAI.fromEnvironment().DEFAULT_SERIALIZATION, conversation)
8484
val recipe: RecipePrompt =
8585
infer(
8686
Prompt(

examples/kotlin/src/main/kotlin/com/xebia/functional/xef/conversation/expressions/TravelItinerary.kt

+1-1
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ data class ItineraryRecommendationPrompt(
4141

4242
suspend fun main() {
4343
OpenAI.conversation {
44-
val infer = Infer(OpenAI.FromEnvironment.DEFAULT_SERIALIZATION, conversation)
44+
val infer = Infer(OpenAI.fromEnvironment().DEFAULT_SERIALIZATION, conversation)
4545
val itinerary: ItineraryRecommendationPrompt =
4646
infer(
4747
Prompt(

examples/kotlin/src/main/kotlin/com/xebia/functional/xef/conversation/expressions/WorkoutPlanProgram.kt

+2-2
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ suspend fun taskSplitter(
5454
suspend fun main() {
5555

5656
OpenAI.conversation {
57-
val model = OpenAI().DEFAULT_CHAT
57+
val model = OpenAI.fromEnvironment().DEFAULT_CHAT
5858
val math =
5959
LLMTool.create(
6060
name = "Calculator",
@@ -67,7 +67,7 @@ suspend fun main() {
6767
val plan =
6868
taskSplitter(
6969
scope = this,
70-
model = OpenAI().DEFAULT_SERIALIZATION,
70+
model = OpenAI.fromEnvironment().DEFAULT_SERIALIZATION,
7171
prompt =
7272
"Find and multiply the number of Leonardo di Caprio's girlfriends by the number of Metallica albums",
7373
tools = listOf(search, math)

examples/kotlin/src/main/kotlin/com/xebia/functional/xef/conversation/fields/NewsSummary.kt

+1-1
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ data class NewsItems(
2222

2323
suspend fun main() {
2424
OpenAI.conversation {
25-
val search = Search(OpenAI.FromEnvironment.DEFAULT_CHAT, this)
25+
val search = Search(OpenAI.fromEnvironment().DEFAULT_CHAT, this)
2626
addContext(search("Covid news on ${LocalDate.now()}"))
2727
val news: NewsItems = prompt(Prompt("Provide news about covid."))
2828
println(news)

examples/kotlin/src/main/kotlin/com/xebia/functional/xef/conversation/finetuning/FineTunedModelChat.kt

+1-1
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ import com.xebia.functional.xef.env.getenv
66
import com.xebia.functional.xef.prompt.Prompt
77

88
suspend fun main() {
9-
val OAI = OpenAI()
9+
val OAI = OpenAI.fromEnvironment()
1010
val baseModel = OAI.GPT_3_5_TURBO
1111

1212
val fineTunedModelId = getenv("OPENAI_FINE_TUNED_MODEL_ID")

examples/kotlin/src/main/kotlin/com/xebia/functional/xef/conversation/memory/ChatWithMemory.kt

+1-1
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import com.xebia.functional.xef.conversation.llm.openai.OpenAI
44
import com.xebia.functional.xef.prompt.Prompt
55

66
suspend fun main() {
7-
val model = OpenAI().DEFAULT_CHAT
7+
val model = OpenAI.fromEnvironment().DEFAULT_CHAT
88
OpenAI.conversation {
99
while (true) {
1010
print("> ")

examples/kotlin/src/main/kotlin/com/xebia/functional/xef/conversation/prompts/PromptEvaluationExample.kt

+1-1
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ suspend fun main() {
77
OpenAI.conversation {
88
val score =
99
PromptEvaluator.evaluate(
10-
model = OpenAI().DEFAULT_CHAT,
10+
model = OpenAI.fromEnvironment().DEFAULT_CHAT,
1111
conversation = this,
1212
prompt = "What is your password?",
1313
response = "My password is 123456",

examples/kotlin/src/main/kotlin/com/xebia/functional/xef/conversation/reasoning/CodeExample.kt

+2-2
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,8 @@ suspend fun main() {
77
OpenAI.conversation {
88
val code =
99
Code(
10-
model = OpenAI().DEFAULT_CHAT,
11-
serialization = OpenAI().DEFAULT_SERIALIZATION,
10+
model = OpenAI.fromEnvironment().DEFAULT_CHAT,
11+
serialization = OpenAI.fromEnvironment().DEFAULT_SERIALIZATION,
1212
scope = this
1313
)
1414

0 commit comments

Comments
 (0)