feat(server): switch i2i to gpt (#12238)

fix AI-14
fix AI-17
fix AI-39
fix AI-112

<!-- This is an auto-generated comment: release notes by coderabbit.ai -->
## Summary by CodeRabbit

- **New Features**
  - Expanded and reorganized prompt options for text and image actions, adding new prompts for image generation, style conversions, upscaling, background removal, and sticker creation.
  - Enhanced image editing capabilities with direct support for image attachments in prompts.

- **Improvements**
  - Updated prompt names and descriptions to be more user-friendly and descriptive.
  - Simplified and clarified prompt selection and image processing workflows with improved default behaviors.
  - Better organization of prompts through clear grouping and categorization.

- **Bug Fixes**
  - Improved validation and handling of image attachments during editing requests.

- **Refactor**
  - Internal code restructuring of prompts and provider logic for clarity and maintainability without affecting user workflows.
  - Refined message handling and content merging logic to ensure consistent prompt processing.
  - Adjusted image attachment rendering logic for improved display consistency.
<!-- end of auto-generated comment: release notes by coderabbit.ai -->
This commit is contained in:
darkskygit
2025-05-27 11:36:47 +00:00
parent 1e9cbdb65d
commit 3c0fa429c5
10 changed files with 342 additions and 145 deletions
@@ -518,12 +518,7 @@ const actions = [
type: 'text' as const,
},
{
promptName: [
'debug:action:fal-face-to-sticker',
'debug:action:fal-remove-bg',
'debug:action:fal-sd15',
'debug:action:fal-upscaler',
],
promptName: ['Convert to sticker', 'Remove background', 'Upscale image'],
messages: [
{
role: 'user' as const,
@@ -590,6 +585,8 @@ for (const {
}))!;
t.truthy(provider, 'should have provider');
await retry(`action: ${promptName}`, t, async t => {
const finalConfig = Object.assign({}, prompt.config, config);
switch (type) {
case 'text': {
const result = await provider.text(
@@ -604,7 +601,7 @@ for (const {
),
...messages,
],
Object.assign({}, prompt.config, config)
finalConfig
);
t.truthy(result, 'should return result');
verifier?.(t, result);
@@ -622,23 +619,39 @@ for (const {
),
...messages,
],
Object.assign({}, prompt.config, config)
finalConfig
);
t.truthy(result, 'should return result');
verifier?.(t, result);
break;
}
case 'image': {
const stream = provider.streamImages({ modelId: prompt.model }, [
...prompt.finish(
messages.reduce(
// @ts-expect-error
(acc, m) => Object.assign(acc, m.params),
{}
)
),
...messages,
]);
const finalMessage = [...messages];
const params = {};
if (finalMessage.length === 1) {
const latestMessage = finalMessage.pop()!;
Object.assign(params, {
content: latestMessage.content,
attachments:
'attachments' in latestMessage
? latestMessage.attachments
: undefined,
});
}
const stream = provider.streamImages(
{ modelId: prompt.model },
[
...prompt.finish(
finalMessage.reduce(
// @ts-expect-error
(acc, m) => Object.assign(acc, m.params),
params
)
),
...finalMessage,
],
finalConfig
);
const result = [];
for await (const attachment of stream) {
@@ -543,12 +543,19 @@ test('should be able to chat with special image model', async t => {
);
};
await testWithModel('debug:action:fal-sd15', 'some-tag');
await testWithModel('Generate image', 'some-tag');
await testWithModel(
'debug:action:fal-upscaler',
'best quality, 8K resolution, highres, clarity, some-tag'
'Convert to sticker',
'convert this image to sticker. you need to identify the subject matter and warp a circle of white stroke around the subject matter and with transparent background. some-tag'
);
await testWithModel(
'Upscale image',
'make the image more detailed. some-tag'
);
await testWithModel(
'Remove background',
'Keep the subject and remove other non-subject items. Transparent background. some-tag'
);
await testWithModel('debug:action:fal-remove-bg', 'some-tag');
Sinon.restore();
});
@@ -84,29 +84,12 @@ export class MockCopilotProvider extends OpenAIProvider {
],
},
{
id: 'lcm-sd15-i2i',
id: 'gpt-image-1',
capabilities: [
{
input: [ModelInputType.Image],
output: [ModelOutputType.Image],
},
],
},
{
id: 'clarity-upscaler',
capabilities: [
{
input: [ModelInputType.Image],
output: [ModelOutputType.Image],
},
],
},
{
id: 'imageutils/rembg',
capabilities: [
{
input: [ModelInputType.Image],
input: [ModelInputType.Text, ModelInputType.Image],
output: [ModelOutputType.Image],
defaultForOutputType: true,
},
],
},