Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

返回的图片url无法下载保存 #148

Open
fouvy opened this issue Sep 29, 2024 · 1 comment
Open

返回的图片url无法下载保存 #148

fouvy opened this issue Sep 29, 2024 · 1 comment

Comments

@fouvy
Copy link

fouvy commented Sep 29, 2024

代码如下:

import requests

def chat_with_gpt(prompt,img_url):
    api_key = "your api key"
    model = "gpt-4o"
    url = "http://127.0.0.1:5005/v1/chat/completions"
    headers = {
        "Authorization": f"Bearer {api_key}",
        "Content-Type": "application/json"
    }
    data = {
        "model": model,
        "messages": [
            {
                "role": "user",
                "content": [
                    {
                        "type": "image_url",
                        "image_url": {
                            "url":img_url
                        }
                    }
                ]
            },
            {
                "role": "system",
                "content": [
                    {
                        "type": "text",
                        "text": prompt
                    }
                ]
            } 
        ]
    }
    
    response = requests.post(url, headers=headers, json=data)
    
    if response.status_code == 200:
        response_data = response.json()
        return response_data['choices'][0]['message']['content']
 
    else:
        return f"Error: {response.status_code}, {response.text}"

def test1():
    img_url="https://dashscope.oss-cn-beijing.aliyuncs.com/images/dog_and_girl.jpeg"
    prompt="帮我画一张类似的2D图片"
    response = chat_with_gpt(prompt,img_url) 
    print(response)

if __name__=="__main__":
    test1()

返回的结果:

json
{
  "size": "1024x1024",
  "prompt": "A 2D illustration of a person sitting on the beach playing with a large dog. The person is sitting cross-legged, smiling and wearing a checkered shirt, while the dog, a large breed with a light-colored coat, sits facing the person, raising its paw to gently touch the person's hand. The beach scene has a peaceful, sunset atmosphere, with soft ocean waves and a golden glow in the background. The illustration should have a playful and warm feeling, capturing the bond between the person and the dog."
}
![image](https://files.oaiusercontent.com/file-TBq8puVoBqTltH0Bk47jI8tA?se=2024-09-29T10%3A28%3A37Z&sp=r&sv=2024-08-04&sr=b&rscc=max-age%3D604800%2C%20immutable%2C%20private&rscd=attachment%3B%20filename%3D98dd12de-9b04-4d09-b7ec-a3d7759c94e7.webp&sig=UKGxaKm9pN/ro8n8ks5ihU9OEzZTeYcPTnSHtBjBG04%3D)
Here is the 2D illustration based on your request! Let me know if you need any adjustments.

上面的image后面的url地址的图片如何下载?我直接把前面的https://files.oaiusercontent.com改成http://127.0.0.1:5005也无法下载。

@fouvy fouvy mentioned this issue Sep 29, 2024
@fouvy
Copy link
Author

fouvy commented Oct 5, 2024

已经解决

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant