langfun 0.1.2.dev202410140804__py3-none-any.whl → 0.1.2.dev202410180804__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- langfun/core/component.py +48 -0
- langfun/core/component_test.py +48 -0
- langfun/core/logging.py +39 -28
- langfun/core/logging_test.py +21 -5
- langfun/core/message.py +104 -64
- langfun/core/message_test.py +101 -11
- langfun/core/modalities/mime.py +32 -20
- langfun/core/modalities/mime_test.py +8 -4
- langfun/core/structured/mapping.py +46 -29
- langfun/core/structured/mapping_test.py +11 -5
- langfun/core/structured/schema.py +1 -1
- langfun/core/template.py +36 -49
- langfun/core/template_test.py +39 -1
- {langfun-0.1.2.dev202410140804.dist-info → langfun-0.1.2.dev202410180804.dist-info}/METADATA +1 -1
- {langfun-0.1.2.dev202410140804.dist-info → langfun-0.1.2.dev202410180804.dist-info}/RECORD +18 -18
- {langfun-0.1.2.dev202410140804.dist-info → langfun-0.1.2.dev202410180804.dist-info}/WHEEL +1 -1
- {langfun-0.1.2.dev202410140804.dist-info → langfun-0.1.2.dev202410180804.dist-info}/LICENSE +0 -0
- {langfun-0.1.2.dev202410140804.dist-info → langfun-0.1.2.dev202410180804.dist-info}/top_level.txt +0 -0
langfun/core/template.py
CHANGED
@@ -17,7 +17,7 @@ import contextlib
|
|
17
17
|
import dataclasses
|
18
18
|
import functools
|
19
19
|
import inspect
|
20
|
-
from typing import Annotated, Any, Callable, Iterator,
|
20
|
+
from typing import Annotated, Any, Callable, Iterator, Set, Tuple, Type, Union
|
21
21
|
|
22
22
|
import jinja2
|
23
23
|
from jinja2 import meta as jinja2_meta
|
@@ -531,59 +531,48 @@ class Template(
|
|
531
531
|
*,
|
532
532
|
view: pg.views.HtmlTreeView,
|
533
533
|
root_path: pg.KeyPath,
|
534
|
-
|
535
|
-
|
534
|
+
collapse_level: int | None = None,
|
535
|
+
extra_flags: dict[str, Any] | None = None,
|
536
|
+
debug: bool = False,
|
536
537
|
**kwargs,
|
537
538
|
):
|
539
|
+
extra_flags = extra_flags if extra_flags is not None else {}
|
540
|
+
collapse_template_vars_level: int | None = extra_flags.get(
|
541
|
+
'collapse_template_vars_level', 1
|
542
|
+
)
|
543
|
+
|
538
544
|
def render_template_str():
|
539
545
|
return pg.Html.element(
|
540
546
|
'div',
|
541
547
|
[
|
542
548
|
pg.Html.element('span', [self.template_str])
|
543
549
|
],
|
544
|
-
|
550
|
+
css_classes=['template-str'],
|
545
551
|
)
|
546
552
|
|
547
553
|
def render_fields():
|
548
|
-
def render_value_fn(value, *, root_path, **kwargs):
|
549
|
-
if isinstance(value, component.ContextualAttribute):
|
550
|
-
inferred = self.sym_inferred(root_path.key, pg.MISSING_VALUE)
|
551
|
-
if inferred != pg.MISSING_VALUE:
|
552
|
-
return pg.Html.element(
|
553
|
-
'div',
|
554
|
-
[
|
555
|
-
view.render(inferred, root_path=root_path, **kwargs)
|
556
|
-
],
|
557
|
-
css_class=['inferred-value'],
|
558
|
-
)
|
559
|
-
else:
|
560
|
-
return pg.Html.element(
|
561
|
-
'span',
|
562
|
-
['(external)'],
|
563
|
-
css_class=['contextual-variable'],
|
564
|
-
)
|
565
|
-
return view.render(
|
566
|
-
value, root_path=root_path, **kwargs
|
567
|
-
)
|
568
554
|
return pg.Html.element(
|
569
555
|
'fieldset',
|
570
556
|
[
|
571
557
|
pg.Html.element('legend', ['Template Variables']),
|
572
558
|
view.complex_value(
|
573
|
-
self.
|
559
|
+
{k: v for k, v in self.sym_items()},
|
574
560
|
name='fields',
|
575
561
|
root_path=root_path,
|
576
|
-
render_value_fn=render_value_fn,
|
577
|
-
exclude_keys=['template_str', 'clean'],
|
578
562
|
parent=self,
|
579
|
-
|
580
|
-
|
581
|
-
collapse_template_vars_level,
|
582
|
-
|
583
|
-
|
563
|
+
exclude_keys=['template_str', 'clean'],
|
564
|
+
collapse_level=max(
|
565
|
+
collapse_template_vars_level, collapse_level
|
566
|
+
) if collapse_level is not None else None,
|
567
|
+
extra_flags=extra_flags,
|
568
|
+
debug=debug,
|
569
|
+
**view.get_passthrough_kwargs(
|
570
|
+
remove=['exclude_keys'],
|
571
|
+
**kwargs,
|
572
|
+
)
|
584
573
|
),
|
585
574
|
],
|
586
|
-
|
575
|
+
css_classes=['template-fields'],
|
587
576
|
)
|
588
577
|
|
589
578
|
return pg.Html.element(
|
@@ -592,11 +581,12 @@ class Template(
|
|
592
581
|
render_template_str(),
|
593
582
|
render_fields(),
|
594
583
|
],
|
595
|
-
|
584
|
+
css_classes=['complex_value'],
|
596
585
|
)
|
597
586
|
|
598
|
-
|
599
|
-
|
587
|
+
@classmethod
|
588
|
+
def _html_tree_view_css_styles(cls) -> list[str]:
|
589
|
+
return super()._html_tree_view_css_styles() + [
|
600
590
|
"""
|
601
591
|
/* Langfun Template styles. */
|
602
592
|
.template-str {
|
@@ -619,22 +609,19 @@ class Template(
|
|
619
609
|
font-size: 0.8em;
|
620
610
|
margin: 5px 0px 5px 0px;
|
621
611
|
}
|
622
|
-
.inferred-value::after {
|
623
|
-
content: ' (inferred)';
|
624
|
-
color: gray;
|
625
|
-
font-style: italic;
|
626
|
-
}
|
627
|
-
.contextual-variable {
|
628
|
-
margin: 0px 0px 0px 5px;
|
629
|
-
font-style: italic;
|
630
|
-
color: gray;
|
631
|
-
}
|
632
612
|
"""
|
633
613
|
]
|
634
614
|
|
635
|
-
|
636
|
-
|
637
|
-
|
615
|
+
@classmethod
|
616
|
+
@functools.cache
|
617
|
+
def _html_tree_view_config(cls) -> dict[str, Any]:
|
618
|
+
return pg.views.HtmlTreeView.get_kwargs(
|
619
|
+
super()._html_tree_view_config(),
|
620
|
+
dict(
|
621
|
+
css_classes=['lf-template'],
|
622
|
+
)
|
623
|
+
)
|
624
|
+
|
638
625
|
|
639
626
|
# Register converter from str to LangFunc, therefore we can always
|
640
627
|
# pass strs to attributes that accept LangFunc.
|
langfun/core/template_test.py
CHANGED
@@ -579,12 +579,50 @@ class HtmlTest(unittest.TestCase):
|
|
579
579
|
"""
|
580
580
|
y: Any
|
581
581
|
|
582
|
+
self.assertIn(
|
583
|
+
inspect.cleandoc(
|
584
|
+
"""
|
585
|
+
/* Langfun Template styles. */
|
586
|
+
.template-str {
|
587
|
+
padding: 10px;
|
588
|
+
margin: 10px 5px 10px 5px;
|
589
|
+
font-style: italic;
|
590
|
+
font-size: 1.1em;
|
591
|
+
white-space: pre-wrap;
|
592
|
+
border: 1px solid #EEE;
|
593
|
+
border-radius: 5px;
|
594
|
+
background-color: #EEE;
|
595
|
+
color: #cc2986;
|
596
|
+
}
|
597
|
+
.template-fields {
|
598
|
+
margin: 0px 0px 5px 0px;
|
599
|
+
border: 1px solid #EEE;
|
600
|
+
padding: 5px;
|
601
|
+
}
|
602
|
+
.template-fields > legend {
|
603
|
+
font-size: 0.8em;
|
604
|
+
margin: 5px 0px 5px 0px;
|
605
|
+
}
|
606
|
+
"""
|
607
|
+
),
|
608
|
+
Foo(x=1, y=2).to_html().style_section,
|
609
|
+
)
|
610
|
+
self.assert_html_content(
|
611
|
+
Foo(x=Bar('{{y}} + {{z}}'), y=1).to_html(
|
612
|
+
enable_summary_tooltip=False,
|
613
|
+
),
|
614
|
+
"""
|
615
|
+
<details open class="pyglove foo lf-template"><summary><div class="summary-title lf-template">Foo(...)</div></summary><div class="complex_value"><div class="template-str"><span>{{x}} + {{y}} = ?</span></div><fieldset class="template-fields"><legend>Template Variables</legend><div class="complex-value foo"><details class="pyglove bar lf-template"><summary><div class="summary-name lf-template">x<span class="tooltip lf-template">x</span></div><div class="summary-title lf-template">Bar(...)</div></summary><div class="complex_value"><div class="template-str"><span>{{y}} + {{z}}</span></div><fieldset class="template-fields"><legend>Template Variables</legend><div class="complex-value bar"><details open class="pyglove contextual-attribute"><summary><div class="summary-name">y<span class="tooltip">x.y</span></div><div class="summary-title">ContextualAttribute(...)</div></summary><span class="simple-value int">1</span></details><details open class="pyglove contextual-attribute"><summary><div class="summary-name">z<span class="tooltip">x.z</span></div><div class="summary-title">ContextualAttribute(...)</div></summary><div class="unavailable-contextual">(not available)</div></details></div></fieldset></div></details><details open class="pyglove int"><summary><div class="summary-name">y<span class="tooltip">y</span></div><div class="summary-title">int</div></summary><span class="simple-value int">1</span></details></div></fieldset></div></details>
|
616
|
+
"""
|
617
|
+
)
|
582
618
|
self.assert_html_content(
|
583
619
|
Foo(x=Bar('{{y}} + {{z}}'), y=1).to_html(
|
584
620
|
enable_summary_tooltip=False,
|
621
|
+
collapse_level=0,
|
622
|
+
key_style='label',
|
585
623
|
),
|
586
624
|
"""
|
587
|
-
<details
|
625
|
+
<details class="pyglove foo lf-template"><summary><div class="summary-title lf-template">Foo(...)</div></summary><div class="complex_value"><div class="template-str"><span>{{x}} + {{y}} = ?</span></div><fieldset class="template-fields"><legend>Template Variables</legend><div class="complex-value foo"><table><tr><td><span class="object-key str">x</span><span class="tooltip">x</span></td><td><details class="pyglove bar lf-template"><summary><div class="summary-title lf-template">Bar(...)</div></summary><div class="complex_value"><div class="template-str"><span>{{y}} + {{z}}</span></div><fieldset class="template-fields"><legend>Template Variables</legend><div class="complex-value bar"><table><tr><td><span class="object-key str">y</span><span class="tooltip">x.y</span></td><td><details open class="pyglove contextual-attribute"><summary><div class="summary-title">ContextualAttribute(...)</div></summary><span class="simple-value int">1</span></details></td></tr><tr><td><span class="object-key str">z</span><span class="tooltip">x.z</span></td><td><details open class="pyglove contextual-attribute"><summary><div class="summary-title">ContextualAttribute(...)</div></summary><div class="unavailable-contextual">(not available)</div></details></td></tr></table></div></fieldset></div></details></td></tr><tr><td><span class="object-key str">y</span><span class="tooltip">y</span></td><td><span class="simple-value int">1</span></td></tr></table></div></fieldset></div></details>
|
588
626
|
"""
|
589
627
|
)
|
590
628
|
|
@@ -1,7 +1,7 @@
|
|
1
1
|
langfun/__init__.py,sha256=mCES7t3R7Z-ZQYvG38-yrVqZubrXNfGCa8tI5HGB7mE,2274
|
2
2
|
langfun/core/__init__.py,sha256=xlvFTXc7IKUTs8aCFRFhzOLTmmeuhXgk9yx2InBLNiA,4937
|
3
|
-
langfun/core/component.py,sha256=
|
4
|
-
langfun/core/component_test.py,sha256=
|
3
|
+
langfun/core/component.py,sha256=kOWdhEYlGw62CO_7aB_oAdivVhnDfyoymRXHr10VtLo,11502
|
4
|
+
langfun/core/component_test.py,sha256=sG-T2wpvBfHqWGZE7sc4NayJj2aj5QFBzSwFiwrGEIc,10376
|
5
5
|
langfun/core/concurrent.py,sha256=QW-LbgF555lwHYmnirYONVjpqgkn95CuQRuAErgYIIY,29598
|
6
6
|
langfun/core/concurrent_test.py,sha256=F9kQKK0D6CHOejckFcVjCB-ThkBN8Oa4P8WV7FOhxIM,17042
|
7
7
|
langfun/core/console.py,sha256=bk5rNPNm9rMGW5YT2HixxU04p2umnoabn5SDz6Dqe88,2317
|
@@ -10,11 +10,11 @@ langfun/core/langfunc.py,sha256=G50YgoVZ0y1GFw2ev41MlOqr6qa8YakbvNC0h_E0PiA,1114
|
|
10
10
|
langfun/core/langfunc_test.py,sha256=KC6fU1InBxdYU5JkLgtafTWZD6Kd1qPaZRzO7sIHf9o,8787
|
11
11
|
langfun/core/language_model.py,sha256=AwvvwoaTbN0phDJBtXOxAIW4wnmEBrBiT0DknGPdn4o,29922
|
12
12
|
langfun/core/language_model_test.py,sha256=cgoSdKwicnvHYo-tQeTdONXAVM-bvWLzgTlqxvace-A,28424
|
13
|
-
langfun/core/logging.py,sha256=
|
14
|
-
langfun/core/logging_test.py,sha256=
|
13
|
+
langfun/core/logging.py,sha256=2zVHV5E4vdsjxY8lFF1zZP0WQlts4LT3nXspOKqDeBs,7454
|
14
|
+
langfun/core/logging_test.py,sha256=b5bPTSUoYeICATaO6I8dOVumodwRbxSp1Oz96Sf3KcE,6104
|
15
15
|
langfun/core/memory.py,sha256=f-asN1F7Vehgdn_fK84v73GrEUOxRtaW934keutTKjk,2416
|
16
|
-
langfun/core/message.py,sha256=
|
17
|
-
langfun/core/message_test.py,sha256=
|
16
|
+
langfun/core/message.py,sha256=Mc-QWnP22ia-ZIKJ_9A3CZynB5sHOH7VkJm7eTDxsbM,25589
|
17
|
+
langfun/core/message_test.py,sha256=HaJ7zB0rtB_RF8mOfXH18csIViP8_QY12GD6ZV7k3H0,32603
|
18
18
|
langfun/core/modality.py,sha256=hC0LF8EGCU2GJxTNbfzR441oOk2-HnHnAVWbwkLG0bI,4133
|
19
19
|
langfun/core/modality_test.py,sha256=7SwhixFME2Q1sIXRgJx97EZFiIyC31A9NVr6_nDtFv4,2441
|
20
20
|
langfun/core/natural_language.py,sha256=3ynSnaYQnjE60LIPK5fyMgdIjubnPYZwzGq4rWPeloE,1177
|
@@ -25,8 +25,8 @@ langfun/core/sampling.py,sha256=SCnS5PFJWNVxSKvSkSCNRUmruvScun8UcNN4gafuXcw,5866
|
|
25
25
|
langfun/core/sampling_test.py,sha256=U7PANpMsl9E_pa4_Y4FzesSjcwg-u-LKHGCWSgv-8FY,3663
|
26
26
|
langfun/core/subscription.py,sha256=euawEuSZP-BHydaT-AQpfYFL0m5pWPGcW0upFhrojqc,10930
|
27
27
|
langfun/core/subscription_test.py,sha256=Y4ZdbZEwm83YNZBxHff0QR4QUa4rdaNXA3_jfIcArBo,8717
|
28
|
-
langfun/core/template.py,sha256=
|
29
|
-
langfun/core/template_test.py,sha256=
|
28
|
+
langfun/core/template.py,sha256=SpI-UvVUDRJ5HYa4fVkOvbjEwrpUjhZoNqiG2adUAwE,25339
|
29
|
+
langfun/core/template_test.py,sha256=Qokz1hQFhRYaTZWBWGqvPJ0NXC9B9ennUpnRYHEf0hE,20542
|
30
30
|
langfun/core/text_formatting.py,sha256=d7t9vaY6aCn1dkfkikpNYnBy5E_i93vHbfyDWFclGZU,5284
|
31
31
|
langfun/core/text_formatting_test.py,sha256=ck0Xzdd4YF4CtCUj7VE0GybfbAyKQ8p3xkM1FBGrqIk,2096
|
32
32
|
langfun/core/coding/__init__.py,sha256=5utju_fwEsImaiftx4oXKl9FAM8p281k8-Esdh_-m1w,835
|
@@ -81,8 +81,8 @@ langfun/core/modalities/audio.py,sha256=qCrVCX690SG0ps-ZfOtNWvHn_CmdJsmxF7GySScW
|
|
81
81
|
langfun/core/modalities/audio_test.py,sha256=yyGEBYqMXmNs_F2dEtj-PX8HE040vqh-YQppsvdxPw4,2025
|
82
82
|
langfun/core/modalities/image.py,sha256=ovcX8NLBNv8WzxAdhQ-u4VQfHVBkWijRj_oiNwhE9lk,1768
|
83
83
|
langfun/core/modalities/image_test.py,sha256=XMgtJXY75R5eo0CZ222D1QUy57_hESnttmCGWwDLt7k,3824
|
84
|
-
langfun/core/modalities/mime.py,sha256=
|
85
|
-
langfun/core/modalities/mime_test.py,sha256=
|
84
|
+
langfun/core/modalities/mime.py,sha256=jKE1eDaP46isD-IjWgfzhxnTcmQJ-b4wCoq6tury3J8,7576
|
85
|
+
langfun/core/modalities/mime_test.py,sha256=lC99gsaTUwVkxQat9hkR3CV-1GI-QPMgwaIdf9EqnoM,4471
|
86
86
|
langfun/core/modalities/ms_office.py,sha256=0PnM6W9SovVfJNd4XCpUfOcGBuvj4hlA1zqPjdsJNFM,3725
|
87
87
|
langfun/core/modalities/ms_office_test.py,sha256=rrDBx51ELAqRaUX6Y6tgg0k3tEFHOlRMfUpeULD7mlo,87868
|
88
88
|
langfun/core/modalities/pdf.py,sha256=mfaeCbUA4JslFVTARiJh8hW7imvL4tLVw9gUhO5bAZA,727
|
@@ -96,13 +96,13 @@ langfun/core/structured/description.py,sha256=SXW4MJvshFjbR-0gw6rE21o6WXq12UlRXa
|
|
96
96
|
langfun/core/structured/description_test.py,sha256=UtZGjSFUaQ6130t1E5tcL7ODu0xIefkapb53TbnqsK8,7362
|
97
97
|
langfun/core/structured/function_generation.py,sha256=pFgS3vcRAWiuFBol2x5Eeip3XqoudONsOpeJpWyjT3s,7479
|
98
98
|
langfun/core/structured/function_generation_test.py,sha256=ZJI-aaGgWWszn92u7h5IZ9Pl70N2DgAGGJrIxPzsvwg,10065
|
99
|
-
langfun/core/structured/mapping.py,sha256=
|
100
|
-
langfun/core/structured/mapping_test.py,sha256=
|
99
|
+
langfun/core/structured/mapping.py,sha256=pMSvxEPqA8h7LsCMKMGG5Fcm0hyaIOTHFcoddQpn4cs,13574
|
100
|
+
langfun/core/structured/mapping_test.py,sha256=bHm2ZCXBITq_G8Lvw_olFHeUUc4s_lGXZm9v9JhoPB4,9630
|
101
101
|
langfun/core/structured/parsing.py,sha256=keoVqEfzAbdULh6GawWFsTQzU91MzJXYFZjXGXLaD8g,11492
|
102
102
|
langfun/core/structured/parsing_test.py,sha256=-sYWlamAuU_tMUSEq2vDhEU6uz_9fBtQ6M6ODBAYy_I,20941
|
103
103
|
langfun/core/structured/prompting.py,sha256=huwwh01AQQCwPBQESOMI_V1V5PZkVQ8C89Yjk67_4Uw,10677
|
104
104
|
langfun/core/structured/prompting_test.py,sha256=pviyb8yTnxkWPAZodLIlQT8y2ScE6FfSHKWf1NUtV-Y,26718
|
105
|
-
langfun/core/structured/schema.py,sha256=
|
105
|
+
langfun/core/structured/schema.py,sha256=UO44Gn4XbFfHmTMYdrhuC8LfGa6kwaOCAMFqBnvFNns,28156
|
106
106
|
langfun/core/structured/schema_generation.py,sha256=U3nRQsqmMZg_qIVDh2fiY3K4JLfsAL1LcKzIFP1iXFg,5316
|
107
107
|
langfun/core/structured/schema_generation_test.py,sha256=RM9s71kMNg2jTePwInkiW9fK1ACN37eyPeF8OII-0zw,2950
|
108
108
|
langfun/core/structured/schema_test.py,sha256=RjYhwTgktQgyqAjzLvo967nTiIK9KWgP-aNGg4e7ihE,25258
|
@@ -119,8 +119,8 @@ langfun/core/templates/demonstration.py,sha256=vCrgYubdZM5Umqcgp8NUVGXgr4P_c-fik
|
|
119
119
|
langfun/core/templates/demonstration_test.py,sha256=SafcDQ0WgI7pw05EmPI2S4v1t3ABKzup8jReCljHeK4,2162
|
120
120
|
langfun/core/templates/selfplay.py,sha256=yhgrJbiYwq47TgzThmHrDQTF4nDrTI09CWGhuQPNv-s,2273
|
121
121
|
langfun/core/templates/selfplay_test.py,sha256=Ot__1P1M8oJfoTp-M9-PQ6HUXqZKyMwvZ5f7yQ3yfyM,2326
|
122
|
-
langfun-0.1.2.
|
123
|
-
langfun-0.1.2.
|
124
|
-
langfun-0.1.2.
|
125
|
-
langfun-0.1.2.
|
126
|
-
langfun-0.1.2.
|
122
|
+
langfun-0.1.2.dev202410180804.dist-info/LICENSE,sha256=WNHhf_5RCaeuKWyq_K39vmp9F28LxKsB4SpomwSZ2L0,11357
|
123
|
+
langfun-0.1.2.dev202410180804.dist-info/METADATA,sha256=8LqnQs02H5_1Bw2RbdEdz5JMYLec6yO04lwkIMHzxE8,8890
|
124
|
+
langfun-0.1.2.dev202410180804.dist-info/WHEEL,sha256=OVMc5UfuAQiSplgO0_WdW7vXVGAt9Hdd6qtN4HotdyA,91
|
125
|
+
langfun-0.1.2.dev202410180804.dist-info/top_level.txt,sha256=RhlEkHxs1qtzmmtWSwYoLVJAc1YrbPtxQ52uh8Z9VvY,8
|
126
|
+
langfun-0.1.2.dev202410180804.dist-info/RECORD,,
|
File without changes
|
{langfun-0.1.2.dev202410140804.dist-info → langfun-0.1.2.dev202410180804.dist-info}/top_level.txt
RENAMED
File without changes
|