-
Notifications
You must be signed in to change notification settings - Fork 15
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
BAI-940 Create Helper Classes #891
Conversation
…/create-helper-classes
…hq/Bailo into BAI-940/create-helper-classes
res = requests.request(method, **kwargs) | ||
|
||
# Check response for a valid range | ||
if 200 <= res.status_code < 300: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This should be replaced with res.status_code < 400
.
return res | ||
|
||
# Give the error message issued by bailo | ||
raise BailoException(res.json()['error']['message']) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This won't exist if it's a network error, as opposed to an error from Bailo. E.g. if the connection is refused.
""" | ||
with self.agent.get(f"{self.url}/v2/model/{model_id}/file/{file_id}/download", stream=True) as r: | ||
if localfile_name is None: | ||
fp = tempfile.NamedTemporaryFile() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Our core client should probably not be saving things to file on disk. This should be moved out to the helper. A core client use case might be saving to S3 / another drive with more space.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
For now I'm just going to use ByteStreams that can be used within a context manager. This will also make them file compatible as well eg. if a user want's to download files
with open("example.txt", "wb") as f:
release.download(<file-id>, f)
return self.agent.post( | ||
f"{self.url}/v2/model/{model_id}/files/upload/simple", | ||
params={"name":name}, | ||
files={name: f} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
files
uses a multi-form file upload. This will return a 200, but I think the uploaded data will differ from the values you provide...? So you'll upload a file saying 'Hello', then get back a file like:
-----------------------------9051914041544843365972754266
Content-Disposition: form-data; name="name"
Hello
You'll instead want to use data.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Also, again, the core client shouldn't be reading from disk. See people uploading from Weights & Biases, S3, etc.
Model = 'model' | ||
Release = 'release' |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There is no Release
schema. The release fields are not configurable.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe review this reviews.py
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We don't need this anymore!
lib/python-beta/test.txt
Outdated
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Interesting file. I don't think we need this.
# Check they're the same access request | ||
assert ar == get_ar | ||
|
||
ar.delete() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do we want to check that this works?
lib/python-beta/tests/test_client.py
Outdated
@@ -96,10 +97,10 @@ def test_post_release(requests_mock): | |||
client = Client("https://example.com") | |||
result = client.post_release( | |||
model_id="test_id", | |||
model_card_version=1, | |||
model_card_version=1.0, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't think this should be a float!
No description provided.