-
Notifications
You must be signed in to change notification settings - Fork 10
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(entities-plugins): ai-proxy-advanced form (#1769)
- Loading branch information
1 parent
34dc09a
commit 0485ca2
Showing
5 changed files
with
64 additions
and
8 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
38 changes: 38 additions & 0 deletions
38
packages/entities/entities-plugins/src/definitions/schemas/AIProxyAdvanced.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
import type { CommonSchemaFields } from '../../types/plugins/shared' | ||
|
||
export const aiProxyAdvancedSchema: CommonSchemaFields = { | ||
// For the ai-proxy-advanced plugin, 'config-embeddings' and 'config-vectordb' fields are non-required | ||
// but they have nested fields that are required. If the nested fields are not provided, 'config-embeddings' | ||
// and 'config-vectordb' should be set to null in the payload. | ||
shamefullyTransformPayload: ({ originalModel, model, payload }) => { | ||
const isDirty = (key: string) => { | ||
// if the model value is the same as the original value | ||
// the field is not dirty | ||
if (originalModel[key] === model[key]) { | ||
return false | ||
} | ||
|
||
// if the original value is null, and the model value is not empty or NaN | ||
// the field is dirty | ||
if (originalModel[key] === null) { | ||
return model[key] !== '' && !Number.isNaN(model[key]) | ||
} | ||
|
||
// if the original value is not null, and the model value is not the same as the original value | ||
// the field is dirty | ||
return true | ||
} | ||
|
||
const hasDirtyFields = (prefix: string) => Object.keys(originalModel) | ||
.some(key => key.startsWith(prefix) && isDirty(key)) | ||
|
||
// If 'config-embeddings-*' fields are not dirty, set 'config-embeddings' to null in the payload | ||
if (!hasDirtyFields('config-embeddings')) { | ||
payload.config.embeddings = null | ||
} | ||
// If 'config-vectordb-*' fields are not dirty, set 'config-vectordb' to null in the payload | ||
if (!hasDirtyFields('config-vectordb')) { | ||
payload.config.vectordb = null | ||
} | ||
}, | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters