2
0

Add "Generate variables" actions in AI blocks

Closes #1586
This commit is contained in:
Baptiste Arnaud
2024-06-18 12:13:00 +02:00
parent bec9cb68ca
commit 76fcf7ee93
25 changed files with 860 additions and 165 deletions

View File

@@ -0,0 +1,40 @@
import OpenAI, { ClientOptions } from 'openai'
import { defaultOpenAIOptions } from '../constants'
type Props = {
apiKey?: string
baseUrl?: string
apiVersion?: string
}
export const fetchGPTModels = async ({
apiKey,
baseUrl = defaultOpenAIOptions.baseUrl,
apiVersion,
}: Props) => {
if (!apiKey) return []
const config = {
apiKey: apiKey,
baseURL: baseUrl ?? defaultOpenAIOptions.baseUrl,
defaultHeaders: {
'api-key': apiKey,
},
defaultQuery: apiVersion
? {
'api-version': apiVersion,
}
: undefined,
} satisfies ClientOptions
const openai = new OpenAI(config)
const models = await openai.models.list()
return (
models.data
.filter((model) => model.id.includes('gpt'))
.sort((a, b) => b.created - a.created)
.map((model) => model.id) ?? []
)
}