Skip to content

Commit dea9570

Browse files
committed
Use LLM choice methods
1 parent 32eb37b commit dea9570

File tree

2 files changed

+28
-19
lines changed

2 files changed

+28
-19
lines changed

examples-java/src/main/java/com/embabel/example/horoscope/StarNewsFinder.java

Lines changed: 25 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -17,14 +17,14 @@
1717

1818
import com.embabel.agent.api.annotation.*;
1919
import com.embabel.agent.api.common.OperationContext;
20+
import com.embabel.agent.config.models.AnthropicModels;
2021
import com.embabel.agent.config.models.OpenAiModels;
2122
import com.embabel.agent.core.CoreToolGroups;
2223
import com.embabel.agent.domain.io.UserInput;
2324
import com.embabel.agent.domain.library.Person;
2425
import com.embabel.agent.domain.library.PersonImpl;
2526
import com.embabel.agent.domain.library.RelevantNewsStories;
2627
import com.embabel.common.ai.model.LlmOptions;
27-
import com.embabel.common.ai.model.ModelSelectionCriteria;
2828
import org.springframework.beans.factory.annotation.Value;
2929

3030
import java.util.stream.Collectors;
@@ -51,12 +51,14 @@ public StarNewsFinder(
5151

5252
@Action
5353
public Person extractPerson(UserInput userInput, OperationContext context) {
54-
return context.ai().withLlm(OpenAiModels.GPT_41).createObjectIfPossible(
55-
"""
56-
Create a person from this user input, extracting their name:
57-
%s""".formatted(userInput.getContent()),
58-
PersonImpl.class
59-
);
54+
return context.ai()
55+
.withLlm(OpenAiModels.GPT_41)
56+
.createObjectIfPossible(
57+
"""
58+
Create a person from this user input, extracting their name:
59+
%s""".formatted(userInput.getContent()),
60+
PersonImpl.class
61+
);
6062
}
6163

6264
@Action(cost = 100.0) // Make it costly so it won't be used in a plan unless there's no other path
@@ -75,12 +77,14 @@ public StarPerson assembleStarPerson(Person person, Starry starry) {
7577

7678
@Action
7779
public StarPerson extractStarPerson(UserInput userInput, OperationContext context) {
78-
return context.ai().withLlm(OpenAiModels.GPT_41).createObjectIfPossible(
79-
"""
80-
Create a person from this user input, extracting their name and star sign:
81-
%s""".formatted(userInput.getContent()),
82-
StarPerson.class
83-
);
80+
return context.ai()
81+
.withLlmByRole("best")
82+
.createObjectIfPossible(
83+
"""
84+
Create a person from this user input, extracting their name and star sign:
85+
%s""".formatted(userInput.getContent()),
86+
StarPerson.class
87+
);
8488
}
8589

8690
@Action
@@ -109,7 +113,9 @@ public RelevantNewsStories findNewsStories(StarPerson person, Horoscope horoscop
109113
find news stories about training courses.""".formatted(
110114
person.name(), person.sign(), horoscope.summary(), storyCount);
111115

112-
return context.ai().withDefaultLlm().createObject(prompt, RelevantNewsStories.class);
116+
return context.ai()
117+
.withDefaultLlm().
118+
createObject(prompt, RelevantNewsStories.class);
113119
}
114120

115121
// The @AchievesGoal annotation indicates that completing this action
@@ -127,10 +133,6 @@ public Writeup writeup(
127133
RelevantNewsStories relevantNewsStories,
128134
Horoscope horoscope,
129135
OperationContext context) {
130-
var llm = LlmOptions.fromCriteria(
131-
ModelSelectionCriteria.firstOf(OpenAiModels.GPT_41_MINI)
132-
).withTemperature(0.9);
133-
134136
var newsItems = relevantNewsStories.getItems().stream()
135137
.map(item -> "- " + item.getUrl() + ": " + item.getSummary())
136138
.collect(Collectors.joining("\n"));
@@ -150,6 +152,10 @@ public Writeup writeup(
150152
151153
Format it as Markdown with links.""".formatted(
152154
person.name(), person.sign(), horoscope.summary(), newsItems);
153-
return context.ai().withLlm(llm).createObject(prompt, Writeup.class);
155+
return context.ai()
156+
.withLlm(LlmOptions
157+
.withFirstAvailableLlmOf(AnthropicModels.CLAUDE_37_SONNET, OpenAiModels.GPT_41_MINI)
158+
.withTemperature(0.9))
159+
.createObject(prompt, Writeup.class);
154160
}
155161
}

examples-java/src/main/resources/application.properties

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,9 @@ spring.application.name=embabel-examples
33
embabel.models.default-llm=gpt-4.1-mini
44
embabel.models.llms.cheapest=gpt-4.1-nano
55

6+
embabel.models.llms.best=gpt-5
7+
8+
69
embabel.shell.chat.confirm-goals=false
710
embabel.shell.chat.multi-goal=false
811
embabel.shell.chat.bind-conversation=false

0 commit comments

Comments
 (0)