Skip to content

Conversation

@wilocu
Copy link
Contributor

@wilocu wilocu commented Jul 29, 2025

#3890
Summary
This PR adds the ability to distinguish between model-generated and tool-generated responses in OllamaChatModel by adding source metadata to
ChatResponse objects. Frontend developers can now easily identify the origin of each response through standardized metadata fields.

Changes Made
Core Implementation:

  • OllamaChatModel.java: Added source metadata constants and modified internalStream() and internalCall() methods to include source="model" in
    generation metadata
  • ToolExecutionResult.java: Added source metadata constants and enhanced buildGenerations() to include source="tool" for tool-generated
    responses

Testing:

  • OllamaChatModelTests.java: Added unit test to verify source metadata creation
  • ToolExecutionResultTests.java: Added unit test to verify tool response source metadata
  • OllamaChatModelIT.java: Added integration test to verify source metadata in real responses

Usage
Developers can now identify response sources:
ChatResponse response = chatModel.call(new Prompt("Hello"));
String source = (String) response.getResult().getMetadata().get("source");
// Returns: "model" for model-generated responses
// Returns: "tool" for tool-generated responses

Testing

  • All existing tests continue to pass
  • New unit tests verify metadata creation for both model and tool responses
  • Integration test confirms functionality with real Ollama responses
  • Build passes with ./mvnw clean package -DskipTests on modified modules

This implementation provides a clean, maintainable solution that enables frontend developers to easily differentiate between response sources
while maintaining full backward compatibility.

Signed-off-by: Mattia Pasetto matpat17@gmail.com

I am still pretty new to contributions, please double check and let me know of any errors.

Signed-off-by: Mattia Pasetto <matpat17@gmail.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

2 participants