(openai) Stream chat completion to avoid serverless timeout (#526)

Closes #520
This commit is contained in:
Baptiste Arnaud
2023-05-25 10:32:35 +02:00
committed by GitHub
parent 6bb6a2b0e3
commit 56364fd863
39 changed files with 556 additions and 121 deletions

View File

@@ -143,7 +143,7 @@ test.describe.parallel('Google sheets integration', () => {
.press('Enter')
await expect(
page.locator('typebot-standard').locator('text=Your name is:')
).toHaveText(`Your name is: Georges2 Smith2`)
).toHaveText(`Your name is: Georges2 Last name`)
})
})

View File

@@ -51,7 +51,7 @@ export const createCredentials = authenticatedProcedure
if (!workspace)
throw new TRPCError({ code: 'NOT_FOUND', message: 'Workspace not found' })
const { encryptedData, iv } = encrypt(credentials.data)
const { encryptedData, iv } = await encrypt(credentials.data)
const createdCredentials = await prisma.credentials.create({
data: {
...credentials,

View File

@@ -174,8 +174,8 @@ test('Rename and icon change should work', async ({ page }) => {
])
await page.goto(`/typebots/${typebotId}/edit`)
await page.click('[data-testid="editable-icon"]')
await page.getByRole('button', { name: 'Emoji' }).click()
await expect(page.locator('text="My awesome typebot"')).toBeVisible()
await page.fill('input[placeholder="Search..."]', 'love')
await page.click('text="😍"')

View File

@@ -19,10 +19,7 @@ test.describe.parallel('Settings page', () => {
await page.click('text="Typebot.io branding"')
await expect(page.locator('a:has-text("Made with Typebot")')).toBeHidden()
await page.click('text="Remember session"')
await expect(
page.locator('input[type="checkbox"] >> nth=-3')
).toHaveAttribute('checked', '')
await page.click('text="Remember user"')
await expect(page.getByPlaceholder('Type your answer...')).toHaveValue(
'Baptiste'

View File

@@ -74,6 +74,7 @@ test('can update workspace info', async ({ page }) => {
await page.click('text=Settings & Members')
await page.click('text="Settings"')
await page.click('[data-testid="editable-icon"]')
await page.getByRole('button', { name: 'Emoji' }).click()
await page.fill('input[placeholder="Search..."]', 'building')
await page.click('text="🏦"')
await page.waitForTimeout(500)
@@ -92,13 +93,13 @@ test('can manage members', async ({ page }) => {
page.getByRole('heading', { name: 'Members (1/5)' })
).toBeVisible()
await expect(page.locator('text="user@email.com"').nth(1)).toBeVisible()
await expect(page.locator('button >> text="Invite"')).toBeEnabled()
await expect(page.locator('button >> text="Invite"')).toBeDisabled()
await page.fill(
'input[placeholder="colleague@company.com"]',
'guest@email.com'
)
await page.click('button >> text="Invite"')
await expect(page.locator('button >> text="Invite"')).toBeEnabled()
await expect(page.locator('button >> text="Invite"')).toBeVisible()
await expect(
page.locator('input[placeholder="colleague@company.com"]')
).toHaveAttribute('value', '')

View File

@@ -21,10 +21,10 @@ export const getAuthenticatedGoogleClient = async (
where: { id: credentialsId, workspace: { members: { some: { userId } } } },
})) as CredentialsFromDb | undefined
if (!credentials) return
const data = decrypt(
const data = (await decrypt(
credentials.data,
credentials.iv
) as GoogleSheetsCredentials['data']
)) as GoogleSheetsCredentials['data']
oauth2Client.setCredentials(data)
oauth2Client.on('tokens', updateTokens(credentials.id, data))
@@ -47,7 +47,7 @@ const updateTokens =
expiry_date: credentials.expiry_date,
access_token: credentials.access_token,
}
const { encryptedData, iv } = encrypt(newCredentials)
const { encryptedData, iv } = await encrypt(newCredentials)
await prisma.credentials.update({
where: { id: credentialsId },
data: { data: encryptedData, iv },

View File

@@ -28,7 +28,7 @@ const handler = async (req: NextApiRequest, res: NextApiResponse) => {
const data = (
typeof req.body === 'string' ? JSON.parse(req.body) : req.body
) as Credentials
const { encryptedData, iv } = encrypt(data.data)
const { encryptedData, iv } = await encrypt(data.data)
const workspace = await prisma.workspace.findFirst({
where: { id: workspaceId, members: { some: { userId: user.id } } },
select: { id: true },

View File

@@ -37,7 +37,7 @@ const handler = async (req: NextApiRequest, res: NextApiResponse) => {
return res
.status(400)
.send({ message: "User didn't accepted required scopes" })
const { encryptedData, iv } = encrypt(tokens)
const { encryptedData, iv } = await encrypt(tokens)
const credentials = {
name: email,
type: 'google sheets',