Skip to content

feat: add safe repr implementations for watsonx and litellm backends - #1359

Merged
AngeloDanducci merged 3 commits into
generative-computing:mainfrom
cptnm3:feat/add-repr-and-str
Jul 7, 2026
Merged

AngeloDanducci merged 3 commits into
generative-computing:mainfrom
cptnm3:feat/add-repr-and-str

Conversation

@cptnm3

@cptnm3 cptnm3 commented Jun 30, 2026 •

Copy link
Copy Markdown
Contributor

Pull Request

Issue

Fixes #1317

Description

Added __repr__ and __str__ to show useful information with masked api_key

Testing

  • Tests added to the respective file if code was changed
  • New code has 100% coverage if code was added
  • Ensure existing tests and github automation passes (a maintainer will kick off the github automation when the rest of the PR is populated)

Attribution

  • AI coding assistants used

Adding a new component, requirement, sampling strategy, or tool?

If your PR adds or modifies one of the types below, check the matching box. A checklist of type-specific review items will be posted as a comment.

  • Component
  • Requirement
  • Sampling Strategy
  • Tool

NOTE: Please ensure you have an issue that has been acknowledged by a core contributor and routed you to open a pull request against this repository. Otherwise, please open an issue before continuing with this pull request.

Added __repr__ and __str__ to show useful information with masked api_key

Closes generative-computing#1317

Signed-off-by: Vishal V <[email protected]>
@cptnm3
cptnm3 requested a review from a team as a code owner June 30, 2026 15:32
@github-actions github-actions Bot added the enhancement New feature or request label Jun 30, 2026
@psschwei

Copy link
Copy Markdown
Contributor

@cptnm3 thanks for the PR! If you don't mind, could you leave a comment on the issue so we can assign it to you?

@cptnm3

cptnm3 commented Jun 30, 2026

Copy link
Copy Markdown
Contributor Author

Done @psschwei . Sorry, in the contribution guidelines I did not see that I have to be assigned to an issue before working on it. Will keep in mind next time. Thanks!

@psschwei

Copy link
Copy Markdown
Contributor

no worries!

@AngeloDanducci AngeloDanducci left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Thanks for the contribution, @cptnm3! The implementation looks good overall and follows the existing OpenAIBackend pattern nicely.

I've left a few inline comments with some requested changes — mostly moving and mocking some of the tests, and a couple of small test improvements. Once those are addressed this should be good to go.

Comment thread mellea/backends/litellm.py Resolved
Comment thread test/backends/test_litellm_ollama.py Resolved
Comment thread test/backends/test_watsonx.py Resolved
Comment thread test/backends/test_watsonx.py Resolved
Comment thread test/backends/test_watsonx.py Resolved
Comment thread test/backends/test_watsonx.py Resolved
Watsonx repr tests moved to test_watsonx_repr.py — plain unit tests,
no e2e/require_api_key markers. Fix inverted assertions in
test_repr_no_key_shows_none; add test_repr_env_key_is_masked for
env-resolved key path. Use _make_backend helper + mock Credentials
to avoid real SDK init.

LiteLLM repr test moved to test_litellm_repr.py. Add
test_repr_omits_default_base_url and test_str_shows_model_id_and_base_url.
Fix LiteLLMBackend.__repr__ to show base_url=None when caller omitted it.

Signed-off-by: Vishal V <[email protected]>
@cptnm3

cptnm3 commented Jul 2, 2026

Copy link
Copy Markdown
Contributor Author

Hi @AngeloDanducci. thanks for the review. I have made the suggested changes. Please take a look and let me know in case I have missed anything else

@cptnm3
cptnm3 requested a review from AngeloDanducci July 3, 2026 06:13

@AngeloDanducci AngeloDanducci left a comment •

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Thanks for the update - fixes all of the review feedback. Just need to move the new test file. Currently it's outside of the pytest testpaths so it won't run.

Once you move mellea/backends/test_litellm_repr.py to test/backends/test_litellm_repr.py it should be good to go.

@cptnm3

cptnm3 commented Jul 6, 2026

Copy link
Copy Markdown
Contributor Author

@AngeloDanducci thanks for catching that! it was an oversight on my end. Please take a look now.

@cptnm3
cptnm3 requested a review from AngeloDanducci July 6, 2026 21:10
@AngeloDanducci
AngeloDanducci enabled auto-merge July 7, 2026 07:03

@AngeloDanducci AngeloDanducci left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

LGTM 🎉

@AngeloDanducci
AngeloDanducci added this pull request to the merge queue Jul 7, 2026
@github-merge-queue
github-merge-queue Bot removed this pull request from the merge queue due to failed status checks Jul 7, 2026
@AngeloDanducci
AngeloDanducci added this pull request to the merge queue Jul 7, 2026
Merged via the queue into generative-computing:main with commit 7a4f934 Jul 7, 2026
9 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

feat: add safe __repr__ to WatsonxBackend and LiteLLMBackend

3 participants