langfun 0.1.2.dev202412100804__py3-none-any.whl → 0.1.2.dev202412120804__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.
@@ -64,23 +64,16 @@ class Action(pg.Object):
64
64
 
65
65
  with session.track_action(self):
66
66
  result = self.call(session=session, **kwargs)
67
- metadata = dict()
68
- if (isinstance(result, tuple)
69
- and len(result) == 2 and isinstance(result[1], dict)):
70
- result, metadata = result
71
67
 
72
68
  # For the top-level action, we store the session in the metadata.
73
69
  if new_session:
74
70
  self._session = session
75
- self._result, self._result_metadata = result, metadata
71
+ self._result = result
72
+ self._result_metadata = session.current_action.result_metadata
76
73
  return self._result
77
74
 
78
75
  @abc.abstractmethod
79
- def call(
80
- self,
81
- session: 'Session',
82
- **kwargs
83
- ) -> Union[Any, tuple[Any, dict[str, Any]]]:
76
+ def call(self, session: 'Session', **kwargs) -> Any:
84
77
  """Calls the action.
85
78
 
86
79
  Args:
@@ -88,7 +81,7 @@ class Action(pg.Object):
88
81
  **kwargs: Additional keyword arguments to pass to the action.
89
82
 
90
83
  Returns:
91
- The result of the action or a tuple of (result, result_metadata).
84
+ The result of the action.
92
85
  """
93
86
 
94
87
 
@@ -726,6 +719,11 @@ class Session(pg.Object, pg.views.html.HtmlTreeView.Extension):
726
719
  """Returns the current invocation."""
727
720
  return self._current_action
728
721
 
722
+ def add_metadata(self, **kwargs: Any) -> None:
723
+ """Adds metadata to the current invocation."""
724
+ with pg.notify_on_change(False):
725
+ self._current_action.result_metadata.update(kwargs)
726
+
729
727
  def phase(self, name: str) -> ContextManager[ExecutionTrace]:
730
728
  """Context manager for starting a new execution phase."""
731
729
  return self.current_action.phase(name)
@@ -33,7 +33,8 @@ class SessionTest(unittest.TestCase):
33
33
  test.assertIs(session.current_action.action, self)
34
34
  session.info('Begin Bar')
35
35
  session.query('bar', lm=lm)
36
- return 2, dict(note='bar')
36
+ session.add_metadata(note='bar')
37
+ return 2
37
38
 
38
39
  class Foo(action_lib.Action):
39
40
  x: int
@@ -45,7 +46,8 @@ class SessionTest(unittest.TestCase):
45
46
  session.query('foo', lm=lm)
46
47
  with session.track_queries():
47
48
  self.make_additional_query(lm)
48
- return self.x + Bar()(session, lm=lm), dict(note='foo')
49
+ session.add_metadata(note='foo')
50
+ return self.x + Bar()(session, lm=lm)
49
51
 
50
52
  def make_additional_query(self, lm):
51
53
  lf_structured.query('additional query', lm=lm)
@@ -556,6 +556,9 @@ class Evaluation(experiment_lib.Experiment):
556
556
  border: 0px;
557
557
  margin: 0px;
558
558
  }
559
+ .eval-details .tab-control {
560
+ width: 100%;
561
+ }
559
562
  .eval-details .tab-button {
560
563
  font-size: large;
561
564
  }
@@ -40,7 +40,7 @@ except ImportError:
40
40
 
41
41
  # https://cloud.google.com/vertex-ai/generative-ai/pricing
42
42
  # describes that the average number of characters per token is about 4.
43
- AVGERAGE_CHARS_PER_TOEKN = 4
43
+ AVGERAGE_CHARS_PER_TOKEN = 4
44
44
 
45
45
 
46
46
  # Price in US dollars,
@@ -102,6 +102,18 @@ SUPPORTED_MODELS_AND_SETTINGS = {
102
102
  cost_per_1k_input_chars=0.000125,
103
103
  cost_per_1k_output_chars=0.000375,
104
104
  ),
105
+ # TODO(sharatsharat): Update costs when published
106
+ 'gemini-exp-1206': pg.Dict(
107
+ rpm=20,
108
+ cost_per_1k_input_chars=0.000,
109
+ cost_per_1k_output_chars=0.000,
110
+ ),
111
+ # TODO(sharatsharat): Update costs when published
112
+ 'gemini-2.0-flash-exp': pg.Dict(
113
+ rpm=20,
114
+ cost_per_1k_input_chars=0.000,
115
+ cost_per_1k_output_chars=0.000,
116
+ ),
105
117
  # TODO(chengrun): Set a more appropriate rpm for endpoint.
106
118
  'vertexai-endpoint': pg.Dict(
107
119
  rpm=20,
@@ -215,7 +227,7 @@ class VertexAI(rest.REST):
215
227
  return (
216
228
  cost_per_1k_input_chars * num_input_tokens
217
229
  + cost_per_1k_output_chars * num_output_tokens
218
- ) * AVGERAGE_CHARS_PER_TOEKN / 1000
230
+ ) * AVGERAGE_CHARS_PER_TOKEN / 1000
219
231
 
220
232
  @functools.cached_property
221
233
  def _session(self):
langfun/core/message.py CHANGED
@@ -769,7 +769,6 @@ class Message(
769
769
  padding: 20px;
770
770
  margin: 10px 5px 10px 5px;
771
771
  font-style: italic;
772
- font-size: 1.1em;
773
772
  white-space: pre-wrap;
774
773
  border: 1px solid #EEE;
775
774
  border-radius: 5px;
@@ -380,7 +380,6 @@ class MessageTest(unittest.TestCase):
380
380
  padding: 20px;
381
381
  margin: 10px 5px 10px 5px;
382
382
  font-style: italic;
383
- font-size: 1.1em;
384
383
  white-space: pre-wrap;
385
384
  border: 1px solid #EEE;
386
385
  border-radius: 5px;
@@ -201,7 +201,7 @@ class Schema(
201
201
  ):
202
202
  return pg.Html.element(
203
203
  'div',
204
- [self.schema_str(protocol='python')],
204
+ [pg.Html.escape(self.schema_str(protocol='python'))],
205
205
  css_classes=['lf-schema-definition']
206
206
  ).add_style(
207
207
  """
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: langfun
3
- Version: 0.1.2.dev202412100804
3
+ Version: 0.1.2.dev202412120804
4
4
  Summary: Langfun: Language as Functions.
5
5
  Home-page: https://github.com/google/langfun
6
6
  Author: Langfun Authors
@@ -13,8 +13,8 @@ langfun/core/language_model_test.py,sha256=hnYhtw7GM_TbhgsJzHNYTaoDewUlPHpOVlI7x
13
13
  langfun/core/logging.py,sha256=uslllP0RTGN223oro1m4nZZ0bFppcL07OwbFKm2iG6k,7519
14
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=tRHEx-oGt325epJ836C4LoRFVWdfV2_Xcg0Qwrau2rs,25716
17
- langfun/core/message_test.py,sha256=v_BVCC5Ia-izwOBvKlw3waDJnKi0g4C68dc_cwlB1Vs,32611
16
+ langfun/core/message.py,sha256=16oiMpg9O9VKrgpfrvJrfvga3n3FzUuD_zdWb9nvSWA,25686
17
+ langfun/core/message_test.py,sha256=jtZoNBNbA99i2fjoKg5vTRgoUe84J4MH8ZMGakGmTHs,32577
18
18
  langfun/core/modality.py,sha256=K8pUGuMpfWcOtVcXC_OqVjro1-RhHF6ddQni61DuYzM,4166
19
19
  langfun/core/modality_test.py,sha256=7SwhixFME2Q1sIXRgJx97EZFiIyC31A9NVr6_nDtFv4,2441
20
20
  langfun/core/natural_language.py,sha256=3ynSnaYQnjE60LIPK5fyMgdIjubnPYZwzGq4rWPeloE,1177
@@ -30,10 +30,10 @@ langfun/core/template_test.py,sha256=Qokz1hQFhRYaTZWBWGqvPJ0NXC9B9ennUpnRYHEf0hE
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/agentic/__init__.py,sha256=ndoDX0sAYsa3eVdXuu6nB-a-BH5TaK3urW6zAaFiyVs,1110
33
- langfun/core/agentic/action.py,sha256=jCVxTULwEi78ggg6lTDI7U1ejHzOvak_3FeAI-Td3Y0,26277
33
+ langfun/core/agentic/action.py,sha256=QZPKRU31m0qr7R7LBtx0B7I1ZOgqf-CSrXf9Mf11CTo,26253
34
34
  langfun/core/agentic/action_eval.py,sha256=ZtjTh34S7XPIUqandQ0YwAtzw-S7ofuZ7rRXnRbUMdQ,4424
35
35
  langfun/core/agentic/action_eval_test.py,sha256=tRUkWmOE9p0rpNOq19xAY2oDEnYsEEykjg6sUpAwJk0,2832
36
- langfun/core/agentic/action_test.py,sha256=gVafU2akdrkEu2G4VaDDmXSYKNSkO1trghgcb1nDfIA,4591
36
+ langfun/core/agentic/action_test.py,sha256=LkRTAa1zv8zavnkvCQEovKbKilVN5VNcqpK4shAcc1E,4637
37
37
  langfun/core/coding/__init__.py,sha256=5utju_fwEsImaiftx4oXKl9FAM8p281k8-Esdh_-m1w,835
38
38
  langfun/core/coding/python/__init__.py,sha256=MJ-vubliz-ebrZH3OBRKBwMi0S9-FrhGCp8YQLR6_I4,1776
39
39
  langfun/core/coding/python/correction.py,sha256=WiBdoScL-6C___iA3Tg3vizuYtJWI-_4wy9zcMfVpj8,7020
@@ -60,7 +60,7 @@ langfun/core/eval/scoring_test.py,sha256=O8olHbrUEg60gMxwOkWzKBJZpZoUlmVnBANX5Se
60
60
  langfun/core/eval/v2/__init__.py,sha256=XMpkKjd_vL_qzCQYPAwR1NNO0T_Zo5j4kP3eYL-EJLc,1428
61
61
  langfun/core/eval/v2/checkpointing.py,sha256=AhChb5U0fTd0NmDHaIaVE9qJ8zFEe7Lhq7KjIt1D2pQ,3766
62
62
  langfun/core/eval/v2/checkpointing_test.py,sha256=xU5asikwUn-rCmNd93ssvT6gDiKvvWogYKQa0r_TqOM,3046
63
- langfun/core/eval/v2/evaluation.py,sha256=hausa1NnUGi56KNrucd61qv9km1eDvcj2GBqiJzb0FA,19371
63
+ langfun/core/eval/v2/evaluation.py,sha256=h_AWRUSKhEs-bHLBgqo-GeBYXluD5bPbAqypRW0ajfA,19441
64
64
  langfun/core/eval/v2/evaluation_test.py,sha256=hh6L2HhQPQ6NBv1pXKcNkYraNcV9MLuJ--69t9jbmaI,5846
65
65
  langfun/core/eval/v2/example.py,sha256=fURrvdNmMsVMqoEErcsmLmC6Xq3ny16dYsnLH8HVlcY,9626
66
66
  langfun/core/eval/v2/example_test.py,sha256=WcJmU7IQQXvjFia63mokySC4CqxzVL9Wso1sC5F0YK8,3032
@@ -96,7 +96,7 @@ langfun/core/llms/openai.py,sha256=l49v6RubfInvV0iG114AymTKNogTX4u4N-UFCeSgIxw,2
96
96
  langfun/core/llms/openai_test.py,sha256=kOWa1nf-nJvtYY10REUw5wojh3ZgfU8tRaCZ8wUgJbA,16623
97
97
  langfun/core/llms/rest.py,sha256=sWbYUV8S3SuOg9giq7xwD-xDRfaF7NP_ig7bI52-Rj4,3442
98
98
  langfun/core/llms/rest_test.py,sha256=NZ3Nf0XQVpT9kLP5cBVo_yBHLI7vWTYhWQxYEJVMGs4,3472
99
- langfun/core/llms/vertexai.py,sha256=BkhRKnr20gIJvRL8G-KwTT7EM7v7L-pXkBkPeRkEFFY,14184
99
+ langfun/core/llms/vertexai.py,sha256=bwOJGuTSsQHqNoa6UIXhk6MUkyMd_b6dzd3Txrw3Rps,14565
100
100
  langfun/core/llms/vertexai_test.py,sha256=ffcA5yPecnQy_rhkuYAw_6o1iLW8AR8FgswmHt6aAys,6725
101
101
  langfun/core/llms/cache/__init__.py,sha256=QAo3InUMDM_YpteNnVCSejI4zOsnjSMWKJKzkb3VY64,993
102
102
  langfun/core/llms/cache/base.py,sha256=rt3zwmyw0y9jsSGW-ZbV1vAfLxQ7_3AVk0l2EySlse4,3918
@@ -131,7 +131,7 @@ langfun/core/structured/parsing.py,sha256=D58wBWOC6r6DCJNychCDkiHPrsy1XJfBDCDDZt
131
131
  langfun/core/structured/parsing_test.py,sha256=i0i090FVgM8ngGqYjds0hjEm1v7q4gv18k-z1kaNr7E,21467
132
132
  langfun/core/structured/prompting.py,sha256=vvPZcB0OL_kQMwyCUe4r4Q77luHT_OwVX3DeILN0hNw,16564
133
133
  langfun/core/structured/prompting_test.py,sha256=TFqerzK5RFlYyNL-X4wrhY-vOjF_XEpHX3nbSNuNKxg,29720
134
- langfun/core/structured/schema.py,sha256=XHA-m_ENT_J0k8Q7WCiCL51xm7oXHOqskhO8RpPIurc,28174
134
+ langfun/core/structured/schema.py,sha256=_T8WIDdpvWXlZVPLVgKYH9TvoM9gK11m3f0b2nImQRM,28190
135
135
  langfun/core/structured/schema_generation.py,sha256=U3nRQsqmMZg_qIVDh2fiY3K4JLfsAL1LcKzIFP1iXFg,5316
136
136
  langfun/core/structured/schema_generation_test.py,sha256=RM9s71kMNg2jTePwInkiW9fK1ACN37eyPeF8OII-0zw,2950
137
137
  langfun/core/structured/schema_test.py,sha256=RjYhwTgktQgyqAjzLvo967nTiIK9KWgP-aNGg4e7ihE,25258
@@ -148,8 +148,8 @@ langfun/core/templates/demonstration.py,sha256=vCrgYubdZM5Umqcgp8NUVGXgr4P_c-fik
148
148
  langfun/core/templates/demonstration_test.py,sha256=SafcDQ0WgI7pw05EmPI2S4v1t3ABKzup8jReCljHeK4,2162
149
149
  langfun/core/templates/selfplay.py,sha256=yhgrJbiYwq47TgzThmHrDQTF4nDrTI09CWGhuQPNv-s,2273
150
150
  langfun/core/templates/selfplay_test.py,sha256=Ot__1P1M8oJfoTp-M9-PQ6HUXqZKyMwvZ5f7yQ3yfyM,2326
151
- langfun-0.1.2.dev202412100804.dist-info/LICENSE,sha256=WNHhf_5RCaeuKWyq_K39vmp9F28LxKsB4SpomwSZ2L0,11357
152
- langfun-0.1.2.dev202412100804.dist-info/METADATA,sha256=IcDza3RsE6fuifE64s71Jo-T4LoROCzQ3mYHo8NCNko,8281
153
- langfun-0.1.2.dev202412100804.dist-info/WHEEL,sha256=PZUExdf71Ui_so67QXpySuHtCi3-J3wvF4ORK6k_S8U,91
154
- langfun-0.1.2.dev202412100804.dist-info/top_level.txt,sha256=RhlEkHxs1qtzmmtWSwYoLVJAc1YrbPtxQ52uh8Z9VvY,8
155
- langfun-0.1.2.dev202412100804.dist-info/RECORD,,
151
+ langfun-0.1.2.dev202412120804.dist-info/LICENSE,sha256=WNHhf_5RCaeuKWyq_K39vmp9F28LxKsB4SpomwSZ2L0,11357
152
+ langfun-0.1.2.dev202412120804.dist-info/METADATA,sha256=OTHTCXZcoQyoFOUiSZqyvA1XirxpyusZ3GUjHXqi8s4,8281
153
+ langfun-0.1.2.dev202412120804.dist-info/WHEEL,sha256=PZUExdf71Ui_so67QXpySuHtCi3-J3wvF4ORK6k_S8U,91
154
+ langfun-0.1.2.dev202412120804.dist-info/top_level.txt,sha256=RhlEkHxs1qtzmmtWSwYoLVJAc1YrbPtxQ52uh8Z9VvY,8
155
+ langfun-0.1.2.dev202412120804.dist-info/RECORD,,