Closed txmazing closed 5 months ago
Just like what you can do on official chat.openai.com gpt-4 model. however the responsed image link of this api is temporary which only available for 1 hour. You could download the image in 1 hour if you like the image
I mean the link that comes back in the response is not the download link. As far as I understand, it should be in the format https://chat.openai.com/backend-api/files/ + XXX + /download right? Do I have to process the link from the response myself, or am I doing it wrong in general?
import requests
url = "http://127.0.0.1:8080/v1/chat/completions"
headers = {
"Content-Type": "application/json",
}
data = {
"model": "gpt-4",
"messages": [{"role": "user", "content": "Generate a image of a cat."}],
}
response = requests.post(url, json=data, headers=headers)
print(response.text)
{
"id": "chatcmpl-QXlha2FBbmROaXhpZUFyZUF3ZXNvbWUK",
"object": "chat.completion",
"created": 0,
"model": "gpt-3.5-turbo-0301",
"usage": {
"prompt_tokens": 0,
"completion_tokens": 0,
"total_tokens": 0
},
"choices": [
{
"index": 0,
"message": {
"role": "assistant",
"content": "[![image](https://files.oaiusercontent.com/file-0msXrS23met8tIqLWGkqbrVP?se=2024-03-25T09%3A35%3A01Z&sp=r&sv=2021-08-06&sr=b&rscc=max-age%3D31536000%2C%20immutable&rscd=attachment%3B%20filename%3D1345b9e6-11a5-4d14-aa6d-29c01ecf0f62.webp&sig=OT0aK/0/PVlzkdg64f9T3SA0jl3cWgFwWbDerHB74Gg%3D \"A fluffy orange tabby cat sitting gracefully on a soft cushion, its bright green eyes looking curiously at the viewer. The room is warmly lit, with soft shadows creating a cozy atmosphere. The cat's fur is detailed, showing a variety of orange and white shades that give it a vibrant yet soft appearance. The background is simple, with a hint of furniture that suggests a comfortable living space, but the focus is clearly on the expressive face and relaxed posture of the cat.\")](https://files.oaiusercontent.com/file-0msXrS23met8tIqLWGkqbrVP?se=2024-03-25T09%3A35%3A01Z&sp=r&sv=2021-08-06&sr=b&rscc=max-age%3D31536000%2C%20immutable&rscd=attachment%3B%20filename%3D1345b9e6-11a5-4d14-aa6d-29c01ecf0f62.webp&sig=OT0aK/0/PVlzkdg64f9T3SA0jl3cWgFwWbDerHB74Gg%3D)Here's the image of a fluffy orange tabby cat sitting gracefully on a soft cushion. Its bright green eyes look curiously at you, creating a cozy and inviting atmosphere."
},
"finish_reason": null
}
]
}
https://chat.openai.com/backend-api/files/+XX is the api to get direct image link(files.oaiusercontent.com/file-XX) with accesstoken, which doesn't direct show image itself, so you can't return that api in response content...
Hi, I know: "no free support" ... but I don't understand the processing of images. Do I have to convert the received link from my "Create an image of X for me." into a download myself, or am I misunderstanding "GetImageSource"? If I see correctly, there is only an endpoint for ChatCompletion, none for image generation.