caikit / caikit/caikit

Enum initialization bug

Open
#259 0 comments 0 reactions 0 assignees View on GitHub
bug
Dominant language
Python
Stars
114
Forks
70
PR merge metrics
No merged PRs in 30d

Description

## Describe the bug

There needs to be updates to `from_proto` and/or initialization for enums, in addition to what was added to `to_proto` in https://github.com/caikit/caikit/pull/95

## Sample Code

Currently an example with the `stop_reason` (an enum), when initialized with the Python enum, rather than the value (int), does not have equivalent attributes after to and from proto-ing, i.e.
```
dummy_generated_response = dm.GeneratedResult(
generated_token_count=2, text="foo bar", stop_reason=dm.StopReason.TIME_LIMIT
)

new = dm.GeneratedResult.from_proto(dummy_generated_response.to_proto())
assert new.stop_reason == dm.StopReason.TIME_LIMIT.value # works
assert new.stop_reason == dummy_generated_response.stop_reason.value # works
assert new.stop_reason == dummy_generated_response.stop_reason # fails
```

With a value (int) initialized, the attributes are as expected:
```
dummy_generated_response = dm.GeneratedResult(
generated_token_count=2, text="foo bar", stop_reason=dm.StopReason.TIME_LIMIT.value
)
new = dm.GeneratedResult.from_proto(dummy_generated_response.to_proto())
assert new.stop_reason == dm.StopReason.TIME_LIMIT.value # works
assert new.stop_reason == dummy_generated_response.stop_reason # works
```

## Expected behavior

Attribute access should be consistent i.e.
```
assert new.stop_reason == dummy_generated_response.stop_reason
```

## Observed behavior

Failure for the above when object is initialized with enum

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.