-
Notifications
You must be signed in to change notification settings - Fork 511
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #276 from Portkey-AI/feat/support-azure-image-models
feat: add azure-openai image generate model support
- Loading branch information
Showing
3 changed files
with
76 additions
and
18 deletions.
There are no files selected for viewing
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
import { AZURE_OPEN_AI } from '../../globals'; | ||
import { OpenAIErrorResponseTransform } from '../openai/chatComplete'; | ||
import { ErrorResponse, ImageGenerateResponse, ProviderConfig } from '../types'; | ||
|
||
export const AzureOpenAIImageGenerateConfig: ProviderConfig = { | ||
prompt: { | ||
param: 'prompt', | ||
required: true, | ||
}, | ||
model: { | ||
param: 'model', | ||
required: true, | ||
default: 'dall-e-3', | ||
}, | ||
n: { | ||
param: 'n', | ||
min: 1, | ||
max: 10, | ||
}, | ||
quality: { | ||
param: 'quality', | ||
}, | ||
response_format: { | ||
param: 'response_format', | ||
}, | ||
size: { | ||
param: 'size', | ||
}, | ||
style: { | ||
param: 'style', | ||
}, | ||
user: { | ||
param: 'user', | ||
}, | ||
}; | ||
|
||
interface AzureOpenAIImageObject { | ||
b64_json?: string; // The base64-encoded JSON of the generated image, if response_format is b64_json. | ||
url?: string; // The URL of the generated image, if response_format is url (default). | ||
revised_prompt?: string; // The prompt that was used to generate the image, if there was any revision to the prompt. | ||
} | ||
|
||
interface AzureOpenAIImageGenerateResponse extends ImageGenerateResponse { | ||
data: AzureOpenAIImageObject[]; | ||
} | ||
|
||
export const AzureOpenAIImageGenerateResponseTransform: ( | ||
response: AzureOpenAIImageGenerateResponse | ErrorResponse, | ||
responseStatus: number | ||
) => ImageGenerateResponse | ErrorResponse = (response, responseStatus) => { | ||
if (responseStatus !== 200 && 'error' in response) { | ||
return OpenAIErrorResponseTransform(response, AZURE_OPEN_AI); | ||
} | ||
|
||
return response; | ||
}; |
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