|
21 | 21 | import com.alibaba.loongsuite.otel.util.genai.types.InputMessage; |
22 | 22 | import com.alibaba.loongsuite.otel.util.genai.types.OutputMessage; |
23 | 23 | import com.alibaba.loongsuite.otel.util.genai.types.TextPart; |
24 | | -import java.util.List; |
| 24 | + |
| 25 | +import java.util.Collections; |
| 26 | + |
25 | 27 | import org.springframework.beans.factory.annotation.Value; |
26 | 28 | import org.springframework.stereotype.Service; |
27 | 29 |
|
@@ -49,24 +51,55 @@ public AgentResponse invokeAgent(String agentName, String task) { |
49 | 51 | inv.setAgentId("agent-" + agentName); |
50 | 52 | inv.setAgentDescription("Example agent: " + agentName); |
51 | 53 | inv.setInputMessages( |
52 | | - List.of(new InputMessage("user", List.of(new TextPart(task))))); |
| 54 | + Collections.singletonList( |
| 55 | + new InputMessage("user", Collections.singletonList(new TextPart(task))))); |
53 | 56 |
|
54 | 57 | ChatService.ChatResponse llmResponse = chatService.chat(task); |
55 | 58 |
|
56 | 59 | inv.setOutputMessages( |
57 | | - List.of( |
| 60 | + Collections.singletonList( |
58 | 61 | new OutputMessage( |
59 | 62 | "assistant", |
60 | | - List.of(new TextPart(llmResponse.content())), |
| 63 | + Collections.singletonList(new TextPart(llmResponse.getContent())), |
61 | 64 | "stop"))); |
62 | | - inv.setInputTokens(llmResponse.inputTokens()); |
63 | | - inv.setOutputTokens(llmResponse.outputTokens()); |
| 65 | + inv.setInputTokens(llmResponse.getInputTokens()); |
| 66 | + inv.setOutputTokens(llmResponse.getOutputTokens()); |
64 | 67 |
|
65 | | - return new AgentResponse(agentName, llmResponse.content(), |
66 | | - llmResponse.inputTokens(), llmResponse.outputTokens()); |
| 68 | + return new AgentResponse( |
| 69 | + agentName, |
| 70 | + llmResponse.getContent(), |
| 71 | + llmResponse.getInputTokens(), |
| 72 | + llmResponse.getOutputTokens()); |
67 | 73 | } |
68 | 74 | } |
69 | 75 |
|
70 | | - public record AgentResponse( |
71 | | - String agentName, String content, long inputTokens, long outputTokens) {} |
| 76 | + public static class AgentResponse { |
| 77 | + private final String agentName; |
| 78 | + private final String content; |
| 79 | + private final long inputTokens; |
| 80 | + private final long outputTokens; |
| 81 | + |
| 82 | + public AgentResponse(String agentName, String content, long inputTokens, long outputTokens) { |
| 83 | + this.agentName = agentName; |
| 84 | + this.content = content; |
| 85 | + this.inputTokens = inputTokens; |
| 86 | + this.outputTokens = outputTokens; |
| 87 | + } |
| 88 | + |
| 89 | + public String getAgentName() { |
| 90 | + return agentName; |
| 91 | + } |
| 92 | + |
| 93 | + public String getContent() { |
| 94 | + return content; |
| 95 | + } |
| 96 | + |
| 97 | + public long getInputTokens() { |
| 98 | + return inputTokens; |
| 99 | + } |
| 100 | + |
| 101 | + public long getOutputTokens() { |
| 102 | + return outputTokens; |
| 103 | + } |
| 104 | + } |
72 | 105 | } |
0 commit comments