chatgpt-api/src/utils.ts

16 wiersze
504 B
TypeScript
Czysty Zwykły widok Historia

import { customAlphabet, urlAlphabet } from 'nanoid'
import * as types from './types'
2023-05-24 06:15:59 +00:00
export const extractJSONObjectFromString = (text: string): string | undefined =>
text.match(/\{(.|\n)*\}/gm)?.[0]
export const extractJSONArrayFromString = (text: string): string | undefined =>
text.match(/\[(.|\n)*\]/gm)?.[0]
2023-06-07 01:03:39 +00:00
export const sleep = (ms: number) =>
new Promise((resolve) => setTimeout(resolve, ms))
export const defaultIDGeneratorFn: types.IDGeneratorFunction =
customAlphabet(urlAlphabet)