langfun 0.0.2.dev20240330__py3-none-any.whl → 0.1.2.dev202501140804__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 (145) hide show
  1. langfun/__init__.py +22 -2
  2. langfun/core/__init__.py +17 -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 -28
  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 +69 -2
  18. langfun/core/component_test.py +54 -0
  19. langfun/core/concurrent.py +414 -117
  20. langfun/core/concurrent_test.py +111 -24
  21. langfun/core/console.py +18 -5
  22. langfun/core/console_test.py +17 -0
  23. langfun/core/eval/__init__.py +17 -0
  24. langfun/core/eval/base.py +767 -140
  25. langfun/core/eval/base_test.py +238 -53
  26. langfun/core/eval/matching.py +80 -76
  27. langfun/core/eval/matching_test.py +19 -9
  28. langfun/core/eval/patching.py +130 -0
  29. langfun/core/eval/patching_test.py +170 -0
  30. langfun/core/eval/scoring.py +37 -28
  31. langfun/core/eval/scoring_test.py +21 -3
  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 +3 -21
  55. langfun/core/langfunc_test.py +26 -8
  56. langfun/core/language_model.py +686 -48
  57. langfun/core/language_model_test.py +681 -44
  58. langfun/core/llms/__init__.py +100 -12
  59. langfun/core/llms/anthropic.py +488 -0
  60. langfun/core/llms/anthropic_test.py +235 -0
  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 +88 -28
  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 +39 -26
  69. langfun/core/llms/fake_test.py +136 -11
  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 -197
  74. langfun/core/llms/groq.py +276 -0
  75. langfun/core/llms/groq_test.py +64 -0
  76. langfun/core/llms/llama_cpp.py +15 -40
  77. langfun/core/llms/llama_cpp_test.py +4 -30
  78. langfun/core/llms/openai.py +436 -226
  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 +35 -174
  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 -23
  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 +15 -16
  107. langfun/core/structured/completion.py +32 -5
  108. langfun/core/structured/completion_test.py +9 -8
  109. langfun/core/structured/description.py +2 -2
  110. langfun/core/structured/description_test.py +3 -3
  111. langfun/core/structured/function_generation.py +278 -0
  112. langfun/core/structured/function_generation_test.py +399 -0
  113. langfun/core/structured/mapping.py +150 -46
  114. langfun/core/structured/mapping_test.py +105 -0
  115. langfun/core/structured/parsing.py +33 -21
  116. langfun/core/structured/parsing_test.py +71 -22
  117. langfun/core/structured/querying.py +746 -0
  118. langfun/core/structured/{prompting_test.py → querying_test.py} +545 -60
  119. langfun/core/structured/schema.py +208 -99
  120. langfun/core/structured/schema_generation.py +1 -1
  121. langfun/core/structured/schema_generation_test.py +2 -2
  122. langfun/core/structured/schema_test.py +133 -34
  123. langfun/core/structured/scoring.py +125 -19
  124. langfun/core/structured/scoring_test.py +30 -0
  125. langfun/core/structured/tokenization.py +64 -0
  126. langfun/core/structured/tokenization_test.py +48 -0
  127. langfun/core/template.py +240 -11
  128. langfun/core/template_test.py +146 -1
  129. langfun/core/templates/conversation.py +9 -0
  130. langfun/core/templates/conversation_test.py +4 -3
  131. langfun/core/templates/selfplay_test.py +14 -2
  132. langfun-0.1.2.dev202501140804.dist-info/METADATA +225 -0
  133. langfun-0.1.2.dev202501140804.dist-info/RECORD +153 -0
  134. {langfun-0.0.2.dev20240330.dist-info → langfun-0.1.2.dev202501140804.dist-info}/WHEEL +1 -1
  135. langfun/core/coding/python/errors.py +0 -108
  136. langfun/core/coding/python/errors_test.py +0 -99
  137. langfun/core/coding/python/permissions.py +0 -90
  138. langfun/core/coding/python/permissions_test.py +0 -86
  139. langfun/core/structured/prompting.py +0 -217
  140. langfun/core/text_formatting.py +0 -162
  141. langfun/core/text_formatting_test.py +0 -47
  142. langfun-0.0.2.dev20240330.dist-info/METADATA +0 -99
  143. langfun-0.0.2.dev20240330.dist-info/RECORD +0 -102
  144. {langfun-0.0.2.dev20240330.dist-info → langfun-0.1.2.dev202501140804.dist-info}/LICENSE +0 -0
  145. {langfun-0.0.2.dev20240330.dist-info → langfun-0.1.2.dev202501140804.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,7 +35,18 @@ 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
49
+ function_gen = structured.function_gen
37
50
 
38
51
  from langfun.core import eval # pylint: disable=redefined-builtin
39
52
  from langfun.core import templates
@@ -45,15 +58,22 @@ PythonFunction = coding.PythonFunction
45
58
  from langfun.core import llms
46
59
  lm_cache = llms.cache.lm_cache
47
60
 
61
+ from langfun.core import agentic
62
+ Action = agentic.Action
63
+ Session = agentic.Session
64
+
48
65
  from langfun.core import memories
49
66
 
50
67
  from langfun.core import modalities
51
68
 
69
+ Mime = modalities.Mime
70
+ MimeType = Mime # For backwards compatibility.
52
71
  Image = modalities.Image
53
72
  Video = modalities.Video
54
73
  PDF = modalities.PDF
55
74
 
56
- # Error types.
75
+ # Additional error types.
76
+ MappingError = structured.MappingError
57
77
  SchemaError = structured.SchemaError
58
78
  JsonError = structured.JsonError
59
79
  CodeError = coding.CodeError
@@ -64,4 +84,4 @@ CodeError = coding.CodeError
64
84
  # pylint: enable=g-import-not-at-top
65
85
  # pylint: enable=g-bad-import-order
66
86
 
67
- __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,22 +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
100
+ from langfun.core.language_model import LMSamplingUsage
101
+ from langfun.core.language_model import UsageNotAvailable
102
+ from langfun.core.language_model import UsageSummary
102
103
  from langfun.core.language_model import LMSamplingResult
103
104
  from langfun.core.language_model import LMScoringResult
104
105
  from langfun.core.language_model import LMCache
105
106
  from langfun.core.language_model import LMDebugMode
106
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
+
107
116
  # Components for building agents.
108
117
  from langfun.core.memory import Memory
109
118
 
110
119
  # Utility for console output.
111
120
  from langfun.core import console
112
121
 
122
+ # Utility for event logging.
123
+ from langfun.core import logging
124
+
113
125
  # Import internal modules.
114
126
 
115
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