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

better singleton already made warnings #1088

Merged
merged 4 commits into from
Apr 23, 2024
Merged

Conversation

piotrm0
Copy link
Contributor

@piotrm0 piotrm0 commented Apr 18, 2024

Other details that are good to know but need not be announced:

  • Added a better warning message when creating an instance of a singleton class that was already made. For example:
from trulens_eval import OpenAI
from trulens_eval.feedback import Groundedness

g = Groundedness()
OpenAI(client=..., something=42)

Will print out

  OpenAIClient singleton already made, ignoring arguments {'something': 42}
  Singleton instance of type OpenAIEndpoint already created at:
  /var/folders/2j/xg0_cv993gl37s_8qs5qrdxm0000gn/T/ipykernel_84662/360095262.py:8
	  OpenAI(client=..., something=42)
  
  You can delete the singleton by calling `<instance>.delete_singleton()` or 
    ```python
    from trulens_eval.utils.python import SingletonPerName
    SingletonPerName.delete_singleton_by_name(name="openai", cls=OpenAIEndpoint)
    ```

The first part is the existing warning but the second points out the source code line that caused the singleton to be created to begin with. In this case, the call to Groundedness created a default openai client hence the second one's configuration is ignored. Note the weird source code file name is because this is in a jupyter notebook running on vscode.

Added this warning to OpenAIEndpoint, LiteLLMEndpoint, and Tru.

  • The instructions also show how to delete the instance, thus this code is ok:
g = Groundedness()
g.groundedness_provider.endpoint.delete_singleton()
OpenAI(client=..., something=42)
  • This is also ok:
g = Groundedness()
from trulens_eval.utils.python import SingletonPerName
from trulens_eval.feedback.provider.endpoint.openai import OpenAIEndpoint
SingletonPerName.delete_singleton_by_name(name="openai", cls=OpenAIEndpoint)
OpenAI(client=..., something=42)

@dosubot dosubot bot added the size:L This PR changes 100-499 lines, ignoring generated files. label Apr 18, 2024
@piotrm0 piotrm0 requested a review from arn-tru April 22, 2024 08:10
@dosubot dosubot bot added the lgtm This PR has been approved by a maintainer label Apr 23, 2024
@arn-tru arn-tru merged commit 7bc2ec2 into main Apr 23, 2024
9 checks passed
sfc-gh-dhuang pushed a commit that referenced this pull request Jun 28, 2024
* first

* delete instructions

* static delete singleton instructions
sfc-gh-chu pushed a commit that referenced this pull request Sep 25, 2024
* first

* delete instructions

* static delete singleton instructions
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
lgtm This PR has been approved by a maintainer size:L This PR changes 100-499 lines, ignoring generated files.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants