Skip to content

Commit

Permalink
trurails: update to getattr (truera#1130)
Browse files Browse the repository at this point in the history
* fix rag triad and awaitable calls

* remove locals printout in awaitables message

* update __getattr__ in select_context (truera#1119)

---------

Co-authored-by: Piotr Mardziel <piotrm@gmail.com>
  • Loading branch information
joshreini1 and piotrm0 authored May 9, 2024
1 parent 11f22e1 commit fc2c5a2
Showing 1 changed file with 6 additions and 10 deletions.
16 changes: 6 additions & 10 deletions trulens_eval/trulens_eval/tru_rails.py
Original file line number Diff line number Diff line change
Expand Up @@ -438,17 +438,13 @@ def select_context(cls, app: Optional[LLMRails] = None) -> Lens:
return mod_feedback_schema.Select.RecordCalls.kb.search_relevant_chunks.rets[:
].body

def __getattr__(self, __name: str) -> Any:
# A message for cases where a user calls something that the wrapped
# app has but we do not wrap yet.

if safe_hasattr(self.app, __name):
return RuntimeError(
f"TruRails has no attribute {__name} but the wrapped app ({type(self.app)}) does. ",
f"If you are calling a {type(self.app)} method, retrieve it from that app instead of from `TruRails`. "
)
def __getattr__(self, name):
if name == "__name__":
return self.__class__.__name__ # Return the class name of TruRails
elif safe_hasattr(self.app, name):
return getattr(self.app, name) # Delegate to the wrapped app if it has the attribute
else:
raise RuntimeError(f"TruRails has no attribute named {__name}.")
raise AttributeError(f"TruRails has no attribute named {name}")


import trulens_eval # for App class annotations
Expand Down

0 comments on commit fc2c5a2

Please sign in to comment.