kopia lustrzana https://github.com/transitive-bullshit/chatgpt-api
feat: core type improvementsgs
rodzic
94150dee82
commit
125088dcd5
|
@ -14,7 +14,7 @@
|
||||||
"type": "module",
|
"type": "module",
|
||||||
"scripts": {
|
"scripts": {
|
||||||
"build": "turbo build",
|
"build": "turbo build",
|
||||||
"dev": "turbo dev --concurrency 50 --continue",
|
"dev": "turbo dev --continue",
|
||||||
"docs": "cd docs && npx mintlify dev",
|
"docs": "cd docs && npx mintlify dev",
|
||||||
"clean": "turbo clean",
|
"clean": "turbo clean",
|
||||||
"fix": "run-s fix:*",
|
"fix": "run-s fix:*",
|
||||||
|
|
|
@ -20,7 +20,6 @@ export type DeepNullable<T> = T extends object
|
||||||
|
|
||||||
export type MaybePromise<T> = T | Promise<T>
|
export type MaybePromise<T> = T | Promise<T>
|
||||||
|
|
||||||
// TODO: use a more specific type
|
|
||||||
export type JSONSchema = Record<string, unknown>
|
export type JSONSchema = Record<string, unknown>
|
||||||
|
|
||||||
export type RelaxedJsonifiable = Jsonifiable | Record<string, unknown>
|
export type RelaxedJsonifiable = Jsonifiable | Record<string, unknown>
|
||||||
|
|
|
@ -232,9 +232,18 @@ export function sanitizeSearchParams(
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Stringifies a JSON value in a way that's optimized for use with LLM prompts.
|
* Stringifies a JSON value in a way that's optimized for use with LLM prompts.
|
||||||
|
*
|
||||||
|
* Replacement for `JSON.stringify` when working with LLMs.
|
||||||
|
*
|
||||||
|
* @example
|
||||||
|
* ```ts
|
||||||
|
* stringifyForModel({ a: 1, b: 2 }) // '{"a":1,"b":2}'
|
||||||
|
* ```
|
||||||
*/
|
*/
|
||||||
export function stringifyForModel(
|
export function stringifyForModel(
|
||||||
jsonObject?: types.RelaxedJsonifiable
|
jsonObject?: types.RelaxedJsonifiable,
|
||||||
|
replacer: (number | string)[] | null = null,
|
||||||
|
space: string | number = 0
|
||||||
): string {
|
): string {
|
||||||
if (jsonObject === undefined) {
|
if (jsonObject === undefined) {
|
||||||
return ''
|
return ''
|
||||||
|
@ -244,13 +253,13 @@ export function stringifyForModel(
|
||||||
return jsonObject
|
return jsonObject
|
||||||
}
|
}
|
||||||
|
|
||||||
return JSON.stringify(jsonObject, null, 0)
|
return JSON.stringify(jsonObject, replacer, space)
|
||||||
}
|
}
|
||||||
|
|
||||||
const dedenter = dedent.withOptions({ escapeSpecialCharacters: true })
|
const dedenter = dedent.withOptions({ escapeSpecialCharacters: true })
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Clean a string by removing extra newlines and indentation.
|
* Cleans a string by removing extra newlines and indentation.
|
||||||
*
|
*
|
||||||
* @see: https://github.com/dmnd/dedent
|
* @see: https://github.com/dmnd/dedent
|
||||||
*/
|
*/
|
||||||
|
|
|
@ -375,10 +375,10 @@ importers:
|
||||||
version: link:../../packages/xsai
|
version: link:../../packages/xsai
|
||||||
'@xsai/tool':
|
'@xsai/tool':
|
||||||
specifier: 'catalog:'
|
specifier: 'catalog:'
|
||||||
version: 0.1.3(zod-to-json-schema@3.24.3(zod@3.24.2))
|
version: 0.1.3(zod-to-json-schema@3.24.5(zod@3.24.2))
|
||||||
xsai:
|
xsai:
|
||||||
specifier: 'catalog:'
|
specifier: 'catalog:'
|
||||||
version: 0.1.3(zod-to-json-schema@3.24.3(zod@3.24.2))
|
version: 0.1.3(zod-to-json-schema@3.24.5(zod@3.24.2))
|
||||||
zod:
|
zod:
|
||||||
specifier: 'catalog:'
|
specifier: 'catalog:'
|
||||||
version: 3.24.2
|
version: 3.24.2
|
||||||
|
@ -1390,7 +1390,7 @@ importers:
|
||||||
version: link:../tsconfig
|
version: link:../tsconfig
|
||||||
'@xsai/tool':
|
'@xsai/tool':
|
||||||
specifier: 'catalog:'
|
specifier: 'catalog:'
|
||||||
version: 0.1.3(zod-to-json-schema@3.24.3(zod@3.24.2))
|
version: 0.1.3(zod-to-json-schema@3.24.5(zod@3.24.2))
|
||||||
|
|
||||||
packages/zoominfo:
|
packages/zoominfo:
|
||||||
dependencies:
|
dependencies:
|
||||||
|
@ -5294,7 +5294,6 @@ packages:
|
||||||
|
|
||||||
libsql@0.4.7:
|
libsql@0.4.7:
|
||||||
resolution: {integrity: sha512-T9eIRCs6b0J1SHKYIvD8+KCJMcWZ900iZyxdnSCdqxN12Z1ijzT+jY5nrk72Jw4B0HGzms2NgpryArlJqvc3Lw==}
|
resolution: {integrity: sha512-T9eIRCs6b0J1SHKYIvD8+KCJMcWZ900iZyxdnSCdqxN12Z1ijzT+jY5nrk72Jw4B0HGzms2NgpryArlJqvc3Lw==}
|
||||||
cpu: [x64, arm64, wasm32]
|
|
||||||
os: [darwin, linux, win32]
|
os: [darwin, linux, win32]
|
||||||
|
|
||||||
lilconfig@3.1.3:
|
lilconfig@3.1.3:
|
||||||
|
@ -7005,6 +7004,11 @@ packages:
|
||||||
peerDependencies:
|
peerDependencies:
|
||||||
zod: ^3.24.1
|
zod: ^3.24.1
|
||||||
|
|
||||||
|
zod-to-json-schema@3.24.5:
|
||||||
|
resolution: {integrity: sha512-/AuWwMP+YqiPbsJx5D6TfgRTc4kTLjsh5SOcd4bLsfUg2RcEXrFMJl1DGgdHy2aCfsIA/cr/1JM0xcB2GZji8g==}
|
||||||
|
peerDependencies:
|
||||||
|
zod: ^3.24.1
|
||||||
|
|
||||||
zod-validation-error@3.4.0:
|
zod-validation-error@3.4.0:
|
||||||
resolution: {integrity: sha512-ZOPR9SVY6Pb2qqO5XHt+MkkTRxGXb4EVtnjc9JpXUOtUB1T9Ru7mZOT361AN3MsetVe7R0a1KZshJDZdgp9miQ==}
|
resolution: {integrity: sha512-ZOPR9SVY6Pb2qqO5XHt+MkkTRxGXb4EVtnjc9JpXUOtUB1T9Ru7mZOT361AN3MsetVe7R0a1KZshJDZdgp9miQ==}
|
||||||
engines: {node: '>=18.0.0'}
|
engines: {node: '>=18.0.0'}
|
||||||
|
@ -9783,10 +9787,10 @@ snapshots:
|
||||||
dependencies:
|
dependencies:
|
||||||
'@xsai/shared': 0.1.3
|
'@xsai/shared': 0.1.3
|
||||||
|
|
||||||
'@xsai/generate-object@0.1.3(zod-to-json-schema@3.24.3(zod@3.24.2))':
|
'@xsai/generate-object@0.1.3(zod-to-json-schema@3.24.5(zod@3.24.2))':
|
||||||
dependencies:
|
dependencies:
|
||||||
'@xsai/generate-text': 0.1.3
|
'@xsai/generate-text': 0.1.3
|
||||||
xsschema: 0.1.3(zod-to-json-schema@3.24.3(zod@3.24.2))
|
xsschema: 0.1.3(zod-to-json-schema@3.24.5(zod@3.24.2))
|
||||||
transitivePeerDependencies:
|
transitivePeerDependencies:
|
||||||
- '@valibot/to-json-schema'
|
- '@valibot/to-json-schema'
|
||||||
- arktype
|
- arktype
|
||||||
|
@ -9814,10 +9818,10 @@ snapshots:
|
||||||
|
|
||||||
'@xsai/shared@0.1.3': {}
|
'@xsai/shared@0.1.3': {}
|
||||||
|
|
||||||
'@xsai/stream-object@0.1.3(zod-to-json-schema@3.24.3(zod@3.24.2))':
|
'@xsai/stream-object@0.1.3(zod-to-json-schema@3.24.5(zod@3.24.2))':
|
||||||
dependencies:
|
dependencies:
|
||||||
'@xsai/stream-text': 0.1.3
|
'@xsai/stream-text': 0.1.3
|
||||||
xsschema: 0.1.3(zod-to-json-schema@3.24.3(zod@3.24.2))
|
xsschema: 0.1.3(zod-to-json-schema@3.24.5(zod@3.24.2))
|
||||||
transitivePeerDependencies:
|
transitivePeerDependencies:
|
||||||
- '@valibot/to-json-schema'
|
- '@valibot/to-json-schema'
|
||||||
- arktype
|
- arktype
|
||||||
|
@ -9827,11 +9831,11 @@ snapshots:
|
||||||
dependencies:
|
dependencies:
|
||||||
'@xsai/shared-chat': 0.1.3
|
'@xsai/shared-chat': 0.1.3
|
||||||
|
|
||||||
'@xsai/tool@0.1.3(zod-to-json-schema@3.24.3(zod@3.24.2))':
|
'@xsai/tool@0.1.3(zod-to-json-schema@3.24.5(zod@3.24.2))':
|
||||||
dependencies:
|
dependencies:
|
||||||
'@xsai/shared': 0.1.3
|
'@xsai/shared': 0.1.3
|
||||||
'@xsai/shared-chat': 0.1.3
|
'@xsai/shared-chat': 0.1.3
|
||||||
xsschema: 0.1.3(zod-to-json-schema@3.24.3(zod@3.24.2))
|
xsschema: 0.1.3(zod-to-json-schema@3.24.5(zod@3.24.2))
|
||||||
transitivePeerDependencies:
|
transitivePeerDependencies:
|
||||||
- '@valibot/to-json-schema'
|
- '@valibot/to-json-schema'
|
||||||
- arktype
|
- arktype
|
||||||
|
@ -13538,19 +13542,19 @@ snapshots:
|
||||||
|
|
||||||
ws@8.18.0: {}
|
ws@8.18.0: {}
|
||||||
|
|
||||||
xsai@0.1.3(zod-to-json-schema@3.24.3(zod@3.24.2)):
|
xsai@0.1.3(zod-to-json-schema@3.24.5(zod@3.24.2)):
|
||||||
dependencies:
|
dependencies:
|
||||||
'@xsai/embed': 0.1.3
|
'@xsai/embed': 0.1.3
|
||||||
'@xsai/generate-object': 0.1.3(zod-to-json-schema@3.24.3(zod@3.24.2))
|
'@xsai/generate-object': 0.1.3(zod-to-json-schema@3.24.5(zod@3.24.2))
|
||||||
'@xsai/generate-speech': 0.1.3
|
'@xsai/generate-speech': 0.1.3
|
||||||
'@xsai/generate-text': 0.1.3
|
'@xsai/generate-text': 0.1.3
|
||||||
'@xsai/generate-transcription': 0.1.3
|
'@xsai/generate-transcription': 0.1.3
|
||||||
'@xsai/model': 0.1.3
|
'@xsai/model': 0.1.3
|
||||||
'@xsai/shared': 0.1.3
|
'@xsai/shared': 0.1.3
|
||||||
'@xsai/shared-chat': 0.1.3
|
'@xsai/shared-chat': 0.1.3
|
||||||
'@xsai/stream-object': 0.1.3(zod-to-json-schema@3.24.3(zod@3.24.2))
|
'@xsai/stream-object': 0.1.3(zod-to-json-schema@3.24.5(zod@3.24.2))
|
||||||
'@xsai/stream-text': 0.1.3
|
'@xsai/stream-text': 0.1.3
|
||||||
'@xsai/tool': 0.1.3(zod-to-json-schema@3.24.3(zod@3.24.2))
|
'@xsai/tool': 0.1.3(zod-to-json-schema@3.24.5(zod@3.24.2))
|
||||||
'@xsai/utils-chat': 0.1.3
|
'@xsai/utils-chat': 0.1.3
|
||||||
'@xsai/utils-stream': 0.1.3
|
'@xsai/utils-stream': 0.1.3
|
||||||
transitivePeerDependencies:
|
transitivePeerDependencies:
|
||||||
|
@ -13558,9 +13562,9 @@ snapshots:
|
||||||
- arktype
|
- arktype
|
||||||
- zod-to-json-schema
|
- zod-to-json-schema
|
||||||
|
|
||||||
xsschema@0.1.3(zod-to-json-schema@3.24.3(zod@3.24.2)):
|
xsschema@0.1.3(zod-to-json-schema@3.24.5(zod@3.24.2)):
|
||||||
optionalDependencies:
|
optionalDependencies:
|
||||||
zod-to-json-schema: 3.24.3(zod@3.24.2)
|
zod-to-json-schema: 3.24.5(zod@3.24.2)
|
||||||
|
|
||||||
xstate@5.19.2: {}
|
xstate@5.19.2: {}
|
||||||
|
|
||||||
|
@ -13594,6 +13598,11 @@ snapshots:
|
||||||
dependencies:
|
dependencies:
|
||||||
zod: 3.24.2
|
zod: 3.24.2
|
||||||
|
|
||||||
|
zod-to-json-schema@3.24.5(zod@3.24.2):
|
||||||
|
dependencies:
|
||||||
|
zod: 3.24.2
|
||||||
|
optional: true
|
||||||
|
|
||||||
zod-validation-error@3.4.0(zod@3.24.2):
|
zod-validation-error@3.4.0(zod@3.24.2):
|
||||||
dependencies:
|
dependencies:
|
||||||
zod: 3.24.2
|
zod: 3.24.2
|
||||||
|
|
Ładowanie…
Reference in New Issue