Skip to content

Instantly share code, notes, and snippets.

@kachar
Created January 30, 2024 15:39
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save kachar/cd097e11209c37e2a9403572a3163290 to your computer and use it in GitHub Desktop.
Save kachar/cd097e11209c37e2a9403572a3163290 to your computer and use it in GitHub Desktop.
Dalee-3 Azure image geneation
import type { ImagesResponse } from 'openai/resources/images.mjs'
import type { AzureOpenAIInput, OpenAIChatInput } from '@langchain/openai'
import { typedFetch } from '@/server/utils/fetch.utils'
export const generateAzureImage = async ({
size,
prompt,
settings,
numImages,
}: {
size: string
prompt: string
settings: Partial<AzureOpenAIInput>
numImages: number
}) => {
if (!settings.azureOpenAIApiKey) {
throw new Error('azureOpenAIApiKey is not set')
}
const url = getAzureEndpoint(settings)
return typedFetch<ImagesResponse>(url, {
method: 'POST',
headers: {
'Content-Type': 'application/json',
'api-key': settings.azureOpenAIApiKey,
},
timeout: 60_000,
body: JSON.stringify({ n: numImages, size, prompt }),
})
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment