Skip to content

Commit 86862cd

Browse files
author
Jasper Blues
committed
Replace deprecated method in craftStory with recommendated approach. Update docs with env info.
1 parent 953cdfc commit 86862cd

3 files changed

Lines changed: 24 additions & 15 deletions

File tree

README.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,13 @@ Add your magic here!
2424

2525
# To run
2626

27+
Create at least one of the following in your env pointing to a valid key:
28+
29+
```bash
30+
export OPENAI_API_KEY=YOUR_OPENAI_KEY
31+
export ANTHROPIC_API_KEY=YOUR_ANTHROPIC_API_KEY
32+
```
33+
2734
Run the shell script to start Embabel under Spring Shell:
2835

2936
```bash

src/main/kotlin/com/embabel/template/agent/WriteAndReviewAgent.kt

Lines changed: 5 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -84,22 +84,18 @@ class WriteAndReviewAgent(
8484
) {
8585

8686
@Action
87-
fun craftStory(userInput: UserInput): Story =
88-
using(
89-
LlmOptions(criteria = Auto)
90-
.withTemperature(.9), // Higher temperature for more creative output
91-
).withPromptContributor(StoryTeller)
92-
.create(
93-
"""
87+
fun craftStory(userInput: UserInput, context: OperationContext): Story =
88+
context.promptRunner().withLlm(LlmOptions(criteria = Auto, temperature = 0.9))
89+
.withPromptContributor(StoryTeller)
90+
.create<Story>("""
9491
Craft a short story in $storyWordCount words or less.
9592
The story should be engaging and imaginative.
9693
Use the user's input as inspiration if possible.
9794
If the user has provided a name, include it in the story.
9895
9996
# User input
10097
${userInput.content}
101-
""".trimIndent()
102-
)
98+
""".trimIndent())
10399

104100
@AchievesGoal(
105101
description = "The user has been greeted",

src/test/kotlin/com/embabel/template/agent/WriteAndReviewAgentTest.kt

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ package com.embabel.template.agent
22

33
import com.embabel.agent.domain.io.UserInput
44
import com.embabel.agent.testing.unit.FakeOperationContext
5+
import com.embabel.agent.testing.unit.FakePromptRunner
56
import com.embabel.agent.testing.unit.LlmInvocation
67
import com.embabel.agent.testing.unit.UnitTestUtils.captureLlmCall
78
import org.junit.jupiter.api.Assertions
@@ -22,22 +23,27 @@ internal class WriteAndReviewAgentTest {
2223
fun testCraftStory() {
2324
// Create agent with word limits: 200 min, 400 max
2425
val agent = WriteAndReviewAgent(200, 400)
26+
val context = FakeOperationContext.create()
27+
val promptRunner = context.promptRunner() as FakePromptRunner
28+
29+
context.expectResponse(Story("One upon a time Sir Galahad . . "))
2530

26-
// Capture the LLM call made during story crafting
27-
val llmCall = captureLlmCall(Runnable {
28-
agent.craftStory(UserInput("Tell me a story about a brave knight", Instant.now()))
29-
})
31+
agent.craftStory(
32+
UserInput("Tell me a story about a brave knight", Instant.now()),
33+
context
34+
)
3035

3136
// Verify the prompt contains the expected keyword
3237
Assertions.assertTrue(
33-
llmCall.prompt.contains("knight"),
38+
promptRunner.llmInvocations.first().prompt.contains("knight"),
3439
"Expected prompt to contain 'knight'"
3540
)
3641

3742

3843
// Verify the temperature setting for creative output
44+
val actual = promptRunner.llmInvocations.first().interaction.llm.temperature
3945
Assertions.assertEquals(
40-
0.9, llmCall.llm!!.temperature, 0.01,
46+
0.9, actual, 0.01,
4147
"Expected temperature to be 0.9: Higher for more creative output"
4248
)
4349
}

0 commit comments

Comments
 (0)