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

feat: support direct bytes for file upload #568

Merged
merged 3 commits into from
Nov 15, 2023

Conversation

floodfx
Copy link
Contributor

@floodfx floodfx commented Nov 13, 2023

Describe the change
CreateFile currently requires a "local" file which it reads from the filesystem and uploads. For various reasons, we require uploading bytes directly rather than relying on local filesystem.

Describe your solution
Add CreateFileBytes which takes a FileBytesRequest that allows directly passing a []byte. This reuses the exsting CreateFormFileReader passing a *bytes.Reader directly.

Tests
Added a test case to files_api_test.go. Also validated that it works in a separate app.

Copy link

codecov bot commented Nov 13, 2023

Codecov Report

All modified and coverable lines are covered by tests ✅

Comparison is base (515de02) 98.35% compared to head (5cb80f0) 98.38%.

Additional details and impacted files
@@            Coverage Diff             @@
##           master     #568      +/-   ##
==========================================
+ Coverage   98.35%   98.38%   +0.03%     
==========================================
  Files          24       24              
  Lines        1276     1300      +24     
==========================================
+ Hits         1255     1279      +24     
  Misses         15       15              
  Partials        6        6              

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

Copy link
Owner

@sashabaranov sashabaranov left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you so much!

@sashabaranov sashabaranov merged commit 71848cc into sashabaranov:master Nov 15, 2023
3 checks passed
maerlyn5 pushed a commit to prassoai/go-openai that referenced this pull request Nov 22, 2023
* feat: support direct bytes for file upload

* add test for errors

* add coverage
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

Successfully merging this pull request may close these issues.

2 participants