Closed yuexdang closed 1 year ago
有方法解决了没,大佬,同样卡这了
describe 这个比较麻烦,因为它的的确确是需要我传入一个图片参数的,替代方法就是载入一个I2T(image to text)的数据库做图片描述,但是很耗时间,我觉得体验挺差的
这个方法可能不太行,midjourney使用describe方法时应该是基于他的模型以及Tag词库,如果引入三方数据库可能会导致数据识别差距比较大,达不到原有效果
https://midjourney-by-api.gitbook.io/midjourney-api/midjourney-api/describe
import requests
url = "YOUR_API_BASE_URL/describe"
payload = {} files=[ ('image',('my-cool-image.jpg',open('/xxxx/images/my-cool-image.jpg','rb'),'image/jpeg')) ] headers = { 'Authorization': 'YOUR_API_KEY' }
response = requests.request("POST", url, headers=headers, data=payload, files=files)
print(response.text)
不太清楚是否有用= =不熟悉后端
https://midjourney-by-api.gitbook.io/midjourney-api/midjourney-api/describe
import requests
url = "YOUR_API_BASE_URL/describe"
payload = {} files=[ ('image',('my-cool-image.jpg',open('/xxxx/images/my-cool-image.jpg','rb'),'image/jpeg')) ] headers = { 'Authorization': 'YOUR_API_KEY' }
response = requests.request("POST", url, headers=headers, data=payload, files=files)
print(response.text)
这个可以作为临时的方法,但是使用的仍然是三方接口(需要注册MidjourneyAPI,而且在他的声明中,他和midjourney Inc. 没有任何关系),我觉得存在一定的风险(比如泄露自己的账号),而且它还会限制我的消息发送速率(笑 我想直接面向discord,保证数据的流程清晰透明,毕竟没有人希望自己运行代码后还需要进入别人的数据库里走一圈,沾染一些不该沾染的东西。同时这也符合我们做这个库的初衷
上传文件这个思路我觉得没有什么问题,应该是可以实现这个效果的,因为有一个Go版本的通过这样的方法实现了目标,等后面有时间会尝试这些方法
同时我还找到了一个好东西,他们(MidjourneyAPI)提供了Midjourney的黑名单词汇,这个也很重要
我正在做一个尝试,但是不清楚nonce在哪里获取,填入空值得时候,服务器总会报错code 500,请问大佬有没有什么思路
def Describe(self, attachment:object, filename : str, size : int):
"""
用于图片描述
"""
api_response = requests.post(
f"https://discord.com/api/v9/channels/" + self.CHANNEL_ID + "/attachments",
headers=self.header,
json={"files": [{"filename": filename, "file_size": size, "id": 0}]},
)
# api_response.raise_for_status()
attachment_info = api_response.json()["attachments"][0]
put_url = attachment_info["upload_filename"]
attachments = {"id":0, "filename": filename, "uploaded_filename": put_url}
attch_list = [attachments]
__payload = JsonDescribe(self.MID_JOURNEY_ID, self.SERVER_ID, self.CHANNEL_ID, attch_list)
response = self.DescribeTest(json=__payload)
return response
我正在做一个尝试,但是不清楚nonce在哪里获取,填入空值得时候,服务器总会报错code 500,请问大佬有没有什么思路
是的,之前我也写过这个转存的方法,但是要注意的是,你的这个流程没有闭合
它的步骤应该是这样的
authorization: vipTOKEN
身份向 url = https://discord.com/api/v9/channels/ChannelID/attachments 发送POST请求,这时Discord会开辟一个图片转存的空间,用于转存用户上传的图片,也就是 "upload_url"参数authority: discord-attachments-uploads-prd.storage.googleapis.com
身份向 upload_url
(.discord.storage.google.api) 发送 OPTIONS 请求,服务器会204,并调整 method_allowed 为 PUT,这个请求必须有path: upload_url.replace("https://discord-attachments-uploads-prd.storage.googleapis.com","")
authority: discord-attachments-uploads-prd.storage.googleapis.com
身份向相同的链接 发送 PUT 请求,上传转存图片,服务器 200,问题就出在这里,没有明白google.api的图片传输方式,解码后的文件流很奇怪现在还没成功,打算有空再试试,不行就换一个别的思路
值得注意的是,这个方法在理论上是可以实现效果的,现在是文件以什么格式传输进入googleapi成为了问题,访问转存路由会显示不支持的图片格式,应该是转码的问题
nonce
nonce这个值,不需要去获取,在我的理解中,它像是每个请求的ID之类的,不传输这个值不会造成任何影响
nonce
nonce这个值,不需要去获取,在我的理解中,它像是每个请求的ID之类的,不传输这个值不会造成任何影响
这个我确认了一下,可以填空,的确没什么用
我正在做一个尝试,但是不清楚nonce在哪里获取,填入空值得时候,服务器总会报错code 500,请问大佬有没有什么思路
是的,之前我也写过这个转存的方法,但是要注意的是,你的这个流程没有闭合
它的步骤应该是这样的
- 以
authorization: vipTOKEN
身份向 url = https://discord.com/api/v9/channels/ChannelID/attachments 发送POST请求,这时Discord会开辟一个图片转存的空间,用于转存用户上传的图片,也就是 "upload_url"参数- 以
authority: discord-attachments-uploads-prd.storage.googleapis.com
身份向upload_url
(.discord.storage.google.api) 发送 OPTIONS 请求,服务器会204,并调整 method_allowed 为 PUT,这个请求必须有path: upload_url.replace("https://discord-attachments-uploads-prd.storage.googleapis.com","")
- 以
authority: discord-attachments-uploads-prd.storage.googleapis.com
身份向相同的链接 发送 PUT 请求,上传转存图片,服务器 200,问题就出在这里,没有明白google.api的图片传输方式,解码后的文件流很奇怪- 最后调用第一步上传的filename和返回的uploaded_filename即可
现在还没成功,打算有空再试试,不行就换一个别的思路
值得注意的是,这个方法在理论上是可以实现效果的,现在是文件以什么格式传输进入googleapi成为了问题,访问转存路由会显示不支持的图片格式,应该是转码的问题
感谢帮助,我去试一下,今天有空也会去试一下文件上传的方式
https://midjourney-by-api.gitbook.io/midjourney-api/midjourney-api/describe import requests url = "YOUR_API_BASE_URL/describe" payload = {} files=[ ('image',('my-cool-image.jpg',open('/xxxx/images/my-cool-image.jpg','rb'),'image/jpeg')) ] headers = { 'Authorization': 'YOUR_API_KEY' } response = requests.request("POST", url, headers=headers, data=payload, files=files) print(response.text)
这个可以作为临时的方法,但是使用的仍然是三方接口(需要注册MidjourneyAPI,而且在他的声明中,他和midjourney Inc. 没有任何关系),我觉得存在一定的风险(比如泄露自己的账号),而且它还会限制我的消息发送速率(笑 我想直接面向discord,保证数据的流程清晰透明,毕竟没有人希望自己运行代码后还需要进入别人的数据库里走一圈,沾染一些不该沾染的东西。同时这也符合我们做这个库的初衷
上传文件这个思路我觉得没有什么问题,应该是可以实现这个效果的,因为有一个Go版本的通过这样的方法实现了目标,等后面有时间会尝试这些方法
同时我还找到了一个好东西,他们(MidjourneyAPI)提供了Midjourney的黑名单词汇,这个也很重要
请问那个go的项目能分享下地址吗,我去学习一下
https://midjourney-by-api.gitbook.io/midjourney-api/midjourney-api/describe import requests url = "YOUR_API_BASE_URL/describe" payload = {} files=[ ('image',('my-cool-image.jpg',open('/xxxx/images/my-cool-image.jpg','rb'),'image/jpeg')) ] headers = { 'Authorization': 'YOUR_API_KEY' } response = requests.request("POST", url, headers=headers, data=payload, files=files) print(response.text)
这个可以作为临时的方法,但是使用的仍然是三方接口(需要注册MidjourneyAPI,而且在他的声明中,他和midjourney Inc. 没有任何关系),我觉得存在一定的风险(比如泄露自己的账号),而且它还会限制我的消息发送速率(笑 我想直接面向discord,保证数据的流程清晰透明,毕竟没有人希望自己运行代码后还需要进入别人的数据库里走一圈,沾染一些不该沾染的东西。同时这也符合我们做这个库的初衷 上传文件这个思路我觉得没有什么问题,应该是可以实现这个效果的,因为有一个Go版本的通过这样的方法实现了目标,等后面有时间会尝试这些方法 同时我还找到了一个好东西,他们(MidjourneyAPI)提供了Midjourney的黑名单词汇,这个也很重要
请问那个go的项目能分享下地址吗,我去学习一下
我正在做一个尝试,但是不清楚nonce在哪里获取,填入空值得时候,服务器总会报错code 500,请问大佬有没有什么思路
是的,之前我也写过这个转存的方法,但是要注意的是,你的这个流程没有闭合
它的步骤应该是这样的
- 以
authorization: vipTOKEN
身份向 url = https://discord.com/api/v9/channels/ChannelID/attachments 发送POST请求,这时Discord会开辟一个图片转存的空间,用于转存用户上传的图片,也就是 "upload_url"参数- 以
authority: discord-attachments-uploads-prd.storage.googleapis.com
身份向upload_url
(.discord.storage.google.api) 发送 OPTIONS 请求,服务器会204,并调整 method_allowed 为 PUT,这个请求必须有path: upload_url.replace("https://discord-attachments-uploads-prd.storage.googleapis.com","")
- 以
authority: discord-attachments-uploads-prd.storage.googleapis.com
身份向相同的链接 发送 PUT 请求,上传转存图片,服务器 200,问题就出在这里,没有明白google.api的图片传输方式,解码后的文件流很奇怪- 最后调用第一步上传的filename和返回的uploaded_filename即可
现在还没成功,打算有空再试试,不行就换一个别的思路
值得注意的是,这个方法在理论上是可以实现效果的,现在是文件以什么格式传输进入googleapi成为了问题,访问转存路由会显示不支持的图片格式,应该是转码的问题
test1 = requests.options(put_url, headers={"authority":"discord-attachments-uploads-prd.storage.googleapis.com", "path":filename1}) print(test1.status_code) req = requests.put(put_url, headers={"authority":"discord-attachments-uploads-prd.storage.googleapis.com"}) print(req.status_code) 我按照这个方式改了下,但是服务器一直回405...
def Describe(self, attachment:object, filename : str, size : int):
"""
用于图片描述
"""
#ERROR 500
api_response = requests.post(
f"https://discord.com/api/v9/channels/" + self.CHANNEL_ID + "/attachments",
headers=self.header,
json={"files": [{"filename": filename, "file_size": size, "id": 0}]},
)
# api_response.raise_for_status()
attachment_info = api_response.json()["attachments"][0]
put_url = attachment_info["upload_url"]
filename1 = attachment_info["upload_filename"]
realPath = attachment.__getattribute__("url")
test1 = requests.get(realPath, headers={"authority":"cdn.discordapp.com"})
req = requests.put(put_url,data=test1.content, headers={"authority":"discord-attachments-uploads-prd.storage.googleapis.com"})
attachments = {"id":0, "filename": filename, "uploaded_filename": filename1}
attch_list = [attachments]
__payload = JsonDescribe(self.MID_JOURNEY_ID, self.SERVER_ID, self.CHANNEL_ID, attch_list)
response = self.DescribeTest(json=__payload)
return response
能够正常使用Describe功能了,可以尝试下
def Describe(self, attachment:object, filename : str, size : int): """ 用于图片描述 """ #ERROR 500 api_response = requests.post( f"https://discord.com/api/v9/channels/" + self.CHANNEL_ID + "/attachments", headers=self.header, json={"files": [{"filename": filename, "file_size": size, "id": 0}]}, ) # api_response.raise_for_status() attachment_info = api_response.json()["attachments"][0] put_url = attachment_info["upload_url"] filename1 = attachment_info["upload_filename"] realPath = attachment.__getattribute__("url") test1 = requests.get(realPath, headers={"authority":"cdn.discordapp.com"}) req = requests.put(put_url,data=test1.content, headers={"authority":"discord-attachments-uploads-prd.storage.googleapis.com"}) attachments = {"id":0, "filename": filename, "uploaded_filename": filename1} attch_list = [attachments] __payload = JsonDescribe(self.MID_JOURNEY_ID, self.SERVER_ID, self.CHANNEL_ID, attch_list) response = self.DescribeTest(json=__payload) return response
能够正常使用Describe功能了,可以尝试下
已实现Blend与Describe的功能,感谢帮助,如果你不介意的话,将会在V2.0正式版发布时将你加入贡献者列表中
def Describe(self, attachment:object, filename : str, size : int): """ 用于图片描述 """ #ERROR 500 api_response = requests.post( f"https://discord.com/api/v9/channels/" + self.CHANNEL_ID + "/attachments", headers=self.header, json={"files": [{"filename": filename, "file_size": size, "id": 0}]}, ) # api_response.raise_for_status() attachment_info = api_response.json()["attachments"][0] put_url = attachment_info["upload_url"] filename1 = attachment_info["upload_filename"] realPath = attachment.__getattribute__("url") test1 = requests.get(realPath, headers={"authority":"cdn.discordapp.com"}) req = requests.put(put_url,data=test1.content, headers={"authority":"discord-attachments-uploads-prd.storage.googleapis.com"}) attachments = {"id":0, "filename": filename, "uploaded_filename": filename1} attch_list = [attachments] __payload = JsonDescribe(self.MID_JOURNEY_ID, self.SERVER_ID, self.CHANNEL_ID, attch_list) response = self.DescribeTest(json=__payload) return response
能够正常使用Describe功能了,可以尝试下
已实现Blend与Describe的功能,感谢帮助,如果你不介意的话,将会在V2.0正式版发布时将你加入贡献者列表中
那实在是太棒了哈哈哈~
@xxvcxxvc 你好,想请教一下,图片描述这个指令后续不能收到从midjourney bot转发到服务机器人的执行结果,在discord中只执行到midjourney bot执行成功了就结束了,请问你那边有好的解决方案吗
@xxvcxxvc 你好,想请教一下,图片描述这个指令后续不能收到从midjourney bot转发到服务机器人的执行结果,在discord中只执行到midjourney bot执行成功了就结束了,请问你那边有好的解决方案吗
暂时还没弄
新版本已发布,已支持blend 与 describe 同时解决了这两个命令无法追踪发送用户的问题
目前这两个在request传入的参数很特殊,因为带有附件,而且这个附件是关于CDN描述的。在ctx中被解码了,导致我拿不到discord POST发送的数据,现在有两个折中的方法
把上传的图片再去使用 discord.googleapi 转存一遍,拿到所需要的数据,从而完善request请求,这个不稳定,十次有两次会传回来一个无法访问的数据
寻找替代方法
大家如果有什么方法,比如能够通过 discord.py 拿到web发送的最原始的POST请求,都可以在下面进行交流(WebHook这个方法除外)