Skip to content

Commit

Permalink
⚡ (openai) Add new models and remove tiktoken
Browse files Browse the repository at this point in the history
Instead of computing total tokens with tiktoken we just attempt retries after trimming the first message
  • Loading branch information
baptisteArno committed Jun 16, 2023
1 parent e54aab4 commit 83f2a29
Show file tree
Hide file tree
Showing 11 changed files with 326 additions and 240 deletions.
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { DropdownList } from '@/components/DropdownList'
import { Textarea } from '@/components/inputs'
import { Textarea, TextInput } from '@/components/inputs'
import { VariableSearchInput } from '@/components/inputs/VariableSearchInput'
import { TableListItemProps } from '@/components/TableList'
import { Stack } from '@chakra-ui/react'
Expand Down Expand Up @@ -55,6 +55,11 @@ export const ChatCompletionMessageItem = ({ item, onItemChange }: Props) => {
})
}

const updateName = (name: string) => {
if (item.role === 'Messages sequence ✨') return
onItemChange({ ...item, name })
}

return (
<Stack p="4" rounded="md" flex="1" borderWidth="1px">
<DropdownList
Expand All @@ -77,12 +82,19 @@ export const ChatCompletionMessageItem = ({ item, onItemChange }: Props) => {
/>
</>
) : (
<Textarea
defaultValue={item.content}
onChange={changeSingleMessageContent}
placeholder="Content"
minH="150px"
/>
<>
<Textarea
defaultValue={item.content}
onChange={changeSingleMessageContent}
placeholder="Content"
minH="150px"
/>
<TextInput
defaultValue={item.name}
onChange={updateName}
placeholder="Name (Optional)"
/>
</>
)}
</Stack>
)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import { DropdownList } from '@/components/DropdownList'
import { TableList } from '@/components/TableList'
import {
chatCompletionModels,
ChatCompletionOpenAIOptions,
deprecatedCompletionModels,
} from '@typebot.io/schemas/features/blocks/integrations/openai'
import { ChatCompletionMessageItem } from './ChatCompletionMessageItem'
import {
Expand All @@ -17,6 +17,7 @@ import {
import { TextLink } from '@/components/TextLink'
import { ChatCompletionResponseItem } from './ChatCompletionResponseItem'
import { NumberInput } from '@/components/inputs'
import { Select } from '@/components/inputs/Select'

const apiReferenceUrl =
'https://platform.openai.com/docs/api-reference/chat/create'
Expand All @@ -30,7 +31,11 @@ export const OpenAIChatCompletionSettings = ({
options,
onOptionsChange,
}: Props) => {
const updateModel = (model: (typeof chatCompletionModels)[number]) => {
const updateModel = (
_: string | undefined,
model: (typeof chatCompletionModels)[number] | undefined
) => {
if (!model) return
onOptionsChange({
...options,
model,
Expand Down Expand Up @@ -74,10 +79,12 @@ export const OpenAIChatCompletionSettings = ({
</TextLink>{' '}
to better understand the available options.
</Text>
<DropdownList
currentItem={options.model}
items={chatCompletionModels}
onItemSelect={updateModel}
<Select
selectedItem={options.model}
items={chatCompletionModels.filter(
(model) => deprecatedCompletionModels.indexOf(model) === -1
)}
onSelect={updateModel}
/>
<Accordion allowMultiple>
<AccordionItem>
Expand Down
36 changes: 30 additions & 6 deletions apps/docs/openapi/builder/_spec_.json
Original file line number Diff line number Diff line change
Expand Up @@ -1066,13 +1066,28 @@
"additionalProperties": false
},
"min": {
"type": "number"
"anyOf": [
{
"type": "number"
},
{}
]
},
"max": {
"type": "number"
"anyOf": [
{
"type": "number"
},
{}
]
},
"step": {
"type": "number"
"anyOf": [
{
"type": "number"
},
{}
]
}
},
"required": [
Expand Down Expand Up @@ -1966,6 +1981,7 @@
"Yesterday",
"Tomorrow",
"Random ID",
"Moment of the day",
"Map item with same index"
]
},
Expand Down Expand Up @@ -2833,12 +2849,17 @@
"model": {
"type": "string",
"enum": [
"gpt-3.5-turbo",
"gpt-3.5-turbo-0613",
"gpt-3.5-turbo-16k",
"gpt-3.5-turbo-16k-0613",
"gpt-3.5-turbo-0301",
"gpt-4",
"gpt-4-0314",
"gpt-4-0613",
"gpt-4-32k",
"gpt-4-32k-0613",
"gpt-4-32k-0314",
"gpt-3.5-turbo",
"gpt-3.5-turbo-0301"
"gpt-4-0314"
]
},
"messages": {
Expand All @@ -2861,6 +2882,9 @@
},
"content": {
"type": "string"
},
"name": {
"type": "string"
}
},
"required": [
Expand Down
57 changes: 48 additions & 9 deletions apps/docs/openapi/chat/_spec_.json
Original file line number Diff line number Diff line change
Expand Up @@ -639,13 +639,28 @@
"additionalProperties": false
},
"min": {
"type": "number"
"anyOf": [
{
"type": "number"
},
{}
]
},
"max": {
"type": "number"
"anyOf": [
{
"type": "number"
},
{}
]
},
"step": {
"type": "number"
"anyOf": [
{
"type": "number"
},
{}
]
}
},
"required": [
Expand Down Expand Up @@ -1539,6 +1554,7 @@
"Yesterday",
"Tomorrow",
"Random ID",
"Moment of the day",
"Map item with same index"
]
},
Expand Down Expand Up @@ -2406,12 +2422,17 @@
"model": {
"type": "string",
"enum": [
"gpt-3.5-turbo",
"gpt-3.5-turbo-0613",
"gpt-3.5-turbo-16k",
"gpt-3.5-turbo-16k-0613",
"gpt-3.5-turbo-0301",
"gpt-4",
"gpt-4-0314",
"gpt-4-0613",
"gpt-4-32k",
"gpt-4-32k-0613",
"gpt-4-32k-0314",
"gpt-3.5-turbo",
"gpt-3.5-turbo-0301"
"gpt-4-0314"
]
},
"messages": {
Expand All @@ -2434,6 +2455,9 @@
},
"content": {
"type": "string"
},
"name": {
"type": "string"
}
},
"required": [
Expand Down Expand Up @@ -3862,13 +3886,28 @@
"additionalProperties": false
},
"min": {
"type": "number"
"anyOf": [
{
"type": "number"
},
{}
]
},
"max": {
"type": "number"
"anyOf": [
{
"type": "number"
},
{}
]
},
"step": {
"type": "number"
"anyOf": [
{
"type": "number"
},
{}
]
}
},
"required": [
Expand Down
1 change: 0 additions & 1 deletion apps/viewer/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@
"test:report": "pnpm playwright show-report"
},
"dependencies": {
"@dqbd/tiktoken": "^1.0.7",
"@planetscale/database": "^1.7.0",
"@sentry/nextjs": "7.53.1",
"@trpc/server": "10.27.3",
Expand Down
Loading

4 comments on commit 83f2a29

@vercel
Copy link

@vercel vercel bot commented on 83f2a29 Jun 16, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@vercel
Copy link

@vercel vercel bot commented on 83f2a29 Jun 16, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Successfully deployed to the following URLs:

builder-v2 – ./apps/builder

app.typebot.io
builder-v2-typebot-io.vercel.app
builder-v2-git-main-typebot-io.vercel.app

@vercel
Copy link

@vercel vercel bot commented on 83f2a29 Jun 16, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Successfully deployed to the following URLs:

viewer-v2 – ./apps/viewer

svhm.mprs.in
tiger.cr8.ai
video.cr8.ai
yoda.riku.ai
zebra.cr8.ai
bemestar.club
bergamo.store
bot.krdfy.com
bot.tvbeat.it
cgcassets.com
cnvhub.com.br
facelabko.com
filmylogy.com
goldorayo.com
rabbit.cr8.ai
shop.mexwa.my
signup.cr8.ai
bium.gratirabbit.com
bot.ansuraniphone.my
bot.barrettamario.it
bot.cotemeuplano.com
bot.grupodojo.com.br
bot.leadbooster.help
bot.mycompay.reviews
bot.socialcliques.me
chat.hayurihijab.com
chatbee.agfunnel.com
click.sevenoways.com
connect.growthguy.in
forms.bonanza.design
hello.advergreen.com
kuiz.sistemniaga.com
malayanboosterhq.com
menu.numero-primo.it
menukb.wpwakanda.com
offer.botscientis.us
sellmycarglasgow.com
talkbot.agfunnel.com
tenorioadvogados.com
uppity.wpwakanda.com
83701274.21000000.lol
87186327.21000000.one
90945247.21000000.one
97320578.21000000.one
abutton.wpwakanda.com
acelera.maxbot.com.br
aidigitalmarketing.kr
atendimento.vrauu.com
bbutton.wpwakanda.com
bot.coachayongzul.com
bot.digitalpointer.id
bot.eikju.photography
bot.incusservices.com
bot.meuesocial.com.br
bot.mycompany.reviews
bot.outstandbrand.com
bot.ramonmatos.com.br
bot.robertohairlab.it
bot.sharemyreview.net
bot.truongnguyen.live
botz.cloudsiteapp.com
cdd.searchcube.com.sg
chat.missarkansas.org
piazzatorre.barrettamario.it
poll.mosaicohairboutique.com
type.cookieacademyonline.com
upload.atlasoutfittersk9.com
bot.brigadeirosemdrama.com.br
tuttirecepcao.fratucci.com.br
forms.escoladeautomacao.com.br
onboarding.libertydreamcare.ie
recepcao.tutti.fratucci.com.br
type.talitasouzamarques.com.br
agendamento.sergiolimajr.com.br
anamnese.clinicamegasjdr.com.br
bookings.littlepartymonkeys.com
bot.comercializadoraomicron.com
elevateyourmind.groovepages.com
viewer-v2-typebot-io.vercel.app
yourfeedback.comebackreward.com
baleia.testeeventos.progenbr.com
bot.cabin-rentals-of-georgia.net
chat.portaloficialautorizado.com
open.campus.bot.aalen.university
sondaggio.mosaicohairboutique.it
baleia.testegabinete.progenbr.com
gerador.verificadordehospedes.com
personal-trainer.barrettamario.it
sondaggio.mosaicohairboutique.com
preagendamento.sergiolimajr.com.br
studiotecnicoimmobiliaremerelli.it
download.thailandmicespecialist.com
register.thailandmicespecialist.com
bot.studiotecnicoimmobiliaremerelli.it
pesquisa.escolamodacomproposito.com.br
anamnese.clinicaramosodontologia.com.br
gabinete.baleia.formulario.progenbr.com
chrome-os-inquiry-system.itschromeos.com
viewer-v2-git-main-typebot-io.vercel.app
main-menu-for-itschromeos.itschromeos.com

@vercel
Copy link

@vercel vercel bot commented on 83f2a29 Jun 16, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Successfully deployed to the following URLs:

docs – ./apps/docs

docs-git-main-typebot-io.vercel.app
docs-typebot-io.vercel.app
docs.typebot.io

Please sign in to comment.