| 5 | import { type chatCompletionInputReqPayload } from "~/types/shared.types"; |
| 6 | |
| 7 | function sortKeys(obj: JsonValue): JsonValue { |
| 8 | if (typeof obj !== "object" || obj === null) { |
| 9 | // Not an object or array, return as is |
| 10 | return obj; |
| 11 | } |
| 12 | |
| 13 | if (Array.isArray(obj)) { |
| 14 | return obj.map(sortKeys); |
| 15 | } |
| 16 | |
| 17 | // Get keys and sort them |
| 18 | const keys = Object.keys(obj).sort(); |
| 19 | const sortedObj = {}; |
| 20 | |
| 21 | for (const key of keys) { |
| 22 | // @ts-expect-error not worth fixing types |
| 23 | // eslint-disable-next-line @typescript-eslint/no-unsafe-argument |
| 24 | sortedObj[key] = sortKeys(obj[key]); |
| 25 | } |
| 26 | |
| 27 | return sortedObj; |
| 28 | } |
| 29 | |
| 30 | export function hashRequest( |
| 31 | modelId: string, |