图像
从文本生成图像
通常,纯 AI 音频服务不支持像工具和对话这样的完整代理能力。因此,你可以将这些组件作为代理工作流中的独立服务来使用,或者将它们放在 Agent 中使用,因为它们实现了 AIProviderInterface 接口。在这种情况下,你可以受益于代理工作流特性,如中间件和护栏。
这些组件有助于根据文本提示自动生成图像。
Nano Banana(Google)
Google Gemini API 提供完整的多模态体验,因此你只需在 Gemini 提供方中更改默认模型,即可根据提示生成图像。由于 Neuron 的多模态消息层和聊天历史管理,它还支持通过多轮对话对生成的图像进行迭代。
只需在 Google Gemini 提供方中配置一个图像生成模型:
namespace App\Neuron;
use NeuronAI\Agent\Agent;
use NeuronAI\Chat\Messages\UserMessage;
use NeuronAI\Providers\AIProviderInterface;
use NeuronAI\Providers\Gemini\Gemini;
class MyAgent extends Agent
{
protected function provider(): AIProviderInterface
{
return new Gemini(
key: 'GEMINI_API_KEY',
model: 'gemini-2.5-flash-image',
);
}
}
// 运行 Agent
$message = MyAgent::make()
->setThreadId('chat_id')
->chat(new UserMessage("生成一张举办最佳 PHP 会议的场地图片!"))
->getMessage();
// 获取消息中的图像部分(它是 base64 格式)
$imageBase64 = $message->getImage()->getContent();
// 保存图像
file_put_contents(__DIR__.'/assets/cover.png', base64_decode($imageBase64));OpenAI 图像
作为 Agent 提供者
直接使用
ZAI 图像
作为代理提供方
直接使用
最后更新于

