openaivec 0.13.4__py3-none-any.whl → 0.13.6__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.
- openaivec/embeddings.py +10 -8
- openaivec/model.py +9 -11
- openaivec/optimize.py +1 -1
- openaivec/pandas_ext.py +61 -42
- openaivec/prompt.py +58 -8
- openaivec/provider.py +10 -0
- openaivec/proxy.py +82 -65
- openaivec/responses.py +35 -18
- openaivec/spark.py +40 -34
- openaivec/task/customer_support/inquiry_classification.py +9 -9
- openaivec/task/customer_support/urgency_analysis.py +13 -13
- openaivec/task/nlp/keyword_extraction.py +2 -2
- openaivec/task/nlp/named_entity_recognition.py +2 -2
- openaivec/util.py +2 -2
- {openaivec-0.13.4.dist-info → openaivec-0.13.6.dist-info}/METADATA +9 -9
- {openaivec-0.13.4.dist-info → openaivec-0.13.6.dist-info}/RECORD +18 -18
- {openaivec-0.13.4.dist-info → openaivec-0.13.6.dist-info}/WHEEL +0 -0
- {openaivec-0.13.4.dist-info → openaivec-0.13.6.dist-info}/licenses/LICENSE +0 -0
openaivec/spark.py
CHANGED
|
@@ -115,7 +115,7 @@ Note: This module provides asynchronous support through the pandas extensions.
|
|
|
115
115
|
import asyncio
|
|
116
116
|
import logging
|
|
117
117
|
from enum import Enum
|
|
118
|
-
from typing import Dict, Iterator, List,
|
|
118
|
+
from typing import Dict, Iterator, List, Type, Union, get_args, get_origin
|
|
119
119
|
|
|
120
120
|
import numpy as np
|
|
121
121
|
import pandas as pd
|
|
@@ -198,7 +198,7 @@ def _pydantic_to_spark_schema(model: Type[BaseModel]) -> StructType:
|
|
|
198
198
|
return StructType(fields)
|
|
199
199
|
|
|
200
200
|
|
|
201
|
-
def _safe_cast_str(x:
|
|
201
|
+
def _safe_cast_str(x: str | None) -> str | None:
|
|
202
202
|
try:
|
|
203
203
|
if x is None:
|
|
204
204
|
return None
|
|
@@ -209,7 +209,7 @@ def _safe_cast_str(x: Optional[str]) -> Optional[str]:
|
|
|
209
209
|
return None
|
|
210
210
|
|
|
211
211
|
|
|
212
|
-
def _safe_dump(x:
|
|
212
|
+
def _safe_dump(x: BaseModel | None) -> Dict:
|
|
213
213
|
try:
|
|
214
214
|
if x is None:
|
|
215
215
|
return {}
|
|
@@ -224,7 +224,7 @@ def responses_udf(
|
|
|
224
224
|
instructions: str,
|
|
225
225
|
response_format: Type[ResponseFormat] = str,
|
|
226
226
|
model_name: str = "gpt-4.1-mini",
|
|
227
|
-
batch_size: int =
|
|
227
|
+
batch_size: int | None = None,
|
|
228
228
|
temperature: float | None = 0.0,
|
|
229
229
|
top_p: float = 1.0,
|
|
230
230
|
max_concurrency: int = 8,
|
|
@@ -255,9 +255,11 @@ def responses_udf(
|
|
|
255
255
|
or a Pydantic `BaseModel` for structured JSON output. Defaults to `str`.
|
|
256
256
|
model_name (str): For Azure OpenAI, use your deployment name (e.g., "my-gpt4-deployment").
|
|
257
257
|
For OpenAI, use the model name (e.g., "gpt-4.1-mini"). Defaults to "gpt-4.1-mini".
|
|
258
|
-
batch_size (int): Number of rows per async batch request within each partition.
|
|
258
|
+
batch_size (int | None): Number of rows per async batch request within each partition.
|
|
259
259
|
Larger values reduce API call overhead but increase memory usage.
|
|
260
|
-
|
|
260
|
+
Defaults to None (automatic batch size optimization that dynamically
|
|
261
|
+
adjusts based on execution time, targeting 30-60 seconds per batch).
|
|
262
|
+
Set to a positive integer (e.g., 32-128) for fixed batch size.
|
|
261
263
|
temperature (float): Sampling temperature (0.0 to 2.0). Defaults to 0.0.
|
|
262
264
|
top_p (float): Nucleus sampling parameter. Defaults to 1.0.
|
|
263
265
|
max_concurrency (int): Maximum number of concurrent API requests **PER EXECUTOR**.
|
|
@@ -284,7 +286,7 @@ def responses_udf(
|
|
|
284
286
|
spark_schema = _pydantic_to_spark_schema(response_format)
|
|
285
287
|
json_schema_string = serialize_base_model(response_format)
|
|
286
288
|
|
|
287
|
-
@pandas_udf(returnType=spark_schema)
|
|
289
|
+
@pandas_udf(returnType=spark_schema) # type: ignore[call-overload]
|
|
288
290
|
def structure_udf(col: Iterator[pd.Series]) -> Iterator[pd.DataFrame]:
|
|
289
291
|
pandas_ext.responses_model(model_name)
|
|
290
292
|
response_format = deserialize_base_model(json_schema_string)
|
|
@@ -306,13 +308,13 @@ def responses_udf(
|
|
|
306
308
|
)
|
|
307
309
|
yield pd.DataFrame(predictions.map(_safe_dump).tolist())
|
|
308
310
|
finally:
|
|
309
|
-
cache.clear()
|
|
311
|
+
asyncio.run(cache.clear())
|
|
310
312
|
|
|
311
|
-
return structure_udf
|
|
313
|
+
return structure_udf # type: ignore[return-value]
|
|
312
314
|
|
|
313
315
|
elif issubclass(response_format, str):
|
|
314
316
|
|
|
315
|
-
@pandas_udf(returnType=StringType())
|
|
317
|
+
@pandas_udf(returnType=StringType()) # type: ignore[call-overload]
|
|
316
318
|
def string_udf(col: Iterator[pd.Series]) -> Iterator[pd.Series]:
|
|
317
319
|
pandas_ext.responses_model(model_name)
|
|
318
320
|
cache = AsyncBatchingMapProxy[str, str](
|
|
@@ -333,18 +335,18 @@ def responses_udf(
|
|
|
333
335
|
)
|
|
334
336
|
yield predictions.map(_safe_cast_str)
|
|
335
337
|
finally:
|
|
336
|
-
cache.clear()
|
|
338
|
+
asyncio.run(cache.clear())
|
|
337
339
|
|
|
338
|
-
return string_udf
|
|
340
|
+
return string_udf # type: ignore[return-value]
|
|
339
341
|
|
|
340
342
|
else:
|
|
341
343
|
raise ValueError(f"Unsupported response_format: {response_format}")
|
|
342
344
|
|
|
343
345
|
|
|
344
346
|
def task_udf(
|
|
345
|
-
task: PreparedTask,
|
|
347
|
+
task: PreparedTask[ResponseFormat],
|
|
346
348
|
model_name: str = "gpt-4.1-mini",
|
|
347
|
-
batch_size: int =
|
|
349
|
+
batch_size: int | None = None,
|
|
348
350
|
max_concurrency: int = 8,
|
|
349
351
|
) -> UserDefinedFunction:
|
|
350
352
|
"""Create an asynchronous Spark pandas UDF from a predefined task.
|
|
@@ -360,9 +362,11 @@ def task_udf(
|
|
|
360
362
|
response format, temperature, and top_p settings.
|
|
361
363
|
model_name (str): For Azure OpenAI, use your deployment name (e.g., "my-gpt4-deployment").
|
|
362
364
|
For OpenAI, use the model name (e.g., "gpt-4.1-mini"). Defaults to "gpt-4.1-mini".
|
|
363
|
-
batch_size (int): Number of rows per async batch request within each partition.
|
|
365
|
+
batch_size (int | None): Number of rows per async batch request within each partition.
|
|
364
366
|
Larger values reduce API call overhead but increase memory usage.
|
|
365
|
-
|
|
367
|
+
Defaults to None (automatic batch size optimization that dynamically
|
|
368
|
+
adjusts based on execution time, targeting 30-60 seconds per batch).
|
|
369
|
+
Set to a positive integer (e.g., 32-128) for fixed batch size.
|
|
366
370
|
max_concurrency (int): Maximum number of concurrent API requests **PER EXECUTOR**.
|
|
367
371
|
Total cluster concurrency = max_concurrency × number_of_executors.
|
|
368
372
|
Higher values increase throughput but may hit OpenAI rate limits.
|
|
@@ -399,7 +403,7 @@ def task_udf(
|
|
|
399
403
|
response_format = deserialize_base_model(task_response_format_json)
|
|
400
404
|
spark_schema = _pydantic_to_spark_schema(response_format)
|
|
401
405
|
|
|
402
|
-
@pandas_udf(returnType=spark_schema)
|
|
406
|
+
@pandas_udf(returnType=spark_schema) # type: ignore[call-overload]
|
|
403
407
|
def task_udf(col: Iterator[pd.Series]) -> Iterator[pd.DataFrame]:
|
|
404
408
|
pandas_ext.responses_model(model_name)
|
|
405
409
|
cache = AsyncBatchingMapProxy[str, response_format](
|
|
@@ -420,13 +424,13 @@ def task_udf(
|
|
|
420
424
|
)
|
|
421
425
|
yield pd.DataFrame(predictions.map(_safe_dump).tolist())
|
|
422
426
|
finally:
|
|
423
|
-
cache.clear()
|
|
427
|
+
asyncio.run(cache.clear())
|
|
424
428
|
|
|
425
|
-
return task_udf
|
|
429
|
+
return task_udf # type: ignore[return-value]
|
|
426
430
|
|
|
427
431
|
elif issubclass(task.response_format, str):
|
|
428
432
|
|
|
429
|
-
@pandas_udf(returnType=StringType())
|
|
433
|
+
@pandas_udf(returnType=StringType()) # type: ignore[call-overload]
|
|
430
434
|
def task_string_udf(col: Iterator[pd.Series]) -> Iterator[pd.Series]:
|
|
431
435
|
pandas_ext.responses_model(model_name)
|
|
432
436
|
cache = AsyncBatchingMapProxy[str, str](
|
|
@@ -447,16 +451,16 @@ def task_udf(
|
|
|
447
451
|
)
|
|
448
452
|
yield predictions.map(_safe_cast_str)
|
|
449
453
|
finally:
|
|
450
|
-
cache.clear()
|
|
454
|
+
asyncio.run(cache.clear())
|
|
451
455
|
|
|
452
|
-
return task_string_udf
|
|
456
|
+
return task_string_udf # type: ignore[return-value]
|
|
453
457
|
|
|
454
458
|
else:
|
|
455
459
|
raise ValueError(f"Unsupported response_format in task: {task.response_format}")
|
|
456
460
|
|
|
457
461
|
|
|
458
462
|
def embeddings_udf(
|
|
459
|
-
model_name: str = "text-embedding-3-small", batch_size: int =
|
|
463
|
+
model_name: str = "text-embedding-3-small", batch_size: int | None = None, max_concurrency: int = 8
|
|
460
464
|
) -> UserDefinedFunction:
|
|
461
465
|
"""Create an asynchronous Spark pandas UDF for generating embeddings.
|
|
462
466
|
|
|
@@ -481,10 +485,12 @@ def embeddings_udf(
|
|
|
481
485
|
Args:
|
|
482
486
|
model_name (str): For Azure OpenAI, use your deployment name (e.g., "my-embedding-deployment").
|
|
483
487
|
For OpenAI, use the model name (e.g., "text-embedding-3-small"). Defaults to "text-embedding-3-small".
|
|
484
|
-
batch_size (int): Number of rows per async batch request within each partition.
|
|
488
|
+
batch_size (int | None): Number of rows per async batch request within each partition.
|
|
485
489
|
Larger values reduce API call overhead but increase memory usage.
|
|
490
|
+
Defaults to None (automatic batch size optimization that dynamically
|
|
491
|
+
adjusts based on execution time, targeting 30-60 seconds per batch).
|
|
492
|
+
Set to a positive integer (e.g., 64-256) for fixed batch size.
|
|
486
493
|
Embeddings typically handle larger batches efficiently.
|
|
487
|
-
Recommended: 64-256 depending on text length. Defaults to 128.
|
|
488
494
|
max_concurrency (int): Maximum number of concurrent API requests **PER EXECUTOR**.
|
|
489
495
|
Total cluster concurrency = max_concurrency × number_of_executors.
|
|
490
496
|
Higher values increase throughput but may hit OpenAI rate limits.
|
|
@@ -505,7 +511,7 @@ def embeddings_udf(
|
|
|
505
511
|
- Use larger batch_size for embeddings compared to response generation
|
|
506
512
|
"""
|
|
507
513
|
|
|
508
|
-
@pandas_udf(returnType=ArrayType(FloatType()))
|
|
514
|
+
@pandas_udf(returnType=ArrayType(FloatType())) # type: ignore[call-overload,misc]
|
|
509
515
|
def _embeddings_udf(col: Iterator[pd.Series]) -> Iterator[pd.Series]:
|
|
510
516
|
pandas_ext.embeddings_model(model_name)
|
|
511
517
|
cache = AsyncBatchingMapProxy[str, np.ndarray](
|
|
@@ -518,9 +524,9 @@ def embeddings_udf(
|
|
|
518
524
|
embeddings: pd.Series = asyncio.run(part.aio.embeddings_with_cache(cache=cache))
|
|
519
525
|
yield embeddings.map(lambda x: x.tolist())
|
|
520
526
|
finally:
|
|
521
|
-
cache.clear()
|
|
527
|
+
asyncio.run(cache.clear())
|
|
522
528
|
|
|
523
|
-
return _embeddings_udf
|
|
529
|
+
return _embeddings_udf # type: ignore[return-value]
|
|
524
530
|
|
|
525
531
|
|
|
526
532
|
def split_to_chunks_udf(max_tokens: int, sep: List[str]) -> UserDefinedFunction:
|
|
@@ -535,7 +541,7 @@ def split_to_chunks_udf(max_tokens: int, sep: List[str]) -> UserDefinedFunction:
|
|
|
535
541
|
values are lists of chunks respecting the ``max_tokens`` limit.
|
|
536
542
|
"""
|
|
537
543
|
|
|
538
|
-
@pandas_udf(ArrayType(StringType()))
|
|
544
|
+
@pandas_udf(ArrayType(StringType())) # type: ignore[call-overload,misc]
|
|
539
545
|
def fn(col: Iterator[pd.Series]) -> Iterator[pd.Series]:
|
|
540
546
|
encoding = tiktoken.get_encoding("o200k_base")
|
|
541
547
|
chunker = TextChunker(encoding)
|
|
@@ -543,7 +549,7 @@ def split_to_chunks_udf(max_tokens: int, sep: List[str]) -> UserDefinedFunction:
|
|
|
543
549
|
for part in col:
|
|
544
550
|
yield part.map(lambda x: chunker.split(x, max_tokens=max_tokens, sep=sep) if isinstance(x, str) else [])
|
|
545
551
|
|
|
546
|
-
return fn
|
|
552
|
+
return fn # type: ignore[return-value]
|
|
547
553
|
|
|
548
554
|
|
|
549
555
|
def count_tokens_udf() -> UserDefinedFunction:
|
|
@@ -556,18 +562,18 @@ def count_tokens_udf() -> UserDefinedFunction:
|
|
|
556
562
|
A pandas UDF producing an ``IntegerType`` column with token counts.
|
|
557
563
|
"""
|
|
558
564
|
|
|
559
|
-
@pandas_udf(IntegerType())
|
|
565
|
+
@pandas_udf(IntegerType()) # type: ignore[call-overload]
|
|
560
566
|
def fn(col: Iterator[pd.Series]) -> Iterator[pd.Series]:
|
|
561
567
|
encoding = tiktoken.get_encoding("o200k_base")
|
|
562
568
|
|
|
563
569
|
for part in col:
|
|
564
570
|
yield part.map(lambda x: len(encoding.encode(x)) if isinstance(x, str) else 0)
|
|
565
571
|
|
|
566
|
-
return fn
|
|
572
|
+
return fn # type: ignore[return-value]
|
|
567
573
|
|
|
568
574
|
|
|
569
575
|
def similarity_udf() -> UserDefinedFunction:
|
|
570
|
-
@pandas_udf(FloatType())
|
|
576
|
+
@pandas_udf(FloatType()) # type: ignore[call-overload]
|
|
571
577
|
def fn(a: pd.Series, b: pd.Series) -> pd.Series:
|
|
572
578
|
"""Compute cosine similarity between two vectors.
|
|
573
579
|
|
|
@@ -583,4 +589,4 @@ def similarity_udf() -> UserDefinedFunction:
|
|
|
583
589
|
|
|
584
590
|
return pd.DataFrame({"a": a, "b": b}).ai.similarity("a", "b")
|
|
585
591
|
|
|
586
|
-
return fn
|
|
592
|
+
return fn # type: ignore[return-value]
|
|
@@ -92,7 +92,7 @@ Example:
|
|
|
92
92
|
```
|
|
93
93
|
"""
|
|
94
94
|
|
|
95
|
-
from typing import Dict, List, Literal
|
|
95
|
+
from typing import Dict, List, Literal
|
|
96
96
|
|
|
97
97
|
from pydantic import BaseModel, Field
|
|
98
98
|
|
|
@@ -114,25 +114,25 @@ class InquiryClassification(BaseModel):
|
|
|
114
114
|
|
|
115
115
|
|
|
116
116
|
def inquiry_classification(
|
|
117
|
-
categories:
|
|
118
|
-
routing_rules:
|
|
119
|
-
priority_rules:
|
|
117
|
+
categories: Dict[str, List[str]] | None = None,
|
|
118
|
+
routing_rules: Dict[str, str] | None = None,
|
|
119
|
+
priority_rules: Dict[str, str] | None = None,
|
|
120
120
|
business_context: str = "general customer support",
|
|
121
|
-
custom_keywords:
|
|
121
|
+
custom_keywords: Dict[str, List[str]] | None = None,
|
|
122
122
|
temperature: float = 0.0,
|
|
123
123
|
top_p: float = 1.0,
|
|
124
124
|
) -> PreparedTask:
|
|
125
125
|
"""Create a configurable inquiry classification task.
|
|
126
126
|
|
|
127
127
|
Args:
|
|
128
|
-
categories (
|
|
128
|
+
categories (Dict[str, List[str]] | None): Dictionary mapping category names to lists of subcategories.
|
|
129
129
|
Default provides standard support categories.
|
|
130
|
-
routing_rules (
|
|
130
|
+
routing_rules (Dict[str, str] | None): Dictionary mapping categories to routing destinations.
|
|
131
131
|
Default provides standard routing options.
|
|
132
|
-
priority_rules (
|
|
132
|
+
priority_rules (Dict[str, str] | None): Dictionary mapping keywords/patterns to priority levels.
|
|
133
133
|
Default uses standard priority indicators.
|
|
134
134
|
business_context (str): Description of the business context to help with classification.
|
|
135
|
-
custom_keywords (
|
|
135
|
+
custom_keywords (Dict[str, List[str]] | None): Dictionary mapping categories to relevant keywords.
|
|
136
136
|
temperature (float): Sampling temperature (0.0-1.0).
|
|
137
137
|
top_p (float): Nucleus sampling parameter (0.0-1.0).
|
|
138
138
|
|
|
@@ -96,7 +96,7 @@ Example:
|
|
|
96
96
|
```
|
|
97
97
|
"""
|
|
98
98
|
|
|
99
|
-
from typing import Dict, List, Literal
|
|
99
|
+
from typing import Dict, List, Literal
|
|
100
100
|
|
|
101
101
|
from pydantic import BaseModel, Field
|
|
102
102
|
|
|
@@ -127,28 +127,28 @@ class UrgencyAnalysis(BaseModel):
|
|
|
127
127
|
|
|
128
128
|
|
|
129
129
|
def urgency_analysis(
|
|
130
|
-
urgency_levels:
|
|
131
|
-
response_times:
|
|
132
|
-
customer_tiers:
|
|
133
|
-
escalation_rules:
|
|
134
|
-
urgency_keywords:
|
|
130
|
+
urgency_levels: Dict[str, str] | None = None,
|
|
131
|
+
response_times: Dict[str, str] | None = None,
|
|
132
|
+
customer_tiers: Dict[str, str] | None = None,
|
|
133
|
+
escalation_rules: Dict[str, str] | None = None,
|
|
134
|
+
urgency_keywords: Dict[str, List[str]] | None = None,
|
|
135
135
|
business_context: str = "general customer support",
|
|
136
136
|
business_hours: str = "24/7 support",
|
|
137
|
-
sla_rules:
|
|
137
|
+
sla_rules: Dict[str, str] | None = None,
|
|
138
138
|
temperature: float = 0.0,
|
|
139
139
|
top_p: float = 1.0,
|
|
140
140
|
) -> PreparedTask:
|
|
141
141
|
"""Create a configurable urgency analysis task.
|
|
142
142
|
|
|
143
143
|
Args:
|
|
144
|
-
urgency_levels (
|
|
145
|
-
response_times (
|
|
146
|
-
customer_tiers (
|
|
147
|
-
escalation_rules (
|
|
148
|
-
urgency_keywords (
|
|
144
|
+
urgency_levels (Dict[str, str] | None): Dictionary mapping urgency levels to descriptions.
|
|
145
|
+
response_times (Dict[str, str] | None): Dictionary mapping urgency levels to response times.
|
|
146
|
+
customer_tiers (Dict[str, str] | None): Dictionary mapping tier names to descriptions.
|
|
147
|
+
escalation_rules (Dict[str, str] | None): Dictionary mapping conditions to escalation actions.
|
|
148
|
+
urgency_keywords (Dict[str, List[str]] | None): Dictionary mapping urgency levels to indicator keywords.
|
|
149
149
|
business_context (str): Description of the business context.
|
|
150
150
|
business_hours (str): Description of business hours for response time calculation.
|
|
151
|
-
sla_rules (
|
|
151
|
+
sla_rules (Dict[str, str] | None): Dictionary mapping customer tiers to SLA requirements.
|
|
152
152
|
temperature (float): Sampling temperature (0.0-1.0).
|
|
153
153
|
top_p (float): Nucleus sampling parameter (0.0-1.0).
|
|
154
154
|
|
|
@@ -50,7 +50,7 @@ Attributes:
|
|
|
50
50
|
top_p=1.0 for deterministic output.
|
|
51
51
|
"""
|
|
52
52
|
|
|
53
|
-
from typing import List
|
|
53
|
+
from typing import List
|
|
54
54
|
|
|
55
55
|
from pydantic import BaseModel, Field
|
|
56
56
|
|
|
@@ -63,7 +63,7 @@ class Keyword(BaseModel):
|
|
|
63
63
|
text: str = Field(description="The keyword or phrase")
|
|
64
64
|
score: float = Field(description="Importance score (0.0-1.0)")
|
|
65
65
|
frequency: int = Field(description="Frequency of occurrence in the text")
|
|
66
|
-
context:
|
|
66
|
+
context: str | None = Field(description="Context where the keyword appears")
|
|
67
67
|
|
|
68
68
|
|
|
69
69
|
class KeywordExtraction(BaseModel):
|
|
@@ -48,7 +48,7 @@ Attributes:
|
|
|
48
48
|
top_p=1.0 for deterministic output.
|
|
49
49
|
"""
|
|
50
50
|
|
|
51
|
-
from typing import List
|
|
51
|
+
from typing import List
|
|
52
52
|
|
|
53
53
|
from pydantic import BaseModel, Field
|
|
54
54
|
|
|
@@ -62,7 +62,7 @@ class NamedEntity(BaseModel):
|
|
|
62
62
|
label: str = Field(description="Entity type label")
|
|
63
63
|
start: int = Field(description="Start position in the original text")
|
|
64
64
|
end: int = Field(description="End position in the original text")
|
|
65
|
-
confidence:
|
|
65
|
+
confidence: float | None = Field(description="Confidence score (0.0-1.0)")
|
|
66
66
|
|
|
67
67
|
|
|
68
68
|
class NamedEntityRecognition(BaseModel):
|
openaivec/util.py
CHANGED
|
@@ -82,7 +82,7 @@ def backoff(
|
|
|
82
82
|
|
|
83
83
|
return wrapper
|
|
84
84
|
|
|
85
|
-
return decorator
|
|
85
|
+
return decorator # type: ignore[return-value]
|
|
86
86
|
|
|
87
87
|
|
|
88
88
|
def backoff_async(
|
|
@@ -134,7 +134,7 @@ def backoff_async(
|
|
|
134
134
|
|
|
135
135
|
return wrapper
|
|
136
136
|
|
|
137
|
-
return decorator
|
|
137
|
+
return decorator # type: ignore[return-value]
|
|
138
138
|
|
|
139
139
|
|
|
140
140
|
@dataclass(frozen=True)
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.4
|
|
2
2
|
Name: openaivec
|
|
3
|
-
Version: 0.13.
|
|
3
|
+
Version: 0.13.6
|
|
4
4
|
Summary: Generative mutation for tabular calculation
|
|
5
5
|
Project-URL: Homepage, https://microsoft.github.io/openaivec/
|
|
6
6
|
Project-URL: Repository, https://github.com/microsoft/openaivec
|
|
@@ -159,7 +159,7 @@ client = BatchResponses.of(
|
|
|
159
159
|
client=OpenAI(),
|
|
160
160
|
model_name="gpt-4.1-mini",
|
|
161
161
|
system_message="Please answer only with 'xx family' and do not output anything else.",
|
|
162
|
-
batch_size
|
|
162
|
+
# batch_size defaults to None (automatic optimization)
|
|
163
163
|
)
|
|
164
164
|
|
|
165
165
|
result = client.parse(["panda", "rabbit", "koala"])
|
|
@@ -304,7 +304,7 @@ async def process_data():
|
|
|
304
304
|
# Asynchronous processing with fine-tuned concurrency control
|
|
305
305
|
results = await df["text"].aio.responses(
|
|
306
306
|
"Analyze sentiment and classify as positive/negative/neutral",
|
|
307
|
-
|
|
307
|
+
# batch_size defaults to None (automatic optimization)
|
|
308
308
|
max_concurrency=12 # Allow up to 12 concurrent requests
|
|
309
309
|
)
|
|
310
310
|
return results
|
|
@@ -315,7 +315,7 @@ sentiments = asyncio.run(process_data())
|
|
|
315
315
|
|
|
316
316
|
**Key Parameters for Performance Tuning:**
|
|
317
317
|
|
|
318
|
-
- **`batch_size`** (default:
|
|
318
|
+
- **`batch_size`** (default: None): Controls how many inputs are grouped into a single API request. When None (default), automatic batch size optimization adjusts based on execution time. Set to a positive integer for fixed batch size. Higher values reduce API call overhead but increase memory usage and request processing time.
|
|
319
319
|
- **`max_concurrency`** (default: 8): Limits the number of concurrent API requests. Higher values increase throughput but may hit rate limits or overwhelm the API.
|
|
320
320
|
|
|
321
321
|
**Performance Benefits:**
|
|
@@ -460,12 +460,12 @@ When using openaivec with Spark, proper configuration of `batch_size` and `max_c
|
|
|
460
460
|
- **Transparent**: Works automatically without code changes - your existing UDFs become more efficient
|
|
461
461
|
- **Partition-Level**: Each partition maintains its own cache, optimal for distributed processing patterns
|
|
462
462
|
|
|
463
|
-
**`batch_size`** (default:
|
|
463
|
+
**`batch_size`** (default: None):
|
|
464
464
|
|
|
465
465
|
- Controls how many rows are processed together in each API request within a partition
|
|
466
|
-
- **
|
|
467
|
-
- **
|
|
468
|
-
- **Recommendation**: 32-128
|
|
466
|
+
- **Default (None)**: Automatic batch size optimization adjusts based on execution time
|
|
467
|
+
- **Positive integer**: Fixed batch size - larger values reduce API calls but increase memory usage
|
|
468
|
+
- **Recommendation**: Use default automatic optimization, or set 32-128 for fixed batch size
|
|
469
469
|
|
|
470
470
|
**`max_concurrency`** (default: 8):
|
|
471
471
|
|
|
@@ -483,7 +483,7 @@ spark.udf.register(
|
|
|
483
483
|
"analyze_sentiment",
|
|
484
484
|
responses_udf(
|
|
485
485
|
instructions="Analyze sentiment as positive/negative/neutral",
|
|
486
|
-
|
|
486
|
+
# batch_size defaults to None (automatic optimization)
|
|
487
487
|
max_concurrency=8 # 80 total concurrent requests across cluster
|
|
488
488
|
)
|
|
489
489
|
)
|
|
@@ -1,35 +1,35 @@
|
|
|
1
1
|
openaivec/__init__.py,sha256=DQcfTw7y4CgPtyyMg-wO4chwVYT0jA_F-EjxT_bXxTg,236
|
|
2
2
|
openaivec/di.py,sha256=eNewaSRx7f_O0IQcyjzGpIMak6O-bc6OeMqjytCfr88,10634
|
|
3
|
-
openaivec/embeddings.py,sha256=
|
|
3
|
+
openaivec/embeddings.py,sha256=ntnsdV2L6WAT4nKqgL3MZfhqf_Xnfu_J8oFavjIVcIU,7470
|
|
4
4
|
openaivec/log.py,sha256=GofgzUpv_xDVuGC-gYmit5Oyu06it1SBXRck6COR5go,1439
|
|
5
|
-
openaivec/model.py,sha256=
|
|
6
|
-
openaivec/optimize.py,sha256
|
|
7
|
-
openaivec/pandas_ext.py,sha256=
|
|
8
|
-
openaivec/prompt.py,sha256=
|
|
9
|
-
openaivec/provider.py,sha256=
|
|
10
|
-
openaivec/proxy.py,sha256=
|
|
11
|
-
openaivec/responses.py,sha256=
|
|
5
|
+
openaivec/model.py,sha256=u1zQLF__Qw9mp92K1LYaAaQEYisMZoMWuX9-dx2JYoE,3316
|
|
6
|
+
openaivec/optimize.py,sha256=jjE-_ZOs_BPuSHHYVoykGHqTF04nlYkz_rFZ0Kcwtdc,3837
|
|
7
|
+
openaivec/pandas_ext.py,sha256=QlTSZkVzVwO1MFAGv_MuFaINpXlxYjkbfO0zCsmbmSM,58717
|
|
8
|
+
openaivec/prompt.py,sha256=ZzHOS2CRLRtPeP4Z734xkaAA5LFcfmhkDQE5URQUidQ,20842
|
|
9
|
+
openaivec/provider.py,sha256=BYsJxioaemDpjOYdNuLMtasi54Je6LNrtyYupHTxWLA,6688
|
|
10
|
+
openaivec/proxy.py,sha256=jsWUqEJVlRHj0854GlvAzG09mm-QmFFNREXeMOc1LsY,28901
|
|
11
|
+
openaivec/responses.py,sha256=v4MtyIh_g6bahmkq1Ra4y63Tlqg6-Ace1SErmoosvMg,21424
|
|
12
12
|
openaivec/serialize.py,sha256=HXi5l_4b_4eUMNL7f7o_suyHHF_hz3RYsUsri5CQ7_4,7325
|
|
13
|
-
openaivec/spark.py,sha256=
|
|
14
|
-
openaivec/util.py,sha256=
|
|
13
|
+
openaivec/spark.py,sha256=uxXXgOhH1g_HEnBIuNGLlKPInJwZBCLaqrTnJT2UHk4,24252
|
|
14
|
+
openaivec/util.py,sha256=A7-QSoGkdllH6e6CVHxuGk-fmAmsSCSZVSJ5VSDzmx4,6409
|
|
15
15
|
openaivec/task/__init__.py,sha256=26Kd2eRRfUqRJnYH83sRrbuEuRwshypRRSkTWtT50Tw,6177
|
|
16
16
|
openaivec/task/customer_support/__init__.py,sha256=KWfGyXPdZyfGdRH17x7hPpJJ1N2EP9PPhZx0fvBAwSI,884
|
|
17
17
|
openaivec/task/customer_support/customer_sentiment.py,sha256=vf2GzUk_06JD1FeRTetg5bCcBFUSqH349J1TI5lsgkg,7616
|
|
18
|
-
openaivec/task/customer_support/inquiry_classification.py,sha256=
|
|
18
|
+
openaivec/task/customer_support/inquiry_classification.py,sha256=F86-wBMjHn_PtUDT9N6LHmxRGkYMd3huT-KrqZAogCg,9644
|
|
19
19
|
openaivec/task/customer_support/inquiry_summary.py,sha256=bZV8pvPAdiijqMnaUMg_jGie0dsEHgnEUvqhunyP0CY,6924
|
|
20
20
|
openaivec/task/customer_support/intent_analysis.py,sha256=i8S19z_-Dgz9rspiDTE0TShmExYE9y6ZCr8ipmHvC4A,7508
|
|
21
21
|
openaivec/task/customer_support/response_suggestion.py,sha256=L3NJLqyFafxEsW3QD0MIiE-MB4akwoDW6nuWOWJQpyE,8348
|
|
22
|
-
openaivec/task/customer_support/urgency_analysis.py,sha256=
|
|
22
|
+
openaivec/task/customer_support/urgency_analysis.py,sha256=_llRrS11BJ392Xz0dXqr5i1jggTjgvtpKDEwUoY2KaE,11573
|
|
23
23
|
openaivec/task/nlp/__init__.py,sha256=QoQ0egEK9IEh5hdrE07rZ_KCmC0gy_2FPrWJYRWiipY,512
|
|
24
24
|
openaivec/task/nlp/dependency_parsing.py,sha256=7JczHzibWARPwo7h81N2Qk9h-3AnLmMkVsJ1cZp1w6Q,2840
|
|
25
|
-
openaivec/task/nlp/keyword_extraction.py,sha256=
|
|
25
|
+
openaivec/task/nlp/keyword_extraction.py,sha256=bPI0mYzgZ3pXEBusOpSpoi_Zs84ccQXknS_nB7Bwy7I,2827
|
|
26
26
|
openaivec/task/nlp/morphological_analysis.py,sha256=DvJhJge7r_oEYfb0Siq-x9rioCWYBVw6wroTdGkqInk,2424
|
|
27
|
-
openaivec/task/nlp/named_entity_recognition.py,sha256=
|
|
27
|
+
openaivec/task/nlp/named_entity_recognition.py,sha256=ehT1SYGsBrviPLVKk2veMKoxdS4CTx89FefAwN2jA4s,3060
|
|
28
28
|
openaivec/task/nlp/sentiment_analysis.py,sha256=9HdMpi7FkjHNXAswaN98k8jeKsatBBXTPaTmp9VI7mE,3089
|
|
29
29
|
openaivec/task/nlp/translation.py,sha256=4fjKtbVvOvivWMrpZfreIsdg8d0DplDujO8kAdLbAKI,6625
|
|
30
30
|
openaivec/task/table/__init__.py,sha256=kJz15WDJXjyC7UIHKBvlTRhCf347PCDMH5T5fONV2sU,83
|
|
31
31
|
openaivec/task/table/fillna.py,sha256=vi8t5QEIU-W3e05wwpATb3MEUDyf8luVnE8U-5VebZo,6582
|
|
32
|
-
openaivec-0.13.
|
|
33
|
-
openaivec-0.13.
|
|
34
|
-
openaivec-0.13.
|
|
35
|
-
openaivec-0.13.
|
|
32
|
+
openaivec-0.13.6.dist-info/METADATA,sha256=JDjFmGAcoqSIeoK5JSEQ0Kd98HVRHW_DPwiUvsheDIU,27566
|
|
33
|
+
openaivec-0.13.6.dist-info/WHEEL,sha256=qtCwoSJWgHk21S1Kb4ihdzI2rlJ1ZKaIurTj_ngOhyQ,87
|
|
34
|
+
openaivec-0.13.6.dist-info/licenses/LICENSE,sha256=ws_MuBL-SCEBqPBFl9_FqZkaaydIJmxHrJG2parhU4M,1141
|
|
35
|
+
openaivec-0.13.6.dist-info/RECORD,,
|
|
File without changes
|
|
File without changes
|