trustgraph-vertexai 1.5.6__tar.gz → 1.8.4__tar.gz

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.
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: trustgraph-vertexai
3
- Version: 1.5.6
3
+ Version: 1.8.4
4
4
  Summary: TrustGraph provides a means to run a pipeline of flexible AI processing components in a flexible means to achieve a processing pipeline.
5
5
  Author-email: "trustgraph.ai" <security@trustgraph.ai>
6
6
  Project-URL: Homepage, https://github.com/trustgraph-ai/trustgraph
@@ -8,7 +8,7 @@ Classifier: Programming Language :: Python :: 3
8
8
  Classifier: Operating System :: OS Independent
9
9
  Requires-Python: >=3.8
10
10
  Description-Content-Type: text/markdown
11
- Requires-Dist: trustgraph-base<1.6,>=1.5
11
+ Requires-Dist: trustgraph-base<1.9,>=1.8
12
12
  Requires-Dist: pulsar-client
13
13
  Requires-Dist: google-cloud-aiplatform
14
14
  Requires-Dist: prometheus-client
@@ -10,7 +10,7 @@ description = "TrustGraph provides a means to run a pipeline of flexible AI proc
10
10
  readme = "README.md"
11
11
  requires-python = ">=3.8"
12
12
  dependencies = [
13
- "trustgraph-base>=1.5,<1.6",
13
+ "trustgraph-base>=1.8,<1.9",
14
14
  "pulsar-client",
15
15
  "google-cloud-aiplatform",
16
16
  "prometheus-client",
@@ -32,7 +32,7 @@ from vertexai.generative_models import (
32
32
  from anthropic import AnthropicVertex, RateLimitError
33
33
 
34
34
  from .... exceptions import TooManyRequests
35
- from .... base import LlmService, LlmResult
35
+ from .... base import LlmService, LlmResult, LlmChunk
36
36
 
37
37
  # Module logger
38
38
  logger = logging.getLogger(__name__)
@@ -239,6 +239,123 @@ class Processor(LlmService):
239
239
  logger.error(f"VertexAI LLM exception: {e}", exc_info=True)
240
240
  raise e
241
241
 
242
+ def supports_streaming(self):
243
+ """VertexAI supports streaming for both Gemini and Claude models"""
244
+ return True
245
+
246
+ async def generate_content_stream(self, system, prompt, model=None, temperature=None):
247
+ """
248
+ Stream content generation from VertexAI (Gemini or Claude).
249
+ Yields LlmChunk objects with is_final=True on the last chunk.
250
+ """
251
+ # Use provided model or fall back to default
252
+ model_name = model or self.default_model
253
+ # Use provided temperature or fall back to default
254
+ effective_temperature = temperature if temperature is not None else self.temperature
255
+
256
+ logger.debug(f"Using model (streaming): {model_name}")
257
+ logger.debug(f"Using temperature: {effective_temperature}")
258
+
259
+ try:
260
+ if 'claude' in model_name.lower():
261
+ # Claude/Anthropic streaming
262
+ logger.debug(f"Streaming request to Anthropic model '{model_name}'...")
263
+ client = self._get_anthropic_client()
264
+
265
+ total_in_tokens = 0
266
+ total_out_tokens = 0
267
+
268
+ with client.messages.stream(
269
+ model=model_name,
270
+ system=system,
271
+ messages=[{"role": "user", "content": prompt}],
272
+ max_tokens=self.api_params['max_output_tokens'],
273
+ temperature=effective_temperature,
274
+ top_p=self.api_params['top_p'],
275
+ top_k=self.api_params['top_k'],
276
+ ) as stream:
277
+ # Stream text chunks
278
+ for text in stream.text_stream:
279
+ yield LlmChunk(
280
+ text=text,
281
+ in_token=None,
282
+ out_token=None,
283
+ model=model_name,
284
+ is_final=False
285
+ )
286
+
287
+ # Get final message with token counts
288
+ final_message = stream.get_final_message()
289
+ total_in_tokens = final_message.usage.input_tokens
290
+ total_out_tokens = final_message.usage.output_tokens
291
+
292
+ # Send final chunk with token counts
293
+ yield LlmChunk(
294
+ text="",
295
+ in_token=total_in_tokens,
296
+ out_token=total_out_tokens,
297
+ model=model_name,
298
+ is_final=True
299
+ )
300
+
301
+ logger.info(f"Input Tokens: {total_in_tokens}")
302
+ logger.info(f"Output Tokens: {total_out_tokens}")
303
+
304
+ else:
305
+ # Gemini streaming
306
+ logger.debug(f"Streaming request to Gemini model '{model_name}'...")
307
+ full_prompt = system + "\n\n" + prompt
308
+
309
+ llm, generation_config = self._get_gemini_model(model_name, effective_temperature)
310
+
311
+ response = llm.generate_content(
312
+ full_prompt,
313
+ generation_config=generation_config,
314
+ safety_settings=self.safety_settings,
315
+ stream=True # Enable streaming
316
+ )
317
+
318
+ total_in_tokens = 0
319
+ total_out_tokens = 0
320
+
321
+ # Stream chunks
322
+ for chunk in response:
323
+ if chunk.text:
324
+ yield LlmChunk(
325
+ text=chunk.text,
326
+ in_token=None,
327
+ out_token=None,
328
+ model=model_name,
329
+ is_final=False
330
+ )
331
+
332
+ # Accumulate token counts if available
333
+ if hasattr(chunk, 'usage_metadata') and chunk.usage_metadata:
334
+ if hasattr(chunk.usage_metadata, 'prompt_token_count'):
335
+ total_in_tokens = chunk.usage_metadata.prompt_token_count
336
+ if hasattr(chunk.usage_metadata, 'candidates_token_count'):
337
+ total_out_tokens = chunk.usage_metadata.candidates_token_count
338
+
339
+ # Send final chunk with token counts
340
+ yield LlmChunk(
341
+ text="",
342
+ in_token=total_in_tokens,
343
+ out_token=total_out_tokens,
344
+ model=model_name,
345
+ is_final=True
346
+ )
347
+
348
+ logger.info(f"Input Tokens: {total_in_tokens}")
349
+ logger.info(f"Output Tokens: {total_out_tokens}")
350
+
351
+ except (google.api_core.exceptions.ResourceExhausted, RateLimitError) as e:
352
+ logger.warning(f"Hit rate limit during streaming: {e}")
353
+ raise TooManyRequests()
354
+
355
+ except Exception as e:
356
+ logger.error(f"VertexAI streaming exception: {e}", exc_info=True)
357
+ raise e
358
+
242
359
  @staticmethod
243
360
  def add_args(parser):
244
361
 
@@ -0,0 +1 @@
1
+ __version__ = "1.8.4"
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: trustgraph-vertexai
3
- Version: 1.5.6
3
+ Version: 1.8.4
4
4
  Summary: TrustGraph provides a means to run a pipeline of flexible AI processing components in a flexible means to achieve a processing pipeline.
5
5
  Author-email: "trustgraph.ai" <security@trustgraph.ai>
6
6
  Project-URL: Homepage, https://github.com/trustgraph-ai/trustgraph
@@ -8,7 +8,7 @@ Classifier: Programming Language :: Python :: 3
8
8
  Classifier: Operating System :: OS Independent
9
9
  Requires-Python: >=3.8
10
10
  Description-Content-Type: text/markdown
11
- Requires-Dist: trustgraph-base<1.6,>=1.5
11
+ Requires-Dist: trustgraph-base<1.9,>=1.8
12
12
  Requires-Dist: pulsar-client
13
13
  Requires-Dist: google-cloud-aiplatform
14
14
  Requires-Dist: prometheus-client
@@ -1,4 +1,4 @@
1
- trustgraph-base<1.6,>=1.5
1
+ trustgraph-base<1.9,>=1.8
2
2
  pulsar-client
3
3
  google-cloud-aiplatform
4
4
  prometheus-client
@@ -1 +0,0 @@
1
- __version__ = "1.5.6"