Skip to content

Commit cf28e67

Browse files
committed
Simplification
1 parent e3b9566 commit cf28e67

4 files changed

Lines changed: 31 additions & 27 deletions

File tree

src/main/java/com/embabel/guide/GuideData.java

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package com.embabel.guide;
22

33
import com.embabel.agent.api.common.LlmReference;
4+
import com.embabel.agent.identity.User;
45
import com.embabel.agent.rag.WritableContentElementRepository;
56
import com.embabel.agent.rag.ingestion.DirectoryParsingResult;
67
import com.embabel.agent.rag.ingestion.HierarchicalContentReader;
@@ -12,6 +13,7 @@
1213
import org.slf4j.Logger;
1314
import org.slf4j.LoggerFactory;
1415
import org.springframework.lang.NonNull;
16+
import org.springframework.lang.Nullable;
1517
import org.springframework.stereotype.Service;
1618
import org.springframework.transaction.PlatformTransactionManager;
1719
import org.springframework.transaction.annotation.Transactional;
@@ -58,12 +60,12 @@ public GuideData(
5860
}
5961

6062
@NonNull
61-
public GuideConfig guideConfig() {
63+
public GuideConfig config() {
6264
return guideConfig;
6365
}
6466

6567
@NonNull
66-
public List<LlmReference> references() {
68+
public List<LlmReference> referencesForUser(@Nullable User user) {
6769
return Collections.unmodifiableList(references);
6870
}
6971

src/main/java/com/embabel/guide/GuideResponderAgent.java

Lines changed: 22 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -13,27 +13,27 @@
1313
import com.embabel.agent.rag.EntitySearch;
1414
import com.embabel.agent.rag.HyDE;
1515
import com.embabel.agent.rag.pipeline.event.RagPipelineEvent;
16+
import com.embabel.agent.rag.tools.DualShotConfig;
1617
import com.embabel.chat.AssistantMessage;
1718
import com.embabel.chat.Chatbot;
1819
import com.embabel.chat.Conversation;
1920
import com.embabel.chat.UserMessage;
2021
import com.embabel.chat.agent.AgentProcessChatbot;
2122
import org.springframework.context.annotation.Bean;
2223
import org.springframework.context.annotation.Configuration;
24+
import org.springframework.lang.NonNull;
2325
import org.springframework.lang.Nullable;
2426

25-
import javax.validation.constraints.Null;
2627
import java.time.Duration;
2728
import java.util.Collections;
2829
import java.util.Set;
2930

30-
record ConversationOver(String why) {
31+
record ConversationOver(@NonNull String why) {
3132
}
3233

33-
// TODO should go into common
3434
record ChatbotReturn(
3535
@Nullable AssistantMessage assistantMessage,
36-
@Null ConversationOver termination
36+
@Nullable ConversationOver termination
3737
) implements SomeOf {
3838
}
3939

@@ -61,22 +61,24 @@ ChatbotReturn respond(
6161
ActionContext context) {
6262
var assistantMessage = context
6363
.ai()
64-
.withLlm(guideData.guideConfig().llm())
65-
.withReferences(guideData.references())
64+
.withLlm(guideData.config().llm())
65+
.withReferences(guideData.referencesForUser(context.user()))
6666
.withTools(CoreToolGroups.WEB)
67-
.withRag(guideData.ragOptions()
68-
.withHyDE(new HyDE(40))
69-
.withContentElementSearch(ContentElementSearch.CHUNKS_ONLY)
70-
.withEntitySearch(new EntitySearch(Set.of(
71-
"Concept", "Example"
72-
), false))
73-
.withDesiredMaxLatency(Duration.ofMinutes(10))
74-
// .withDualShot(new DualShotConfig(100))
75-
.withListener(e -> {
76-
if (e instanceof RagPipelineEvent rpe) {
77-
context.updateProgress(rpe.getDescription());
78-
}
79-
}))
67+
.withRag(
68+
guideData
69+
.ragOptions()
70+
.withHyDE(new HyDE(40))
71+
.withContentElementSearch(ContentElementSearch.CHUNKS_ONLY)
72+
.withEntitySearch(new EntitySearch(Set.of(
73+
"Concept", "Example"
74+
), false))
75+
.withDesiredMaxLatency(Duration.ofMinutes(10))
76+
.withDualShot(new DualShotConfig(100))
77+
.withListener(e -> {
78+
if (e instanceof RagPipelineEvent rpe) {
79+
context.updateProgress(rpe.getDescription());
80+
}
81+
}))
8082
.withTemplate("guide_system")
8183
.respondWithSystemPrompt(conversation,
8284
guideData.templateModel(Collections.singletonMap("user",
@@ -89,7 +91,7 @@ ChatbotReturn respond(
8991

9092
@AchievesGoal(description = "Conversation completed")
9193
@Action
92-
ConversationOver respondAndMaybeTerminate(
94+
ConversationOver respondAndTerminate(
9395
ConversationOver conversationOver,
9496
Conversation conversation,
9597
ActionContext context) {

src/main/java/com/embabel/guide/simple/GuideAgent.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,8 +35,8 @@ public record GuideAgent(
3535
@Action
3636
GuideResponse answerQuestion(GuideRequest guideRequest, OperationContext operationContext) {
3737
return operationContext.ai()
38-
.withLlm(guideData.guideConfig().llm())
39-
.withReferences(guideData.references())
38+
.withLlm(guideData.config().llm())
39+
.withReferences(guideData.referencesForUser(null))
4040
.withRag(guideData.ragOptions())
4141
.withTemplate("guide_system")
4242
.createObject(GuideResponse.class, guideData.templateModel(Collections.singletonMap(

src/main/java/com/embabel/guide/simple/GuideChatSession.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
import java.util.Collections;
1717

1818
/**
19-
* GuideLoader will have loaded content
19+
* Shows how to write a ChatSession without an agent backing it
2020
*/
2121
public class GuideChatSession implements ChatSession {
2222

@@ -66,8 +66,8 @@ public void onUserMessage(@NotNull UserMessage userMessage) {
6666
final var assistantMessage = aiBuilder
6767
.withShowPrompts(false)
6868
.ai()
69-
.withLlm(guideData.guideConfig().llm())
70-
.withReferences(guideData.references())
69+
.withLlm(guideData.config().llm())
70+
.withReferences(guideData.referencesForUser(getUser()))
7171
.withRag(guideData.ragOptions().withListener(e -> {
7272
if (e instanceof RagPipelineEvent rpe) {
7373
var am = new AssistantMessage(rpe.getDescription());

0 commit comments

Comments
 (0)