Bases: App
Instantiates a Basic app that makes little assumptions. Assumes input text and output text.
Usage:
def custom_application(prompt: str) -> str:
return "a response"
from trulens_eval import TruBasicApp
# f_lang_match, f_qa_relevance, f_qs_relevance are feedback functions
tru_recorder = TruBasicApp(custom_application,
app_id="Custom Application v1",
feedbacks=[f_lang_match, f_qa_relevance, f_qs_relevance])
# Basic app works by turning your callable into an app
# This app is accessbile with the `app` attribute in the recorder
with tru_recorder as recording:
tru_recorder.app(question)
tru_record = recording.records[0]
See
Feedback Functions for instantiating feedback functions.
Parameters:
Name |
Type |
Description |
Default |
text_to_text |
Callable
|
|
required
|
Source code in trulens_eval/trulens_eval/tru_basic_app.py
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149 | class TruBasicApp(App):
"""Instantiates a Basic app that makes little assumptions. Assumes input text and output text.
**Usage:**
```
def custom_application(prompt: str) -> str:
return "a response"
from trulens_eval import TruBasicApp
# f_lang_match, f_qa_relevance, f_qs_relevance are feedback functions
tru_recorder = TruBasicApp(custom_application,
app_id="Custom Application v1",
feedbacks=[f_lang_match, f_qa_relevance, f_qs_relevance])
# Basic app works by turning your callable into an app
# This app is accessbile with the `app` attribute in the recorder
with tru_recorder as recording:
tru_recorder.app(question)
tru_record = recording.records[0]
```
See [Feedback Functions](https://www.trulens.org/trulens_eval/api/feedback/) for instantiating feedback functions.
Args:
text_to_text (Callable): A text to text callable.
"""
app: TruWrapperApp
root_callable: ClassVar[FunctionOrMethod] = Field(
default_factory=lambda: FunctionOrMethod.
of_callable(TruWrapperApp._call),
const=True
)
def __init__(self, text_to_text: Callable, **kwargs):
"""
Wrap a callable for monitoring.
Arguments:
- text_to_text: A function with signature string to string.
- More args in App
- More args in AppDefinition
- More args in WithClassInfo
"""
super().update_forward_refs()
app = TruWrapperApp(text_to_text)
kwargs['app'] = TruWrapperApp(text_to_text)
kwargs['root_class'] = Class.of_object(app)
kwargs['instrument'] = TruBasicCallableInstrument(app=self)
super().__init__(**kwargs)
# Setup the DB-related things:
self.post_init()
def main_input(
self, func: Callable, sig: Signature, bindings: BoundArguments
) -> str:
if func == getattr(TruWrapperApp._call, Instrument.INSTRUMENT):
# If func is the wrapper app _call, replace the signature and
# bindings based on the actual containing callable instead of
# self.app._call . This needs to be done since the a TruWrapperApp
# may be wrapping apps with different signatures on their callables
# so TruWrapperApp._call cannot have a consistent signature
# statically. Note also we are looking up the Instrument.INSTRUMENT
# attribute here since the method is instrumented and overridden by
# another wrapper in the process with the original accessible at
# this attribute.
sig = signature(self.app._call_fn)
# Skipping self as TruWrapperApp._call takes in self, but
# self.app._call_fn does not.
bindings = sig.bind(*bindings.args[1:], **bindings.kwargs)
return super().main_input(func, sig, bindings)
def call_with_record(self, *args, **kwargs):
"""
Run the callable with the given arguments. Note that the wrapped
callable is expected to take in a single string.
Returns:
dict: record metadata
"""
# NOTE: Actually text_to_text can take in more args.
self._with_dep_message(method="call", is_async=False, with_record=True)
return self.with_record(self.app._call, *args, **kwargs)
|
__init__(text_to_text, **kwargs)
Wrap a callable for monitoring.
- text_to_text: A function with signature string to string.
- More args in App
- More args in AppDefinition
- More args in WithClassInfo
Source code in trulens_eval/trulens_eval/tru_basic_app.py
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113 | def __init__(self, text_to_text: Callable, **kwargs):
"""
Wrap a callable for monitoring.
Arguments:
- text_to_text: A function with signature string to string.
- More args in App
- More args in AppDefinition
- More args in WithClassInfo
"""
super().update_forward_refs()
app = TruWrapperApp(text_to_text)
kwargs['app'] = TruWrapperApp(text_to_text)
kwargs['root_class'] = Class.of_object(app)
kwargs['instrument'] = TruBasicCallableInstrument(app=self)
super().__init__(**kwargs)
# Setup the DB-related things:
self.post_init()
|
call_with_record(*args, **kwargs)
Run the callable with the given arguments. Note that the wrapped
callable is expected to take in a single string.
Returns:
Name | Type |
Description |
dict |
|
|
Source code in trulens_eval/trulens_eval/tru_basic_app.py
137
138
139
140
141
142
143
144
145
146
147
148
149 | def call_with_record(self, *args, **kwargs):
"""
Run the callable with the given arguments. Note that the wrapped
callable is expected to take in a single string.
Returns:
dict: record metadata
"""
# NOTE: Actually text_to_text can take in more args.
self._with_dep_message(method="call", is_async=False, with_record=True)
return self.with_record(self.app._call, *args, **kwargs)
|