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

Langfun component to use inferred contextual values for __str__/__repr__. #16

Merged
merged 1 commit into from
Sep 26, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 13 additions & 0 deletions langfun/core/component.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,19 @@
class Component(pg.Object):
"""Base class for langfun components."""

# Override __repr__ format to use inferred values when available.
__str_format_args__ = dict(
compact=True,
use_inferred=True,
)

# Override __str__ format to use inferred values when available.
__str_format_args__ = dict(
compact=False,
verbose=False,
use_inferred=True,
)

# Allow symbolic assignment, which invalidates the object and recomputes
# states upon update.
allow_symbolic_assignment = True
Expand Down
3 changes: 2 additions & 1 deletion langfun/core/langfunc.py
Original file line number Diff line number Diff line change
Expand Up @@ -488,7 +488,8 @@ def __repr__(self) -> str:
exclude_keys.append('input_path')
if self.output_path is None:
exclude_keys.append('output_path')
return self.format(compact=True, exclude_keys=exclude_keys)
return self.format(
compact=True, use_inferred=True, exclude_keys=exclude_keys)


# Register converter from str to LangFunc, therefore we can always
Expand Down
3 changes: 1 addition & 2 deletions langfun/core/langfunc_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -94,8 +94,7 @@ def test_call(self):
"LangFunc(template_str='Hello', clean=True, returns=None, "
'lm=ExcitedEchoer(sampling_options=LMSamplingOptions(temperature=0.0, '
'max_tokens=1024, n=1, top_k=40, top_p=None, random_seed=None), '
'cache=ContextualAttribute(type=None, default=None), timeout=120.0, '
'max_attempts=5, debug=False), '
'cache=None, timeout=120.0, max_attempts=5, debug=False), '
'input_transform=None, output_transform=None)',
)

Expand Down
2 changes: 1 addition & 1 deletion langfun/core/language_model.py
Original file line number Diff line number Diff line change
Expand Up @@ -243,7 +243,7 @@ def __call__(

if self.debug:
console.write(
self.format(compact=True),
self.format(compact=True, use_inferred=True),
title=f'[{call_counter}] LM INFO:',
color='magenta',
)
Expand Down
2 changes: 1 addition & 1 deletion requirements.txt
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
jinja2>=3.1.2
openai>=0.18.1
pyglove>=0.4.4.dev20230922
pyglove>=0.4.4.dev20230926
termcolor==1.1.0
tqdm>=4.64.1
Loading