feat: Update responseHandler method to accept AgentContext
This commit is contained in:
@@ -555,7 +555,7 @@ public class BlogPostAgent implements BaseAgent {
|
|||||||
|
|
||||||
// OPTIONAL: How to parse/store the response (default: TextAgentResponseHandler("response"))
|
// OPTIONAL: How to parse/store the response (default: TextAgentResponseHandler("response"))
|
||||||
@Override
|
@Override
|
||||||
public AgentResponseHandler responseHandler() {
|
public AgentResponseHandler responseHandler(final AgentContext ctx) {
|
||||||
return new TextAgentResponseHandler("blogPost");
|
return new TextAgentResponseHandler("blogPost");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
2
pom.xml
2
pom.xml
@@ -4,7 +4,7 @@
|
|||||||
<artifactId>lm-lib</artifactId>
|
<artifactId>lm-lib</artifactId>
|
||||||
<groupId>de.extio</groupId>
|
<groupId>de.extio</groupId>
|
||||||
<name>lm-lib</name>
|
<name>lm-lib</name>
|
||||||
<version>1.9.0</version>
|
<version>1.9.2</version>
|
||||||
|
|
||||||
<properties>
|
<properties>
|
||||||
<java.version>21</java.version>
|
<java.version>21</java.version>
|
||||||
|
|||||||
@@ -54,6 +54,14 @@ public record Agent(String name,
|
|||||||
return BaseAgent.super.modelProfile(context);
|
return BaseAgent.super.modelProfile(context);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public AgentResponseHandler responseHandler(final AgentContext context) {
|
||||||
|
if (responseHandler != null) {
|
||||||
|
return responseHandler;
|
||||||
|
}
|
||||||
|
return BaseAgent.super.responseHandler(context);
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void preProcess(final AgentContext context) {
|
public void preProcess(final AgentContext context) {
|
||||||
if (preProcessor != null) {
|
if (preProcessor != null) {
|
||||||
|
|||||||
@@ -56,7 +56,7 @@ public interface BaseAgent {
|
|||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
default AgentResponseHandler responseHandler() {
|
default AgentResponseHandler responseHandler(final AgentContext context) {
|
||||||
return new TextAgentResponseHandler("response");
|
return new TextAgentResponseHandler("response");
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -109,10 +109,10 @@ public interface BaseAgent {
|
|||||||
for (int i = 0; i < 2; i++) {
|
for (int i = 0; i < 2; i++) {
|
||||||
LOGGER.debug("Conversation: {}", conversation);
|
LOGGER.debug("Conversation: {}", conversation);
|
||||||
|
|
||||||
final var responseHandler = this.responseHandler();
|
|
||||||
final var modelProfile = this.modelProfile(split.context());
|
final var modelProfile = this.modelProfile(split.context());
|
||||||
|
final var responseHandler = this.responseHandler(split.context());
|
||||||
|
long requestStart = 0;
|
||||||
Completion completion = null;
|
Completion completion = null;
|
||||||
final var requestStart = System.currentTimeMillis();
|
|
||||||
if (split.context().isStreaming()) {
|
if (split.context().isStreaming()) {
|
||||||
if (responseHandler instanceof final StreamedAgentResponseHandler streamedResponseHandler) {
|
if (responseHandler instanceof final StreamedAgentResponseHandler streamedResponseHandler) {
|
||||||
streamedResponseHandler.beforeStream(split.context());
|
streamedResponseHandler.beforeStream(split.context());
|
||||||
@@ -125,17 +125,21 @@ public interface BaseAgent {
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
if (modelProfile != null) {
|
if (modelProfile != null) {
|
||||||
|
requestStart = System.currentTimeMillis();
|
||||||
completion = client.streamConversation(modelProfile, conversation, chunkConsumer);
|
completion = client.streamConversation(modelProfile, conversation, chunkConsumer);
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
|
requestStart = System.currentTimeMillis();
|
||||||
completion = client.streamConversation(this.modelCategory(split.context()), conversation, chunkConsumer);
|
completion = client.streamConversation(this.modelCategory(split.context()), conversation, chunkConsumer);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
if (modelProfile != null) {
|
if (modelProfile != null) {
|
||||||
|
requestStart = System.currentTimeMillis();
|
||||||
completion = client.conversation(modelProfile, conversation);
|
completion = client.conversation(modelProfile, conversation);
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
|
requestStart = System.currentTimeMillis();
|
||||||
completion = client.conversation(this.modelCategory(split.context()), conversation);
|
completion = client.conversation(this.modelCategory(split.context()), conversation);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user