langfun 0.1.2.dev202502060804__py3-none-any.whl → 0.1.2.dev202502080803__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.
@@ -90,7 +90,7 @@ SUPPORTED_MODELS_AND_SETTINGS = {
90
90
  experimental=True,
91
91
  in_service=True,
92
92
  supported_modalities=ALL_MODALITIES,
93
- rpm_free=2000,
93
+ rpm_free=10_000,
94
94
  tpm_free=40_000_000,
95
95
  rpm_paid=0,
96
96
  tpm_paid=0,
@@ -106,32 +106,32 @@ SUPPORTED_MODELS_AND_SETTINGS = {
106
106
  experimental=True,
107
107
  in_service=True,
108
108
  supported_modalities=ALL_MODALITIES,
109
- rpm_free=2000,
109
+ rpm_free=10_000,
110
110
  tpm_free=40_000_000,
111
111
  rpm_paid=0,
112
112
  tpm_paid=0,
113
- cost_per_1m_input_tokens_up_to_128k=0,
114
- cost_per_1m_output_tokens_up_to_128k=0,
115
- cost_per_1m_cached_tokens_up_to_128k=0,
116
- cost_per_1m_input_tokens_longer_than_128k=0,
117
- cost_per_1m_output_tokens_longer_than_128k=0,
118
- cost_per_1m_cached_tokens_longer_than_128k=0,
113
+ cost_per_1m_input_tokens_up_to_128k=0.1,
114
+ cost_per_1m_output_tokens_up_to_128k=0.4,
115
+ cost_per_1m_cached_tokens_up_to_128k=0.025,
116
+ cost_per_1m_input_tokens_longer_than_128k=0.1,
117
+ cost_per_1m_output_tokens_longer_than_128k=0.4,
118
+ cost_per_1m_cached_tokens_longer_than_128k=0.025,
119
119
  ),
120
120
  'gemini-2.0-pro-exp-02-05': pg.Dict(
121
121
  latest_update='2025-02-05',
122
122
  experimental=True,
123
123
  in_service=True,
124
124
  supported_modalities=ALL_MODALITIES,
125
- rpm_free=1000,
126
- tpm_free=40_000_000,
125
+ rpm_free=10,
126
+ tpm_free=4_000_000,
127
127
  rpm_paid=0,
128
128
  tpm_paid=0,
129
- cost_per_1m_input_tokens_up_to_128k=0,
130
- cost_per_1m_output_tokens_up_to_128k=0,
131
- cost_per_1m_cached_tokens_up_to_128k=0,
132
- cost_per_1m_input_tokens_longer_than_128k=0,
133
- cost_per_1m_output_tokens_longer_than_128k=0,
134
- cost_per_1m_cached_tokens_longer_than_128k=0,
129
+ cost_per_1m_input_tokens_up_to_128k=0.1,
130
+ cost_per_1m_output_tokens_up_to_128k=0.4,
131
+ cost_per_1m_cached_tokens_up_to_128k=0.025,
132
+ cost_per_1m_input_tokens_longer_than_128k=0.1,
133
+ cost_per_1m_output_tokens_longer_than_128k=0.4,
134
+ cost_per_1m_cached_tokens_longer_than_128k=0.025,
135
135
  ),
136
136
  'gemini-2.0-flash-thinking-exp-01-21': pg.Dict(
137
137
  latest_update='2024-01-21',
langfun/core/llms/rest.py CHANGED
@@ -63,15 +63,14 @@ class REST(lf.LanguageModel):
63
63
  def _initialize(self) -> None:
64
64
  """Initializes the API. Subclasses can override."""
65
65
 
66
- @functools.cached_property
67
- def _session(self) -> requests.Session:
66
+ def session(self) -> requests.Session:
68
67
  assert self._api_initialized
69
- s = self._create_session()
68
+ s = self._session()
70
69
  # Placeholder for Google-internal session adapter.
71
70
  s.headers.update(self.headers or {})
72
71
  return s
73
72
 
74
- def _create_session(self) -> requests.Session:
73
+ def _session(self) -> requests.Session:
75
74
  """Creates a new session."""
76
75
  return requests.Session()
77
76
 
@@ -88,12 +87,14 @@ class REST(lf.LanguageModel):
88
87
 
89
88
  def _sample_single(self, prompt: lf.Message) -> lf.LMSamplingResult:
90
89
  try:
91
- response = self._session.post(
92
- self.api_endpoint,
93
- json=self.request(prompt, self.sampling_options),
94
- timeout=self.timeout,
95
- )
96
- return self._parse_response(response)
90
+ with self.session() as session:
91
+ return self._parse_response(
92
+ session.post(
93
+ self.api_endpoint,
94
+ json=self.request(prompt, self.sampling_options),
95
+ timeout=self.timeout,
96
+ )
97
+ )
97
98
  except (requests.exceptions.ReadTimeout,
98
99
  requests.exceptions.ConnectTimeout) as e:
99
100
  raise lf.TemporaryLMError(str(e)) from e
@@ -118,7 +118,7 @@ class VertexAI(rest.REST):
118
118
  """Returns a string to identify the model."""
119
119
  return f'VertexAI({self.model})'
120
120
 
121
- def _create_session(self):
121
+ def _session(self):
122
122
  assert self._credentials is not None
123
123
  assert auth_requests is not None
124
124
  return auth_requests.AuthorizedSession(self._credentials)
@@ -198,37 +198,43 @@ class VertexAIGeminiExp_20241114(VertexAIGemini): # pylint: disable=invalid-nam
198
198
  class VertexAIGeminiPro1_5(VertexAIGemini): # pylint: disable=invalid-name
199
199
  """Vertex AI Gemini 1.5 Pro model."""
200
200
 
201
- model = 'gemini-1.5-pro-latest'
201
+ model = 'gemini-1.5-pro-002'
202
+ location = 'us-central1'
202
203
 
203
204
 
204
205
  class VertexAIGeminiPro1_5_002(VertexAIGemini): # pylint: disable=invalid-name
205
206
  """Vertex AI Gemini 1.5 Pro model."""
206
207
 
207
208
  model = 'gemini-1.5-pro-002'
209
+ location = 'us-central1'
208
210
 
209
211
 
210
212
  class VertexAIGeminiPro1_5_001(VertexAIGemini): # pylint: disable=invalid-name
211
213
  """Vertex AI Gemini 1.5 Pro model."""
212
214
 
213
215
  model = 'gemini-1.5-pro-001'
216
+ location = 'us-central1'
214
217
 
215
218
 
216
219
  class VertexAIGeminiFlash1_5(VertexAIGemini): # pylint: disable=invalid-name
217
220
  """Vertex AI Gemini 1.5 Flash model."""
218
221
 
219
222
  model = 'gemini-1.5-flash'
223
+ location = 'us-central1'
220
224
 
221
225
 
222
226
  class VertexAIGeminiFlash1_5_002(VertexAIGemini): # pylint: disable=invalid-name
223
227
  """Vertex AI Gemini 1.5 Flash model."""
224
228
 
225
229
  model = 'gemini-1.5-flash-002'
230
+ location = 'us-central1'
226
231
 
227
232
 
228
233
  class VertexAIGeminiFlash1_5_001(VertexAIGemini): # pylint: disable=invalid-name
229
234
  """Vertex AI Gemini 1.5 Flash model."""
230
235
 
231
236
  model = 'gemini-1.5-flash-001'
237
+ location = 'us-central1'
232
238
 
233
239
 
234
240
  class VertexAIGeminiPro1(VertexAIGemini): # pylint: disable=invalid-name
@@ -45,7 +45,7 @@ class VertexAITest(unittest.TestCase):
45
45
  self.assertTrue(model.model_id.startswith('VertexAI('))
46
46
  self.assertIn('us-central1', model.api_endpoint)
47
47
  self.assertTrue(model._api_initialized)
48
- self.assertIsNotNone(model._session)
48
+ self.assertIsNotNone(model.session())
49
49
  del os.environ['VERTEXAI_PROJECT']
50
50
  del os.environ['VERTEXAI_LOCATION']
51
51
 
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.2
2
2
  Name: langfun
3
- Version: 0.1.2.dev202502060804
3
+ Version: 0.1.2.dev202502080803
4
4
  Summary: Langfun: Language as Functions.
5
5
  Home-page: https://github.com/google/langfun
6
6
  Author: Langfun Authors
@@ -82,7 +82,7 @@ langfun/core/llms/deepseek.py,sha256=9EbuNrngd5BwpsvsEfkW2XQdq3K23S3-jlI8RbMNZF4
82
82
  langfun/core/llms/deepseek_test.py,sha256=dS72i52bwMpCN4dJDvpJI59AnNChpwxS5eYYFrhGh90,1843
83
83
  langfun/core/llms/fake.py,sha256=gCHBYBLvBCsC78HI1hpoqXCS-p1FMTgY1P1qh_sGBPk,3070
84
84
  langfun/core/llms/fake_test.py,sha256=2h13qkwEz_JR0mtUDPxdAhQo7MueXaFSwsD2DIRDW9g,7653
85
- langfun/core/llms/gemini.py,sha256=oYcpQ3I7-c1MeSC7mj9iKtAZTdbWKI9Fzp84drvR5QY,19703
85
+ langfun/core/llms/gemini.py,sha256=jSwj9TQMDHkByr09hftq3CQozifjqwPwHfn-A64MIBg,19736
86
86
  langfun/core/llms/gemini_test.py,sha256=2ERhYWCJwnfDTQbCaZHFuB1TdWJFrOBS7yyCBInIdQk,6129
87
87
  langfun/core/llms/google_genai.py,sha256=WbVZAIDhh7mKy15LZMXOEniQ8Obd-hjiy2KviUCfmXQ,4261
88
88
  langfun/core/llms/google_genai_test.py,sha256=JZf_cbQ4GGGpwiQCLjFJn7V4jxBBqgZhIx91AzbGKVo,1250
@@ -94,10 +94,10 @@ langfun/core/llms/openai.py,sha256=bIJae2UDO_uwoZGZRYP58GM4FdP4w9qjQhBIYJyGH34,1
94
94
  langfun/core/llms/openai_compatible.py,sha256=MF9JCc0uTPkIK95uvQTMIBXk4z_xKQMZqQHFaVmXwcA,5898
95
95
  langfun/core/llms/openai_compatible_test.py,sha256=0uFYhCiuHo2Wrlgj16-GRG6rW8P6EaHCUguL3jS0QJ8,16708
96
96
  langfun/core/llms/openai_test.py,sha256=m85YjGCvWvV5ZYagjC0FqI0FcqyCEVCbUUs8Wm3iUrc,2475
97
- langfun/core/llms/rest.py,sha256=2N-zg9wuB-XeQvISc-xWOBCfBVvjMc4p3LO_rD23z7c,3818
97
+ langfun/core/llms/rest.py,sha256=46aGJghpQunwc3ju47V0N-1a1X4DydhwRBtRP9LBH2E,3828
98
98
  langfun/core/llms/rest_test.py,sha256=zWGiI08f9gXsoQPJS9TlX1zD2uQLrJUB-1VpAJXRHfs,3475
99
- langfun/core/llms/vertexai.py,sha256=zLiHHrm5gpE6DgC5k0cxugD2qui9MF8bhg-4aJDXB24,16364
100
- langfun/core/llms/vertexai_test.py,sha256=6eLQOyeL5iGZOIWb39sFcf1TgYD_6TBGYdMO4UIvhf4,3333
99
+ langfun/core/llms/vertexai.py,sha256=CYi_KbsNcMW4O4NR_zvBF0RykvuF3ACO0W4-uYV-1cE,16516
100
+ langfun/core/llms/vertexai_test.py,sha256=9LYv2equht9Vq-kwzdSZerENZjV9LYb4IIplSnfV5Os,3334
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
103
103
  langfun/core/llms/cache/in_memory.py,sha256=i58oiQL28RDsq37dwqgVpC2mBETJjIEFS20yHiV5MKU,5185
@@ -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.dev202502060804.dist-info/LICENSE,sha256=WNHhf_5RCaeuKWyq_K39vmp9F28LxKsB4SpomwSZ2L0,11357
152
- langfun-0.1.2.dev202502060804.dist-info/METADATA,sha256=tw5p6p7Pp2I6CbNWAJx1EcB-umB-X10YeiJnw8LS65o,8172
153
- langfun-0.1.2.dev202502060804.dist-info/WHEEL,sha256=In9FTNxeP60KnTkGw7wk6mJPYd_dQSjEZmXdBdMCI-8,91
154
- langfun-0.1.2.dev202502060804.dist-info/top_level.txt,sha256=RhlEkHxs1qtzmmtWSwYoLVJAc1YrbPtxQ52uh8Z9VvY,8
155
- langfun-0.1.2.dev202502060804.dist-info/RECORD,,
151
+ langfun-0.1.2.dev202502080803.dist-info/LICENSE,sha256=WNHhf_5RCaeuKWyq_K39vmp9F28LxKsB4SpomwSZ2L0,11357
152
+ langfun-0.1.2.dev202502080803.dist-info/METADATA,sha256=HwxvNwOrL6oliIMpZ9vm2dAU8E7BY5FGU6-8JpOmbkg,8172
153
+ langfun-0.1.2.dev202502080803.dist-info/WHEEL,sha256=In9FTNxeP60KnTkGw7wk6mJPYd_dQSjEZmXdBdMCI-8,91
154
+ langfun-0.1.2.dev202502080803.dist-info/top_level.txt,sha256=RhlEkHxs1qtzmmtWSwYoLVJAc1YrbPtxQ52uh8Z9VvY,8
155
+ langfun-0.1.2.dev202502080803.dist-info/RECORD,,