-
Notifications
You must be signed in to change notification settings - Fork 3.5k
feat(quiver): add QuiverAI integration for SVG generation and vectorization #3728
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
5846c60
feat(quiver): add QuiverAI integration for SVG generation and vectori…
waleedlatif1 9ab80e3
fix(quiver): address review feedback — n>1 data loss, error handling,…
waleedlatif1 da17505
fix(quiver): add files array to image-to-svg response, remove camelCa…
waleedlatif1 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 hidden or 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 hidden or 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 |
|---|---|---|
|
|
@@ -121,6 +121,7 @@ | |
| "posthog", | ||
| "pulse", | ||
| "qdrant", | ||
| "quiver", | ||
| "rds", | ||
| "reddit", | ||
| "redis", | ||
|
|
||
This file contains hidden or 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,131 @@ | ||
| --- | ||
| title: Quiver | ||
| description: Generate and vectorize SVGs | ||
| --- | ||
|
|
||
| import { BlockInfoCard } from "@/components/ui/block-info-card" | ||
|
|
||
| <BlockInfoCard | ||
| type="quiver" | ||
| color="#000000" | ||
| /> | ||
|
|
||
| {/* MANUAL-CONTENT-START:intro */} | ||
| [QuiverAI](https://quiver.ai/) is an AI-powered SVG generation platform that creates high-quality, scalable vector graphics from text descriptions or by vectorizing raster images. It produces clean, resolution-independent SVGs that are ideal for icons, illustrations, logos, and UI elements. | ||
|
|
||
| With Quiver, you can: | ||
|
|
||
| - **Generate SVGs from text prompts**: Describe the vector graphic you need and get production-ready SVG output | ||
| - **Vectorize raster images**: Convert PNG, JPG, and other raster images into clean SVG vector format | ||
| - **Provide reference images**: Upload up to 4 reference images to guide the style and composition of generated SVGs | ||
| - **Control generation parameters**: Adjust temperature, number of outputs, and token limits to fine-tune results | ||
| - **List available models**: Query available QuiverAI models to discover supported operations and capabilities | ||
| - **Get clean SVG markup**: Receive raw SVG content alongside downloadable files for easy embedding | ||
|
|
||
| In Sim, the Quiver integration enables your workflows to generate and vectorize graphics on demand. This is useful for creating dynamic illustrations, converting raster assets to scalable vectors, generating icons for applications, producing visual assets for content pipelines, or building design automation workflows. The generated SVGs are returned as files that can be passed to downstream blocks for further processing, storage, or delivery. | ||
| {/* MANUAL-CONTENT-END */} | ||
|
|
||
|
|
||
| ## Usage Instructions | ||
|
|
||
| Generate SVG images from text prompts or vectorize raster images into SVGs using QuiverAI. Supports reference images, style instructions, and multiple output generation. | ||
|
|
||
|
|
||
|
|
||
| ## Tools | ||
|
|
||
| ### `quiver_text_to_svg` | ||
|
|
||
| Generate SVG images from text prompts using QuiverAI | ||
|
|
||
| #### Input | ||
|
|
||
| | Parameter | Type | Required | Description | | ||
| | --------- | ---- | -------- | ----------- | | ||
| | `apiKey` | string | Yes | QuiverAI API key | | ||
| | `prompt` | string | Yes | A text description of the desired SVG | | ||
| | `model` | string | Yes | The model to use for SVG generation \(e.g., "arrow-preview"\) | | ||
| | `instructions` | string | No | Style or formatting guidance for the SVG output | | ||
| | `references` | file | No | Reference images to guide SVG generation \(up to 4\) | | ||
| | `n` | number | No | Number of SVGs to generate \(1-16, default 1\) | | ||
| | `temperature` | number | No | Sampling temperature \(0-2, default 1\) | | ||
| | `top_p` | number | No | Nucleus sampling probability \(0-1, default 1\) | | ||
| | `max_output_tokens` | number | No | Maximum output tokens \(1-131072\) | | ||
| | `presence_penalty` | number | No | Token penalty for prior output \(-2 to 2, default 0\) | | ||
|
|
||
| #### Output | ||
|
|
||
| | Parameter | Type | Description | | ||
| | --------- | ---- | ----------- | | ||
| | `success` | boolean | Whether the SVG generation succeeded | | ||
| | `output` | object | Generated SVG output | | ||
| | ↳ `file` | file | Generated SVG file | | ||
| | ↳ `svgContent` | string | Raw SVG markup content | | ||
| | ↳ `id` | string | Generation request ID | | ||
| | ↳ `usage` | json | Token usage statistics | | ||
| | ↳ `totalTokens` | number | Total tokens used | | ||
| | ↳ `inputTokens` | number | Input tokens used | | ||
| | ↳ `outputTokens` | number | Output tokens used | | ||
|
|
||
| ### `quiver_image_to_svg` | ||
|
|
||
| Convert raster images into vector SVG format using QuiverAI | ||
|
|
||
| #### Input | ||
|
|
||
| | Parameter | Type | Required | Description | | ||
| | --------- | ---- | -------- | ----------- | | ||
| | `apiKey` | string | Yes | QuiverAI API key | | ||
| | `model` | string | Yes | The model to use for vectorization \(e.g., "arrow-preview"\) | | ||
| | `image` | file | Yes | The raster image to vectorize into SVG | | ||
| | `temperature` | number | No | Sampling temperature \(0-2, default 1\) | | ||
| | `top_p` | number | No | Nucleus sampling probability \(0-1, default 1\) | | ||
| | `max_output_tokens` | number | No | Maximum output tokens \(1-131072\) | | ||
| | `presence_penalty` | number | No | Token penalty for prior output \(-2 to 2, default 0\) | | ||
| | `auto_crop` | boolean | No | Automatically crop the image before vectorizing | | ||
| | `target_size` | number | No | Square resize target in pixels \(128-4096\) | | ||
|
|
||
| #### Output | ||
|
|
||
| | Parameter | Type | Description | | ||
| | --------- | ---- | ----------- | | ||
| | `success` | boolean | Whether the vectorization succeeded | | ||
| | `output` | object | Vectorized SVG output | | ||
| | ↳ `file` | file | Generated SVG file | | ||
| | ↳ `svgContent` | string | Raw SVG markup content | | ||
| | ↳ `id` | string | Vectorization request ID | | ||
| | ↳ `usage` | json | Token usage statistics | | ||
| | ↳ `totalTokens` | number | Total tokens used | | ||
| | ↳ `inputTokens` | number | Input tokens used | | ||
| | ↳ `outputTokens` | number | Output tokens used | | ||
|
|
||
| ### `quiver_list_models` | ||
|
|
||
| List all available QuiverAI models | ||
|
|
||
| #### Input | ||
|
|
||
| | Parameter | Type | Required | Description | | ||
| | --------- | ---- | -------- | ----------- | | ||
| | `apiKey` | string | Yes | QuiverAI API key | | ||
|
|
||
| #### Output | ||
|
|
||
| | Parameter | Type | Description | | ||
| | --------- | ---- | ----------- | | ||
| | `success` | boolean | Whether the request succeeded | | ||
| | `output` | object | Available models | | ||
| | ↳ `models` | json | List of available QuiverAI models | | ||
| | ↳ `id` | string | Model identifier | | ||
| | ↳ `name` | string | Human-readable model name | | ||
| | ↳ `description` | string | Model capabilities summary | | ||
| | ↳ `created` | number | Unix timestamp of creation | | ||
| | ↳ `ownedBy` | string | Organization that owns the model | | ||
| | ↳ `inputModalities` | json | Supported input types \(text, image, svg\) | | ||
| | ↳ `outputModalities` | json | Supported output types \(text, image, svg\) | | ||
| | ↳ `contextLength` | number | Maximum context window | | ||
| | ↳ `maxOutputLength` | number | Maximum generation length | | ||
| | ↳ `supportedOperations` | json | Available operations \(svg_generate, svg_edit, svg_animate, svg_vectorize, chat_completions\) | | ||
| | ↳ `supportedSamplingParameters` | json | Supported sampling parameters \(temperature, top_p, top_k, repetition_penalty, presence_penalty, stop\) | | ||
|
|
||
|
|
This file contains hidden or 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 hidden or 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 hidden or 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,141 @@ | ||
| import { createLogger } from '@sim/logger' | ||
| import { type NextRequest, NextResponse } from 'next/server' | ||
| import { z } from 'zod' | ||
| import { checkInternalAuth } from '@/lib/auth/hybrid' | ||
| import { generateRequestId } from '@/lib/core/utils/request' | ||
| import { FileInputSchema, type RawFileInput } from '@/lib/uploads/utils/file-schemas' | ||
| import { processFilesToUserFiles } from '@/lib/uploads/utils/file-utils' | ||
| import { downloadFileFromStorage } from '@/lib/uploads/utils/file-utils.server' | ||
|
|
||
| const logger = createLogger('QuiverImageToSvgAPI') | ||
|
|
||
| const RequestSchema = z.object({ | ||
| apiKey: z.string().min(1), | ||
| model: z.string().min(1), | ||
| image: z.union([FileInputSchema, z.string()]), | ||
| temperature: z.number().min(0).max(2).optional().nullable(), | ||
| top_p: z.number().min(0).max(1).optional().nullable(), | ||
| max_output_tokens: z.number().int().min(1).max(131072).optional().nullable(), | ||
| presence_penalty: z.number().min(-2).max(2).optional().nullable(), | ||
| auto_crop: z.boolean().optional().nullable(), | ||
| target_size: z.number().int().min(128).max(4096).optional().nullable(), | ||
| }) | ||
|
|
||
| export async function POST(request: NextRequest) { | ||
| const requestId = generateRequestId() | ||
|
|
||
| const authResult = await checkInternalAuth(request, { requireWorkflowId: false }) | ||
| if (!authResult.success) { | ||
| return NextResponse.json({ success: false, error: 'Unauthorized' }, { status: 401 }) | ||
| } | ||
|
|
||
| try { | ||
| const body = await request.json() | ||
| const data = RequestSchema.parse(body) | ||
|
|
||
| let apiImage: { url: string } | { base64: string } | ||
|
|
||
| if (typeof data.image === 'string') { | ||
| try { | ||
| const parsed = JSON.parse(data.image) | ||
| if (parsed && typeof parsed === 'object') { | ||
| const userFiles = processFilesToUserFiles([parsed as RawFileInput], requestId, logger) | ||
| if (userFiles.length > 0) { | ||
| const buffer = await downloadFileFromStorage(userFiles[0], requestId, logger) | ||
| apiImage = { base64: buffer.toString('base64') } | ||
| } else { | ||
| return NextResponse.json( | ||
| { success: false, error: 'Invalid file input' }, | ||
| { status: 400 } | ||
| ) | ||
| } | ||
| } else { | ||
| apiImage = { url: data.image } | ||
| } | ||
| } catch { | ||
| apiImage = { url: data.image } | ||
| } | ||
| } else if (typeof data.image === 'object' && data.image !== null) { | ||
| const userFiles = processFilesToUserFiles([data.image as RawFileInput], requestId, logger) | ||
| if (userFiles.length > 0) { | ||
| const buffer = await downloadFileFromStorage(userFiles[0], requestId, logger) | ||
| apiImage = { base64: buffer.toString('base64') } | ||
| } else { | ||
| return NextResponse.json({ success: false, error: 'Invalid file input' }, { status: 400 }) | ||
| } | ||
| } else { | ||
| return NextResponse.json({ success: false, error: 'Image is required' }, { status: 400 }) | ||
| } | ||
|
|
||
| const apiBody: Record<string, unknown> = { | ||
| model: data.model, | ||
| image: apiImage, | ||
| } | ||
|
|
||
| if (data.temperature != null) apiBody.temperature = data.temperature | ||
| if (data.top_p != null) apiBody.top_p = data.top_p | ||
| if (data.max_output_tokens != null) apiBody.max_output_tokens = data.max_output_tokens | ||
| if (data.presence_penalty != null) apiBody.presence_penalty = data.presence_penalty | ||
| if (data.auto_crop != null) apiBody.auto_crop = data.auto_crop | ||
| if (data.target_size != null) apiBody.target_size = data.target_size | ||
|
|
||
| logger.info(`[${requestId}] Calling Quiver vectorization API with model: ${data.model}`) | ||
|
|
||
| const response = await fetch('https://api.quiver.ai/v1/svgs/vectorizations', { | ||
| method: 'POST', | ||
| headers: { | ||
| 'Content-Type': 'application/json', | ||
| Authorization: `Bearer ${data.apiKey}`, | ||
| }, | ||
| body: JSON.stringify(apiBody), | ||
| }) | ||
|
|
||
| if (!response.ok) { | ||
| const errorText = await response.text() | ||
| logger.error(`[${requestId}] Quiver API error: ${response.status} - ${errorText}`) | ||
| return NextResponse.json( | ||
| { success: false, error: `Quiver API error: ${response.status} - ${errorText}` }, | ||
| { status: response.status } | ||
| ) | ||
| } | ||
|
|
||
| const result = await response.json() | ||
|
|
||
| if (!result.data || result.data.length === 0) { | ||
| return NextResponse.json( | ||
| { success: false, error: 'No SVG data returned from Quiver API' }, | ||
| { status: 500 } | ||
| ) | ||
| } | ||
|
|
||
| const svgContent = result.data[0].svg | ||
| const svgBuffer = Buffer.from(svgContent, 'utf-8') | ||
| const file = { | ||
| name: 'vectorized.svg', | ||
| mimeType: 'image/svg+xml', | ||
| data: svgBuffer.toString('base64'), | ||
| size: svgBuffer.length, | ||
| } | ||
|
|
||
| return NextResponse.json({ | ||
| success: true, | ||
| output: { | ||
| file, | ||
| files: [file], | ||
| svgContent, | ||
| id: result.id ?? null, | ||
| usage: result.usage | ||
| ? { | ||
| totalTokens: result.usage.total_tokens ?? 0, | ||
| inputTokens: result.usage.input_tokens ?? 0, | ||
| outputTokens: result.usage.output_tokens ?? 0, | ||
| } | ||
| : null, | ||
| }, | ||
| }) | ||
| } catch (error) { | ||
| logger.error(`[${requestId}] Error in Quiver image-to-svg:`, error) | ||
| const message = error instanceof Error ? error.message : 'Unknown error' | ||
| return NextResponse.json({ success: false, error: message }, { status: 500 }) | ||
| } | ||
| } | ||
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.