Skip to content

Conversation

@ThomasVitale
Copy link
Contributor

  • Make ChatClient and Advisor observation logic null-safe
  • Simplify naming for Advisor observations
  • Include high-cardinality attributes only if a value is present
  • Fix condition to include system test to chat client observations
  • Add Advisor order information to context
  • Streamline usage of enums and utils to reduce hard-coded/duplications
  • Fix pending Chroma integration test

* Make ChatClient and Advisor observation logic null-safe
* Simplify naming for Advisor observations
* Include high-cardinality attributes only if a value is present
* Fix condition to include system test to chat client observations
* Add Advisor order information to context
* Streamline usage of enums and utils to reduce hard-coded/duplications
* Fix pending Chroma integration test

Signed-off-by: Thomas Vitale <[email protected]>
.withAdvisorType(AdvisorObservationContext.Type.AROUND)
.withAdvisedRequest(advisedRequest)
.withAdvisorRequestContext(advisedRequest.adviseContext())
.withOrder(advisor.getOrder())
Copy link
Contributor Author

@ThomasVitale ThomasVitale Oct 6, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I noticed we were not passing the "order" field to the observation context, so I added it both for imperative and stream operations

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've added the order to the context but apparently missed to populate it

@Override
public String asString() {
return "spring.ai.chat.client.advisor.type";
return "spring.ai.advisor.type";
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@tzolov what do you think about this simplification of the naming for Advisor attributes?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The advisors are only applicable in the context of ChatClient.
But i guess it is enough to reflect this int the observation's name (e.g. spring.ai.chat.client.advisor) and not in the attribute names?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The related span is also nested under a "chat_client" parent span, so that might be enough. But if we should have it in the attribute name as well, I can revert this

if (!StringUtils.hasText(context.getRequest().getUserText())) {
return CHAT_CLIENT_SYSTEM_TEXT_NONE;
protected void chatClientSystemText(ChatClientObservationContext context) {
if (!StringUtils.hasText(context.getRequest().getSystemText())) {
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Here the condition was checking the user text instead of the system text, I fixed it now

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

good catch

@Override
public String asString() {
return "spring.ai.chat.client.tool.functioncallbacks";
return "spring.ai.chat.client.tool.function.callbacks";
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@tzolov I made this change to align with the other attributes called "*.function.names". Is this ok?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

looks good


private static final KeyValue ADVISOR_NAME_NONE = KeyValue.of(HighCardinalityKeyNames.ADVISOR_NAME,
KeyValue.NONE_VALUE);
public static final String DEFAULT_NAME = "spring.ai.advisor";
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@tzolov this name is only used for metrics. Since Micrometer generates several timer-related metrics with long names, I thought of making this base name shorter as well.

So, instead of having metrics with name "spring_ai_chat_client_advisor_active_milliseconds_count" we would have "spring_ai_advisor_active_milliseconds_count".

Thoughts? Since Advisors are not used anywhere else, we might not need the "chat.client" part in the base name.

@tzolov
Copy link
Contributor

tzolov commented Oct 6, 2024

LGTM, thanks @ThomasVitale

@tzolov tzolov merged commit 1ee9094 into spring-projects:main Oct 6, 2024
1 check passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants