首先感謝laf提供免費使用Midjourney API接口和云函數(shù),需要詳細(xì)了解的可以訪問他們的官網(wǎng)論壇。
感謝論壇前面幾位的分享,我做了參考。都有參考就不列啦哈?。?!
直接開始:
第一步
復(fù)制MJ-SEND云函數(shù)到laf云平臺,并發(fā)布獲得云函數(shù)訪問地址“https://xxx.laf.dev/mj-sent”
import cloud from '@lafjs/cloud'
import { Midjourney, MidjourneyMessage } from 'midjourney'
const SERVER_ID = '' // Midjourney 服務(wù) ID
const CHANNEL_ID = '' // Midjourney 頻道 ID
const SALAI_TOKEN = '' // Midjourney 服務(wù) Token
const Limit = 100
const MaxWait = 3
const client = new Midjourney({
ServerId: SERVER_ID,
ChannelId: CHANNEL_ID,
SalaiToken: SALAI_TOKEN,
Debug: true,
SessionId: SALAI_TOKEN,
Limit: Limit,
MaxWait: MaxWait
});
export default async function (ctx: FunctionContext) {
const { type, param } = ctx.body
switch (type) {
case 'RetrieveMessages':
return await RetrieveMessages(param)
case 'imagine':
return await imagine(param)
case 'upscale':
return await upscale(param)
case 'variation':
return await variation(param)
}
}
// 查詢最近消息
async function RetrieveMessages(param) {
console.log("RetrieveMessages")
const client = new MidjourneyMessage({
ChannelId: CHANNEL_ID,
SalaiToken: SALAI_TOKEN,
});
const msg = await client.RetrieveMessages();
console.log("RetrieveMessages success ", msg)
return msg
}
// 創(chuàng)建生圖任務(wù)
async function imagine(param) {
console.log("imagine", param)
const { question, msg_Id } = param
const msg = await client.Imagine(
`[${msg_Id}] ${question}`,
(uri: string, progress: string) => {
console.log("loading", uri, "progress", progress);
}
);
console.log("imagine success ", msg)
return true
}
// upscale 放大圖片
async function upscale(param) {
console.log("upscale", param)
const { question, index, id, url } = param
const hash = url.split("_").pop()?.split(".")[0] ?? ""
console.log(hash)
const msg = await client.Upscale(
question,
index,
id,
hash,
(uri: string, progress: string) => {
console.log("loading", uri, "progress", progress);
}
);
console.log("upscale success ", msg)
return msg
}
// variation 變換圖片
async function variation(param) {
console.log("variation", param)
const client = new Midjourney({
ServerId: SERVER_ID,
ChannelId: CHANNEL_ID,
SalaiToken: SALAI_TOKEN,
Debug: true,
SessionId: SALAI_TOKEN,
Limit: Limit,
MaxWait: 100
});
const { question, index, id, url } = param
const hash = url.split("_").pop()?.split(".")[0] ?? ""
const msg = await client.Variation(
question,
index,
id,
hash,
(uri: string, progress: string) => {
console.log("loading", uri, "progress", progress);
}
);
console.log("variation success ", msg)
return msg
}
第二步
?到我的huggingface空間復(fù)制到自己的服務(wù)器,查找“https://xxx.laf.dev/mj-sent”替換成你自己的云函數(shù)地址“
文章來源:http://www.zghlxwxcb.cn/news/detail-606008.html
3、五分鐘不到就可以免費擁有CHATGPT+Midjourney啦,加油?。∪ペA得AI第一桶金?。。?span toymoban-style="hidden">文章來源地址http://www.zghlxwxcb.cn/news/detail-606008.html
到了這里,關(guān)于五分鐘零基礎(chǔ)開發(fā)chatgpt+Midjourney工具贏得被動收入的文章就介紹完了。如果您還想了解更多內(nèi)容,請在右上角搜索TOY模板網(wǎng)以前的文章或繼續(xù)瀏覽下面的相關(guān)文章,希望大家以后多多支持TOY模板網(wǎng)!