langfun 0.0.2.dev20240429__py3-none-any.whl → 0.1.2.dev202501150804__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.
Files changed (144) hide show
  1. langfun/__init__.py +20 -2
  2. langfun/core/__init__.py +16 -5
  3. langfun/core/agentic/__init__.py +30 -0
  4. langfun/core/agentic/action.py +854 -0
  5. langfun/core/agentic/action_eval.py +150 -0
  6. langfun/core/agentic/action_eval_test.py +109 -0
  7. langfun/core/agentic/action_test.py +136 -0
  8. langfun/core/coding/python/__init__.py +5 -11
  9. langfun/core/coding/python/correction.py +37 -21
  10. langfun/core/coding/python/correction_test.py +29 -3
  11. langfun/core/coding/python/execution.py +40 -216
  12. langfun/core/coding/python/execution_test.py +29 -89
  13. langfun/core/coding/python/generation.py +21 -11
  14. langfun/core/coding/python/generation_test.py +2 -2
  15. langfun/core/coding/python/parsing.py +108 -193
  16. langfun/core/coding/python/parsing_test.py +2 -105
  17. langfun/core/component.py +63 -2
  18. langfun/core/component_test.py +53 -0
  19. langfun/core/concurrent.py +414 -117
  20. langfun/core/concurrent_test.py +111 -24
  21. langfun/core/console.py +17 -5
  22. langfun/core/console_test.py +17 -0
  23. langfun/core/eval/__init__.py +16 -1
  24. langfun/core/eval/base.py +622 -174
  25. langfun/core/eval/base_test.py +200 -54
  26. langfun/core/eval/matching.py +63 -76
  27. langfun/core/eval/matching_test.py +17 -8
  28. langfun/core/eval/patching.py +130 -0
  29. langfun/core/eval/patching_test.py +170 -0
  30. langfun/core/eval/scoring.py +26 -26
  31. langfun/core/eval/scoring_test.py +19 -2
  32. langfun/core/eval/v2/__init__.py +42 -0
  33. langfun/core/eval/v2/checkpointing.py +380 -0
  34. langfun/core/eval/v2/checkpointing_test.py +228 -0
  35. langfun/core/eval/v2/eval_test_helper.py +136 -0
  36. langfun/core/eval/v2/evaluation.py +725 -0
  37. langfun/core/eval/v2/evaluation_test.py +180 -0
  38. langfun/core/eval/v2/example.py +305 -0
  39. langfun/core/eval/v2/example_test.py +128 -0
  40. langfun/core/eval/v2/experiment.py +1048 -0
  41. langfun/core/eval/v2/experiment_test.py +433 -0
  42. langfun/core/eval/v2/metric_values.py +156 -0
  43. langfun/core/eval/v2/metric_values_test.py +80 -0
  44. langfun/core/eval/v2/metrics.py +357 -0
  45. langfun/core/eval/v2/metrics_test.py +203 -0
  46. langfun/core/eval/v2/progress.py +348 -0
  47. langfun/core/eval/v2/progress_test.py +82 -0
  48. langfun/core/eval/v2/progress_tracking.py +210 -0
  49. langfun/core/eval/v2/progress_tracking_test.py +66 -0
  50. langfun/core/eval/v2/reporting.py +270 -0
  51. langfun/core/eval/v2/reporting_test.py +158 -0
  52. langfun/core/eval/v2/runners.py +488 -0
  53. langfun/core/eval/v2/runners_test.py +334 -0
  54. langfun/core/langfunc.py +4 -17
  55. langfun/core/langfunc_test.py +22 -6
  56. langfun/core/language_model.py +577 -39
  57. langfun/core/language_model_test.py +470 -56
  58. langfun/core/llms/__init__.py +87 -16
  59. langfun/core/llms/anthropic.py +312 -87
  60. langfun/core/llms/anthropic_test.py +71 -3
  61. langfun/core/llms/cache/base.py +21 -2
  62. langfun/core/llms/cache/in_memory.py +13 -0
  63. langfun/core/llms/cache/in_memory_test.py +53 -2
  64. langfun/core/llms/compositional.py +101 -0
  65. langfun/core/llms/compositional_test.py +73 -0
  66. langfun/core/llms/deepseek.py +117 -0
  67. langfun/core/llms/deepseek_test.py +61 -0
  68. langfun/core/llms/fake.py +11 -7
  69. langfun/core/llms/fake_test.py +14 -0
  70. langfun/core/llms/gemini.py +507 -0
  71. langfun/core/llms/gemini_test.py +195 -0
  72. langfun/core/llms/google_genai.py +62 -218
  73. langfun/core/llms/google_genai_test.py +9 -202
  74. langfun/core/llms/groq.py +160 -144
  75. langfun/core/llms/groq_test.py +31 -137
  76. langfun/core/llms/llama_cpp.py +15 -42
  77. langfun/core/llms/llama_cpp_test.py +4 -30
  78. langfun/core/llms/openai.py +395 -203
  79. langfun/core/llms/openai_compatible.py +179 -0
  80. langfun/core/llms/openai_compatible_test.py +495 -0
  81. langfun/core/llms/openai_test.py +30 -395
  82. langfun/core/llms/rest.py +113 -0
  83. langfun/core/llms/rest_test.py +111 -0
  84. langfun/core/llms/vertexai.py +192 -0
  85. langfun/core/llms/vertexai_test.py +52 -0
  86. langfun/core/logging.py +284 -0
  87. langfun/core/logging_test.py +125 -0
  88. langfun/core/message.py +319 -9
  89. langfun/core/message_test.py +190 -13
  90. langfun/core/modalities/__init__.py +6 -2
  91. langfun/core/modalities/audio.py +30 -0
  92. langfun/core/modalities/audio_test.py +63 -0
  93. langfun/core/modalities/image.py +39 -20
  94. langfun/core/modalities/image_test.py +52 -9
  95. langfun/core/modalities/mime.py +206 -29
  96. langfun/core/modalities/mime_test.py +90 -9
  97. langfun/core/modalities/ms_office.py +117 -0
  98. langfun/core/modalities/ms_office_test.py +389 -0
  99. langfun/core/modalities/pdf.py +22 -0
  100. langfun/core/modalities/pdf_test.py +57 -0
  101. langfun/core/modalities/video.py +9 -26
  102. langfun/core/modalities/video_test.py +3 -3
  103. langfun/core/modality.py +26 -3
  104. langfun/core/modality_test.py +2 -2
  105. langfun/core/sampling.py +11 -11
  106. langfun/core/structured/__init__.py +12 -16
  107. langfun/core/structured/completion.py +32 -5
  108. langfun/core/structured/completion_test.py +7 -6
  109. langfun/core/structured/description.py +2 -2
  110. langfun/core/structured/description_test.py +3 -3
  111. langfun/core/structured/function_generation.py +60 -27
  112. langfun/core/structured/function_generation_test.py +72 -2
  113. langfun/core/structured/mapping.py +97 -47
  114. langfun/core/structured/mapping_test.py +90 -2
  115. langfun/core/structured/parsing.py +33 -21
  116. langfun/core/structured/parsing_test.py +53 -9
  117. langfun/core/structured/querying.py +746 -0
  118. langfun/core/structured/{prompting_test.py → querying_test.py} +469 -51
  119. langfun/core/structured/schema.py +204 -97
  120. langfun/core/structured/schema_generation.py +1 -1
  121. langfun/core/structured/schema_test.py +130 -29
  122. langfun/core/structured/scoring.py +125 -19
  123. langfun/core/structured/scoring_test.py +30 -0
  124. langfun/core/structured/tokenization.py +64 -0
  125. langfun/core/structured/tokenization_test.py +48 -0
  126. langfun/core/template.py +115 -1
  127. langfun/core/template_test.py +71 -1
  128. langfun/core/templates/conversation.py +9 -0
  129. langfun/core/templates/conversation_test.py +4 -3
  130. langfun/core/templates/selfplay_test.py +10 -2
  131. langfun-0.1.2.dev202501150804.dist-info/METADATA +225 -0
  132. langfun-0.1.2.dev202501150804.dist-info/RECORD +153 -0
  133. {langfun-0.0.2.dev20240429.dist-info → langfun-0.1.2.dev202501150804.dist-info}/WHEEL +1 -1
  134. langfun/core/coding/python/errors.py +0 -108
  135. langfun/core/coding/python/errors_test.py +0 -99
  136. langfun/core/coding/python/permissions.py +0 -90
  137. langfun/core/coding/python/permissions_test.py +0 -86
  138. langfun/core/structured/prompting.py +0 -238
  139. langfun/core/text_formatting.py +0 -162
  140. langfun/core/text_formatting_test.py +0 -47
  141. langfun-0.0.2.dev20240429.dist-info/METADATA +0 -100
  142. langfun-0.0.2.dev20240429.dist-info/RECORD +0 -108
  143. {langfun-0.0.2.dev20240429.dist-info → langfun-0.1.2.dev202501150804.dist-info}/LICENSE +0 -0
  144. {langfun-0.0.2.dev20240429.dist-info → langfun-0.1.2.dev202501150804.dist-info}/top_level.txt +0 -0
langfun/__init__.py CHANGED
@@ -23,6 +23,8 @@ Schema = structured.Schema
23
23
  MISSING = structured.MISSING
24
24
  UNKNOWN = structured.UNKNOWN
25
25
 
26
+ include_method_in_prompt = structured.include_method_in_prompt
27
+
26
28
  MappingExample = structured.MappingExample
27
29
 
28
30
  call = structured.call
@@ -33,6 +35,16 @@ complete = structured.complete
33
35
  score = structured.score
34
36
  generate_class = structured.generate_class
35
37
 
38
+ track_queries = structured.track_queries
39
+
40
+ # Helper function for map-reduce style querying.
41
+ query_and_reduce = structured.query_and_reduce
42
+
43
+ # Helper functions for input/output transformations based on
44
+ # `lf.query` (e.g. jax-on-beam could use these for batch processing)
45
+ query_prompt = structured.query_prompt
46
+ query_output = structured.query_output
47
+
36
48
  source_form = structured.source_form
37
49
  function_gen = structured.function_gen
38
50
 
@@ -46,15 +58,21 @@ PythonFunction = coding.PythonFunction
46
58
  from langfun.core import llms
47
59
  lm_cache = llms.cache.lm_cache
48
60
 
61
+ from langfun.core import agentic
62
+ Action = agentic.Action
63
+ Session = agentic.Session
64
+
49
65
  from langfun.core import memories
50
66
 
51
67
  from langfun.core import modalities
52
68
 
69
+ Mime = modalities.Mime
70
+ MimeType = Mime # For backwards compatibility.
53
71
  Image = modalities.Image
54
72
  Video = modalities.Video
55
73
  PDF = modalities.PDF
56
74
 
57
- # Error types.
75
+ # Additional error types.
58
76
  MappingError = structured.MappingError
59
77
  SchemaError = structured.SchemaError
60
78
  JsonError = structured.JsonError
@@ -66,4 +84,4 @@ CodeError = coding.CodeError
66
84
  # pylint: enable=g-import-not-at-top
67
85
  # pylint: enable=g-bad-import-order
68
86
 
69
- __version__ = "0.0.2"
87
+ __version__ = "0.1.2"
langfun/core/__init__.py CHANGED
@@ -45,6 +45,7 @@ use_context = context
45
45
  from langfun.core.component import use_settings
46
46
 
47
47
  from langfun.core.component import get_contextual_override
48
+ from langfun.core.component import context_value
48
49
 
49
50
  # Value marker for attribute whose values will be provided from parent
50
51
  # objects or from the `pg.component_context` context manager.
@@ -71,16 +72,12 @@ from langfun.core.sampling import random_sample
71
72
 
72
73
  # Concurrent execute a function with parallel inputs with inheriting current
73
74
  # context's defaults and overrides.
75
+ from langfun.core.concurrent import RetryEntry
74
76
  from langfun.core.concurrent import concurrent_execute
75
77
  from langfun.core.concurrent import concurrent_map
76
78
  from langfun.core.concurrent import with_context_access
77
79
  from langfun.core.concurrent import with_retry
78
80
 
79
- # Utility libraries for text formatting.
80
- from langfun.core.text_formatting import colored
81
- from langfun.core.text_formatting import colored_print as print # pylint: disable=redefined-builtin
82
- from langfun.core.text_formatting import colored_template
83
-
84
81
  # Interface for natural language formattable.
85
82
  from langfun.core.natural_language import NaturalLanguageFormattable
86
83
 
@@ -94,23 +91,37 @@ from langfun.core.message import MemoryRecord
94
91
  # Interface for modality.
95
92
  from langfun.core.modality import Modality
96
93
  from langfun.core.modality import ModalityRef
94
+ from langfun.core.modality import ModalityError
97
95
 
98
96
  # Interfaces for languge models.
99
97
  from langfun.core.language_model import LanguageModel
100
98
  from langfun.core.language_model import LMSample
101
99
  from langfun.core.language_model import LMSamplingOptions
102
100
  from langfun.core.language_model import LMSamplingUsage
101
+ from langfun.core.language_model import UsageNotAvailable
102
+ from langfun.core.language_model import UsageSummary
103
103
  from langfun.core.language_model import LMSamplingResult
104
104
  from langfun.core.language_model import LMScoringResult
105
105
  from langfun.core.language_model import LMCache
106
106
  from langfun.core.language_model import LMDebugMode
107
107
 
108
+ from langfun.core.language_model import LMError
109
+ from langfun.core.language_model import RetryableLMError
110
+ from langfun.core.language_model import RateLimitError
111
+ from langfun.core.language_model import TemporaryLMError
112
+
113
+ # Context manager for tracking usages.
114
+ from langfun.core.language_model import track_usages
115
+
108
116
  # Components for building agents.
109
117
  from langfun.core.memory import Memory
110
118
 
111
119
  # Utility for console output.
112
120
  from langfun.core import console
113
121
 
122
+ # Utility for event logging.
123
+ from langfun.core import logging
124
+
114
125
  # Import internal modules.
115
126
 
116
127
  # pylint: enable=g-import-not-at-top
@@ -0,0 +1,30 @@
1
+ # Copyright 2024 The Langfun Authors
2
+ #
3
+ # Licensed under the Apache License, Version 2.0 (the "License");
4
+ # you may not use this file except in compliance with the License.
5
+ # You may obtain a copy of the License at
6
+ #
7
+ # http://www.apache.org/licenses/LICENSE-2.0
8
+ #
9
+ # Unless required by applicable law or agreed to in writing, software
10
+ # distributed under the License is distributed on an "AS IS" BASIS,
11
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12
+ # See the License for the specific language governing permissions and
13
+ # limitations under the License.
14
+ """Langfun agentic framework.."""
15
+
16
+ # pylint: disable=g-bad-import-order
17
+ # pylint: disable=g-importing-member
18
+ # pylint: disable=g-import-not-at-top
19
+
20
+ from langfun.core.agentic.action import Action
21
+ from langfun.core.agentic.action import ActionInvocation
22
+ from langfun.core.agentic.action import Session
23
+
24
+ from langfun.core.agentic.action_eval import ActionEval
25
+ from langfun.core.agentic.action_eval import ActionEvalV1
26
+
27
+
28
+ # pylint: enable=g-bad-import-order
29
+ # pylint: enable=g-importing-member
30
+ # pylint: enable=g-import-not-at-top