| const interchangeableKeys = new Map([ |
| ['chatGptLabel', ['modelLabel']], |
| ['modelLabel', ['chatGptLabel']], |
| ]); |
|
|
| |
| |
| |
| |
| |
| |
| const enforceModelSpec = (modelSpec, parsedBody) => { |
| for (const [key, value] of Object.entries(modelSpec.preset)) { |
| if (key === 'endpoint') { |
| continue; |
| } |
|
|
| if (!checkMatch(key, value, parsedBody)) { |
| return false; |
| } |
| } |
| return true; |
| }; |
|
|
| |
| |
| |
| |
| |
| |
| |
| |
| const checkMatch = (key, value, parsedBody) => { |
| const isEqual = (a, b) => { |
| if (Array.isArray(a) && Array.isArray(b)) { |
| return a.length === b.length && a.every((val, index) => isEqual(val, b[index])); |
| } else if (typeof a === 'object' && typeof b === 'object' && a !== null && b !== null) { |
| const keysA = Object.keys(a); |
| const keysB = Object.keys(b); |
| return keysA.length === keysB.length && keysA.every((k) => isEqual(a[k], b[k])); |
| } |
| return a === b; |
| }; |
|
|
| if (isEqual(parsedBody[key], value)) { |
| return true; |
| } |
|
|
| if (interchangeableKeys.has(key)) { |
| return interchangeableKeys |
| .get(key) |
| .some((interchangeableKey) => isEqual(parsedBody[interchangeableKey], value)); |
| } |
|
|
| return false; |
| }; |
|
|
| module.exports = enforceModelSpec; |
|
|