Created
January 30, 2024 15:39
-
-
Save kachar/cd097e11209c37e2a9403572a3163290 to your computer and use it in GitHub Desktop.
Dalee-3 Azure image geneation
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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