🚑 (openai) Fix create credentials modal not displaying
This commit is contained in:
@ -123,12 +123,24 @@ export const listModels = authenticatedProcedure
|
||||
|
||||
const response = await openai.listModels()
|
||||
|
||||
const modelsData = (await response.json()) as ResponseTypes['listModels']
|
||||
const modelsData = (await response.json()) as
|
||||
| ResponseTypes['listModels']
|
||||
| {
|
||||
error: unknown
|
||||
}
|
||||
|
||||
if ('error' in modelsData)
|
||||
throw new TRPCError({
|
||||
code: 'INTERNAL_SERVER_ERROR',
|
||||
message: 'Could not list models',
|
||||
cause: modelsData.error,
|
||||
})
|
||||
|
||||
return {
|
||||
models: modelsData.data
|
||||
.sort((a, b) => b.created - a.created)
|
||||
.map((model) => model.id),
|
||||
models:
|
||||
modelsData.data
|
||||
.sort((a, b) => b.created - a.created)
|
||||
.map((model) => model.id) ?? [],
|
||||
}
|
||||
}
|
||||
)
|
||||
|
@ -75,14 +75,21 @@ export const OpenAISettings = ({
|
||||
return (
|
||||
<Stack>
|
||||
{workspace && (
|
||||
<CredentialsDropdown
|
||||
type="openai"
|
||||
workspaceId={workspace.id}
|
||||
currentCredentialsId={options?.credentialsId}
|
||||
onCredentialsSelect={updateCredentialsId}
|
||||
onCreateNewClick={onOpen}
|
||||
credentialsName="OpenAI account"
|
||||
/>
|
||||
<>
|
||||
<CredentialsDropdown
|
||||
type="openai"
|
||||
workspaceId={workspace.id}
|
||||
currentCredentialsId={options?.credentialsId}
|
||||
onCredentialsSelect={updateCredentialsId}
|
||||
onCreateNewClick={onOpen}
|
||||
credentialsName="OpenAI account"
|
||||
/>
|
||||
<OpenAICredentialsModal
|
||||
isOpen={isOpen}
|
||||
onClose={onClose}
|
||||
onNewCredentials={updateCredentialsId}
|
||||
/>
|
||||
</>
|
||||
)}
|
||||
{options.credentialsId && (
|
||||
<>
|
||||
@ -110,11 +117,7 @@ export const OpenAISettings = ({
|
||||
</AccordionPanel>
|
||||
</AccordionItem>
|
||||
</Accordion>
|
||||
<OpenAICredentialsModal
|
||||
isOpen={isOpen}
|
||||
onClose={onClose}
|
||||
onNewCredentials={updateCredentialsId}
|
||||
/>
|
||||
|
||||
<DropdownList
|
||||
currentItem={options.task}
|
||||
items={openAITasks.slice(0, -1)}
|
||||
|
@ -1,6 +1,7 @@
|
||||
import { Select } from '@/components/inputs/Select'
|
||||
import { useTypebot } from '@/features/editor/providers/TypebotProvider'
|
||||
import { useWorkspace } from '@/features/workspace/WorkspaceProvider'
|
||||
import { useToast } from '@/hooks/useToast'
|
||||
import { trpc } from '@/lib/trpc'
|
||||
|
||||
type Props = {
|
||||
@ -18,6 +19,7 @@ export const ModelsDropdown = ({
|
||||
}: Props) => {
|
||||
const { typebot } = useTypebot()
|
||||
const { workspace } = useWorkspace()
|
||||
const { showToast } = useToast()
|
||||
|
||||
const { data } = trpc.openAI.listModels.useQuery(
|
||||
{
|
||||
@ -28,6 +30,12 @@ export const ModelsDropdown = ({
|
||||
},
|
||||
{
|
||||
enabled: !!typebot && !!workspace,
|
||||
onError: (error) => {
|
||||
showToast({
|
||||
description: error.message,
|
||||
status: 'error',
|
||||
})
|
||||
},
|
||||
}
|
||||
)
|
||||
|
||||
|
Reference in New Issue
Block a user