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

怎么上传本地文件呢?有没有大佬知道 #10

Closed
332123342 opened this issue Apr 11, 2024 · 5 comments
Closed

怎么上传本地文件呢?有没有大佬知道 #10

332123342 opened this issue Apr 11, 2024 · 5 comments

Comments

@332123342
Copy link

332123342 commented Apr 11, 2024

image 这里只能写url吗?
@Vinlic
Copy link
Member

Vinlic commented Apr 11, 2024

请将文件编码为base64提供在url位置,base64前面还需要提供数据头,比如上传jpg文件需要这样提供:
"url": "data:image/jpeg;base64,/9j/4AAQSkZJRgA..."
@332123342

@Vinlic Vinlic closed this as completed Apr 11, 2024
@332123342
Copy link
Author

目前的想到的办法是把本地文件先上传到github上,再去到url。。。

@332123342
Copy link
Author

请将文件编码为base64提供在url位置,base64前面还需要提供数据头,比如上传jpg文件需要这样提供: "url": "data:image/jpeg;base64,/9j/4AAQSkZJRgA..." @332123342

文件大小有几兆,这样有问题吗?

@Vinlic
Copy link
Member

Vinlic commented Apr 11, 2024

@332123342 没问题的,十几M的也传过

@332123342
Copy link
Author

332123342 commented Apr 12, 2024

@Vinlic

response = client.chat.completions.create(
    model="qwen",
    messages = [
        {
            "role": "user",
            "content": [
                {
                    "type": "file",
                    "file_url": {
                        "url": "data:text/plain;base64,aSBhbSBhIGdvb2QgYm95"
                    }
                },
                {
                    "type": "text",
                    "text": "上传的文档说了什么"
                }
            ]
        }
    ],
)

这样可以了,感谢🙏

update:
用base64上传的文档长度太长还是会报错。。。
image

@Vinlic Vinlic pinned this issue Apr 12, 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

2 participants