Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions config/prism.php
Original file line number Diff line number Diff line change
Expand Up @@ -61,5 +61,9 @@
'x_title' => env('OPENROUTER_SITE_X_TITLE', null),
],
],
'qwen' => [
'api_key' => env('QWEN_API_KEY', ''),
'url' => env('QWEN_URL', 'https://dashscope-intl.aliyuncs.com/api/v1'),
],
],
];
4 changes: 4 additions & 0 deletions docs/.vitepress/config.mts
Original file line number Diff line number Diff line change
Expand Up @@ -211,6 +211,10 @@ export default defineConfig({
text: "OpenRouter",
link: "/providers/openrouter",
},
{
text: "Qwen",
link: "/providers/qwen",
},
{
text: "Voyage AI",
link: "/providers/voyageai",
Expand Down
13 changes: 13 additions & 0 deletions docs/components/ProviderSupport.vue
Original file line number Diff line number Diff line change
Expand Up @@ -341,6 +341,19 @@ export default {
documents: Supported,
moderation: Supported,
},
{
name: "Qwen",
text: Supported,
streaming: Supported,
structured: Supported,
embeddings: Supported,
image: Supported,
"speech-to-text": Unsupported,
"text-to-speech": Unsupported,
tools: Supported,
documents: Unsupported,
moderation: Unsupported,
},
{
name: "VoyageAI",
text: Unsupported,
Expand Down
76 changes: 75 additions & 1 deletion docs/core-concepts/image-generation.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ Currently, Prism supports image generation through:

- **OpenAI**: DALL-E 2, DALL-E 3, and GPT-Image-1 models
- **Gemini**: Gemini 2.0 Flash Preview Image Generation, Imagen 4, Imagen 3
- **Qwen**: Qwen-Image (generation), Qwen-Image-Edit (editing & multi-image fusion)

Additional providers will be added in future releases as the ecosystem evolves.

Expand Down Expand Up @@ -250,6 +251,79 @@ $response = Prism::image()
->generate();
```

### Qwen Options

#### Image Generation

Qwen provides image generation through `qwen-image-max` and `qwen-image-plus` models:

```php
$response = Prism::image()
->using(Provider::Qwen, 'qwen-image-max')
->withPrompt('A cute baby sea otter floating on its back')
->withProviderOptions([
'size' => '1328*1328', // Image resolution (width*height)
'negative_prompt' => 'low quality, blurry', // Content to avoid
'prompt_extend' => true, // Enable prompt rewriting
'watermark' => false, // Disable watermark
'seed' => 42, // Random seed for reproducibility
])
->generate();
```

> [!IMPORTANT]
> Generated image URLs are valid for **24 hours** only. Download and save images promptly.

#### Image Editing

Qwen's `qwen-image-edit-max` and `qwen-image-edit-plus` models support single-image editing and multi-image fusion. Pass your images as the second parameter to `withPrompt()`:

```php
use Prism\Prism\ValueObjects\Media\Image;

$response = Prism::image()
->using(Provider::Qwen, 'qwen-image-edit-max')
->withPrompt('Generate an image following this depth map: a red bicycle on a muddy path with dense forest', [
Image::fromUrl('https://example.com/depth-map.png'),
])
->withProviderOptions([
'n' => 2, // Output 1-6 images (max/plus models)
'size' => '1536*1024', // Custom output resolution
'negative_prompt' => 'low quality', // Content to avoid
'prompt_extend' => true, // Enable prompt rewriting
'watermark' => false, // Disable watermark
])
->generate();
```

For multi-image fusion, pass multiple images — the model can combine elements from up to 3 input images:

```php
$response = Prism::image()
->using(Provider::Qwen, 'qwen-image-edit-max')
->withPrompt('The girl in image 1 wearing the black dress from image 2, sitting in the pose of image 3', [
Image::fromUrl('https://example.com/person.png'),
Image::fromUrl('https://example.com/dress.png'),
Image::fromUrl('https://example.com/pose.png'),
])
->withProviderOptions([
'n' => 2,
'size' => '1024*1536',
])
->generate();
```

You can also pass images from local files or base64 data:

```php
$response = Prism::image()
->using(Provider::Qwen, 'qwen-image-edit-max')
->withPrompt('Add a sunset sky to the background', [
Image::fromLocalPath('/path/to/photo.png'),
])
->generate();
```

## Testing

Prism provides convenient fakes for testing image generation:
Expand All @@ -272,4 +346,4 @@ test('can generate images', function () {
});
```

Need help with a specific provider or use case? Check the [openai documentation](/providers/openai) or [gemini documentation](/providers/gemini) for detailed configuration options and examples.
Need help with a specific provider or use case? Check the [openai documentation](/providers/openai), [gemini documentation](/providers/gemini), or [qwen documentation](/providers/qwen) for detailed configuration options and examples.
24 changes: 24 additions & 0 deletions docs/core-concepts/structured-output.md
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,30 @@ $response = Prism::structured()
// ... rest of your configuration
```

### Qwen: JSON Schema Mode
Qwen supports two modes for structured output through DashScope's `response_format` parameter:

- **JSON Object mode** (default): Ensures valid JSON output. Supported by most Qwen models.
- **JSON Schema mode**: Strictly enforces the schema structure. Supported by `qwen3-max`, `qwen-plus`, `qwen-flash` series and later models.

To use JSON Schema mode for strict schema validation:

```php
use Prism\Prism\Facades\Prism;
use Prism\Prism\Enums\Provider;
use Prism\Prism\Enums\StructuredMode;

$response = Prism::structured()
->using(Provider::Qwen, 'qwen-plus')
->usingStructuredMode(StructuredMode::Structured)
->withSchema($schema)
->withPrompt('Extract user information')
->asStructured();
```

> [!NOTE]
> JSON Schema mode is only supported by newer models. If you use a model that does not support it, use the default JSON Object mode (or `StructuredMode::Auto`) instead. Check the [Qwen structured output documentation](https://www.alibabacloud.com/help/en/model-studio/qwen-structured-output) for the full list of supported models.

### Anthropic: Tool Calling Mode
Anthropic doesn't have native structured output, but Prism provides two approaches. For more reliable JSON parsing, especially with complex content or non-English text, use tool calling mode:

Expand Down
13 changes: 13 additions & 0 deletions docs/core-concepts/text-generation.md
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,19 @@ $response = Prism::text()
]
)
->asText();

// Multi-image analysis with Qwen VL models
$response = Prism::text()
->using(Provider::Qwen, 'qwen-vl-max')
->withPrompt(
'What are these?',
[
Image::fromUrl('https://example.com/dog.jpeg'),
Image::fromUrl('https://example.com/tiger.png'),
Image::fromUrl('https://example.com/rabbit.png'),
]
)
->asText();
```

## Message Chains and Conversations
Expand Down
1 change: 1 addition & 0 deletions docs/getting-started/introduction.md
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,7 @@ We currently offer first-party support for these leading AI providers:
- [Mistral](/providers/mistral.md)
- [Ollama](/providers/ollama.md)
- [OpenAI](/providers/openai.md)
- [Qwen](/providers/qwen.md)
- [xAI](/providers/xai.md)

Each provider brings its own strengths to the table, and Prism makes it easy to use them all through a consistent, elegant interface.
Expand Down
Loading