-
-
Notifications
You must be signed in to change notification settings - Fork 1.9k
Feature(provider): add i18n registration path for provider adapters #6889
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
09e88e2
a2c1fc9
6761013
dd1abfc
ed8cfd6
2a61a1a
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,4 +1,17 @@ | ||
| from .entities import ProviderMetaData | ||
| from .provider import Provider, STTProvider | ||
| from .provider import ( | ||
| EmbeddingProvider, | ||
| Provider, | ||
| RerankProvider, | ||
| STTProvider, | ||
| TTSProvider, | ||
| ) | ||
|
|
||
| __all__ = ["Provider", "ProviderMetaData", "STTProvider"] | ||
| __all__ = [ | ||
| "Provider", | ||
| "ProviderMetaData", | ||
| "STTProvider", | ||
| "TTSProvider", | ||
| "EmbeddingProvider", | ||
| "RerankProvider", | ||
| ] |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -43,9 +43,21 @@ const translateIfKey = (value) => { | |
| } | ||
|
|
||
| const filteredIterable = computed(() => { | ||
| if (!props.iterable) return {} | ||
| const { hint, ...rest } = props.iterable | ||
| return rest | ||
| const result = {} | ||
| const metadataItems = props.metadata?.[props.metadataKey]?.items || {} | ||
| const iterable = props.iterable || {} | ||
|
|
||
| for (const key of Object.keys(metadataItems)) { | ||
| if (key === 'hint') continue | ||
| result[key] = iterable[key] | ||
| } | ||
|
Comment on lines
+50
to
+53
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
This loop now prioritizes all metadata keys instead of the keys actually present in Useful? React with 👍 / 👎. |
||
|
|
||
| for (const [key, value] of Object.entries(iterable)) { | ||
| if (key === 'hint' || key in result) continue | ||
| result[key] = value | ||
| } | ||
|
|
||
| return result | ||
| }) | ||
|
|
||
| const providerHint = computed(() => { | ||
|
|
@@ -155,6 +167,28 @@ function getItemPath(key) { | |
| return props.pathPrefix ? `${props.pathPrefix}.${key}` : key | ||
| } | ||
|
|
||
| function ensureStructuredValue(key, itemMeta) { | ||
| if (!props.iterable || typeof props.iterable !== 'object') { | ||
| return undefined | ||
| } | ||
|
|
||
| if (props.iterable[key] !== undefined && props.iterable[key] !== null) { | ||
| return props.iterable[key] | ||
| } | ||
|
|
||
| if (itemMeta?.type === 'object' || itemMeta?.type === 'dict') { | ||
| props.iterable[key] = {} | ||
| return props.iterable[key] | ||
| } | ||
|
|
||
| if (itemMeta?.type === 'list' || itemMeta?.type === 'template_list') { | ||
| props.iterable[key] = [] | ||
| return props.iterable[key] | ||
| } | ||
|
|
||
| return props.iterable[key] | ||
| } | ||
|
Comment on lines
+170
to
+190
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. |
||
|
|
||
| function hasVisibleItemsAfter(items, currentIndex) { | ||
| const itemEntries = Object.entries(items) | ||
|
|
||
|
|
@@ -204,7 +238,7 @@ function hasVisibleItemsAfter(items, currentIndex) { | |
| <v-expand-transition> | ||
| <AstrBotConfig | ||
| :metadata="metadata[metadataKey].items" | ||
| :iterable="iterable[key]" | ||
| :iterable="ensureStructuredValue(key, metadata[metadataKey].items[key])" | ||
| :metadataKey="key" | ||
| :pluginName="pluginName" | ||
| :pathPrefix="getItemPath(key)" | ||
|
|
@@ -231,7 +265,8 @@ function hasVisibleItemsAfter(items, currentIndex) { | |
| </v-list-item-subtitle> | ||
| </div> | ||
| <TemplateListEditor | ||
| v-model="iterable[key]" | ||
| :model-value="ensureStructuredValue(key, metadata[metadataKey].items[key])" | ||
| @update:model-value="iterable[key] = $event" | ||
| :templates="metadata[metadataKey].items[key]?.templates || {}" | ||
| class="config-field" | ||
| /> | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This rewrites dynamic provider metadata to i18n keys whenever
i18n_resourcesis present, but it does not keep a readable fallback for locales that the plugin does not provide. In that case (for example, plugin only shipszh-CNwhile UI isen-US), the frontend receives key paths without corresponding translations and renders raw strings likeprovider_group.provider.xxx.field.hint, making provider-source forms hard to use. Keep original metadata text as fallback (or gate key-rewriting on available locale data) so partially localized providers remain usable.Useful? React with 👍 / 👎.