2
0

🐛 (openai) Fix assistant sequence was not correctly saved

Also add logs to debug open ai errors. Related to #393.
This commit is contained in:
Baptiste Arnaud
2023-03-15 17:47:05 +01:00
parent 76a8064e7c
commit 5aec8b6c66
4 changed files with 62 additions and 35 deletions

View File

@@ -1,27 +1,38 @@
import { Variable } from '@typebot.io/schemas'
import { parseVariables } from './parseVariables'
import {
defaultParseVariablesOptions,
parseVariables,
ParseVariablesOptions,
} from './parseVariables'
export const deepParseVariables =
(variables: Variable[]) =>
(
variables: Variable[],
options: ParseVariablesOptions = defaultParseVariablesOptions
) =>
<T extends Record<string, unknown>>(object: T): T =>
Object.keys(object).reduce<T>((newObj, key) => {
const currentValue = object[key]
if (typeof currentValue === 'string')
return { ...newObj, [key]: parseVariables(variables)(currentValue) }
return {
...newObj,
[key]: parseVariables(variables, options)(currentValue),
}
if (currentValue instanceof Object && currentValue.constructor === Object)
return {
...newObj,
[key]: deepParseVariables(variables)(
currentValue as Record<string, unknown>
),
[key]: deepParseVariables(
variables,
options
)(currentValue as Record<string, unknown>),
}
if (currentValue instanceof Array)
return {
...newObj,
[key]: currentValue.map(deepParseVariables(variables)),
[key]: currentValue.map(deepParseVariables(variables, options)),
}
return { ...newObj, [key]: currentValue }