先聊几句日常。Flux模型开源以后,身边不少朋友又纷纷投入AI创作的大军,个个摩拳擦掌,立志成为数字时代的“梵高”。不过一个现实问题很快就浮现了——画着画着,灵感就枯竭了。过去,大家多半会打开素材网站,翻翻别人的作品找找感觉。可如今已是2024年,遇到bug我们找AI修复,缺乏灵感,自然也应当向AI求助。
那么,怎样才能不依赖大厂的AI服务,自己动手,利用开源的大语言模型(LLM)打造一个随时能激发灵感的AI小助手呢?
Ollama启动

当下要本地部署开源大语言模型,没装Ollama框架可就说不过去了。安装流程不算复杂,之前的文章已详细介绍过,这里就不再重复了。
基于Ollama本地部署Llama3指南!

安装完成后,打开PowerShell(Windows用户),输入一行命令:
ollama run gemma2:27b
至于其他模型是否兼容,我没有逐一测试,但至少gemma2对System Prompt的理解能力相当出色。下图就是运行后的界面效果。

待模型拉取完毕,接下来是关键的一步:利用Ollama的Modelfile功能创建一个新模型。具体方法是新建一个文件夹,在其中放置一个txt文件(例如modelfile.txt),将上图中的参数和System Prompt内容填入。当然,还有更多参数可调,为了简洁这里不再展开,感兴趣的朋友可以查阅之前的文章。
保存文件时注意文件名不要搞错,必须命名为modelfile.txt。

之后,在modelfile所在的文件夹中打开PowerShell,输入以下命令:
ollama create SDArt -f modelfile.txt
这里需要说明一下:SDArt是你新建模型的名字,可以自由替换;modelfile.txt是文件名和格式,也可根据实际情况调整。

一旦命令行中弹出“Success”的提示——说明创建成功了!而且这种创建方式并不会额外占用硬盘空间。
模型准备就绪,接下来就可以找第三方应用来测试了。我正在开发一款专为Ollama设计的应用,目前界面有些粗糙,尚未精心设计,但对话功能已经可以正常使用。

从对话表现来看,模型对提示词的理解能力相当不错。那么我们就用Flux模型搭配这组提示词,直接生成一张海报来验证效果:

正面提示词:text An underwater scene with dim lighting filtering through the surface, an ancient shipwreck partially buried in sand overgrown with seaweed and coral, a mysterious stone structure nearby with intricate carvings eroded by time, vibrant coral reefs teeming with colorful fish, starfish, sea urchins, and shells scattered on the seabed, a large grouper hiding in the shadow of the wreck, jellyfish drifting gracefully in the current, masterpiece, best quality, 4k, illustration style, atmospheric lighting, detailed textures.
另一组示例用于生成蝙蝠侠场景:
| 正面提示词:text A solitary Batman overlooking Gotham City from the night sky, in his iconic Batsuit, standing against a backdrop of the city's dark and Gothic architecture illuminated by the night lights, capturing the brooding atmosphere of Gotham City, masterpiece, high quality, detailed character, dramatic cityscape, atmospheric lighting, starry night sky, 4k resolution, illustration style, depth of field, superhero theme, expressive facial features, detailed Batsuit, iconic Gotham buildings, city lights, night ambiance, Batman's flying vehicle or grappling hook in use. |
