Skip to content

Fix Nacos 3.2.1 Prompt Registry integration - #294

Open
logicwu0 wants to merge 2 commits into
spring-ai-alibaba:mainfrom
logicwu0:fix/246-nacos-prompt-registry
Open

Fix Nacos 3.2.1 Prompt Registry integration#294
logicwu0 wants to merge 2 commits into
spring-ai-alibaba:mainfrom
logicwu0:fix/246-nacos-prompt-registry

Conversation

@logicwu0

Copy link
Copy Markdown
Contributor

Summary

  • create the Nacos AI client from the existing Nacos configuration
  • subscribe each configurable prompt by its Prompt Registry key
  • apply remote templates and variable defaults on initial load and updates
  • keep the legacy aggregate configuration listener for backward compatibility

Tests

  • mvn -pl auto-configurations/spring-ai-alibaba-autoconfigure-nacos-prompt -am test

Closes #246

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: e0c98e7e10

ℹ️ About Codex in GitHub

Codex has been enabled to automatically review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".

Comment on lines +145 to +147
.configure(PromptTemplate.builder()
.template(template)
.variables(model == null ? new HashMap<>() : model));

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P2 Badge Render Nacos prompt variables with the right delimiters

When a registry prompt uses Nacos's standard double-brace placeholders like {{name}}, this passes the template unchanged into Spring AI's default PromptTemplate renderer, which expects single-brace placeholders like {name}. In that common Nacos Prompt Registry format, the defaults extracted from PromptVariable do not bind to the remote template, so factory.create(...).render() fails or leaves malformed braces instead of rendering the registry prompt; translate the Nacos placeholders or configure an appropriate renderer before building the PromptTemplate.

Useful? React with 👍 / 👎.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Fixed in db1835f. Registry templates now normalize only declared Nacos double-brace placeholders to the single-brace form expected by the Spring prompt renderer. The initial-load and update tests now use the registry format.

Comment on lines +126 to +127
if (prompt == null) {
return;

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P2 Badge Handle Nacos prompt deletion events

When a subscribed prompt is deleted from the Nacos Prompt Registry, the prompt-change event carries a null prompt, but this branch returns without changing templates. In environments that withdraw or delete a prompt after it has been loaded, callers keep rendering the last remote version indefinitely instead of falling back to the local template or removing the entry, so the null event should actively clear or restore the cached state.

Useful? React with 👍 / 👎.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Fixed in db1835f. The factory now retains the first locally created template as a fallback. A null prompt event restores that fallback, or removes the cached entry when no fallback exists. A deletion regression test covers this behavior.

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.

[BUG] 与nacos3.2.1的prompt管理兼容性问题

1 participant