nebu 0.1.35__py3-none-any.whl → 0.1.36__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.
- nebu/chatx/openai.py +2 -2
- nebu/processors/consumer.py +19 -0
- nebu/processors/decorate.py +78 -1
- nebu/processors/processor.py +1 -1
- {nebu-0.1.35.dist-info → nebu-0.1.36.dist-info}/METADATA +1 -1
- {nebu-0.1.35.dist-info → nebu-0.1.36.dist-info}/RECORD +9 -9
- {nebu-0.1.35.dist-info → nebu-0.1.36.dist-info}/WHEEL +0 -0
- {nebu-0.1.35.dist-info → nebu-0.1.36.dist-info}/licenses/LICENSE +0 -0
- {nebu-0.1.35.dist-info → nebu-0.1.36.dist-info}/top_level.txt +0 -0
nebu/chatx/openai.py
CHANGED
@@ -6,7 +6,7 @@ from __future__ import annotations
|
|
6
6
|
|
7
7
|
from typing import Dict, List, Literal, Optional, Union
|
8
8
|
|
9
|
-
from pydantic import
|
9
|
+
from pydantic import BaseModel, ConfigDict, Field, RootModel
|
10
10
|
|
11
11
|
|
12
12
|
class FunctionDefinition(BaseModel):
|
@@ -151,7 +151,7 @@ class ChatCompletionRequestMessageContentPartFile(BaseModel):
|
|
151
151
|
|
152
152
|
|
153
153
|
class ImageUrl(BaseModel):
|
154
|
-
url:
|
154
|
+
url: str = Field(
|
155
155
|
..., description="Either a URL of the image or the base64 encoded image data."
|
156
156
|
)
|
157
157
|
detail: str | None = Field(
|
nebu/processors/consumer.py
CHANGED
@@ -28,6 +28,10 @@ try:
|
|
28
28
|
return_type_name = os.environ.get("RETURN_TYPE_NAME")
|
29
29
|
content_type_name = os.environ.get("CONTENT_TYPE_NAME")
|
30
30
|
|
31
|
+
# Get before_func source if provided
|
32
|
+
before_func_source = os.environ.get("BEFORE_FUNC_SOURCE")
|
33
|
+
before_func_name = os.environ.get("BEFORE_FUNC_NAME")
|
34
|
+
|
31
35
|
# Check for generic type arguments
|
32
36
|
input_model_args = []
|
33
37
|
output_model_args = []
|
@@ -211,6 +215,21 @@ try:
|
|
211
215
|
traceback.print_exc()
|
212
216
|
sys.exit(1)
|
213
217
|
|
218
|
+
# Execute before_func if provided
|
219
|
+
if before_func_source and before_func_name:
|
220
|
+
print(f"Executing before_func: {before_func_name}...")
|
221
|
+
try:
|
222
|
+
exec(before_func_source, local_namespace)
|
223
|
+
before_function = local_namespace[before_func_name]
|
224
|
+
before_function() # Call the function
|
225
|
+
print(f"Successfully executed before_func: {before_func_name}")
|
226
|
+
except Exception as e:
|
227
|
+
print(f"Error executing before_func '{before_func_name}': {e}")
|
228
|
+
traceback.print_exc()
|
229
|
+
# Decide if failure is critical. For now, let's exit.
|
230
|
+
print("Exiting due to before_func failure.")
|
231
|
+
sys.exit(1)
|
232
|
+
|
214
233
|
except Exception as e:
|
215
234
|
print(f"Error setting up function: {e}")
|
216
235
|
traceback.print_exc()
|
nebu/processors/decorate.py
CHANGED
@@ -352,6 +352,7 @@ def processor(
|
|
352
352
|
python_cmd: str = "python",
|
353
353
|
no_delete: bool = False,
|
354
354
|
include: Optional[List[Any]] = None,
|
355
|
+
before_func: Optional[Callable[[], None]] = None,
|
355
356
|
):
|
356
357
|
def decorator(
|
357
358
|
func: Callable[[Any], Any],
|
@@ -538,7 +539,7 @@ def processor(
|
|
538
539
|
"[DEBUG Decorator] Validating parameter and return types are BaseModel subclasses..."
|
539
540
|
)
|
540
541
|
|
541
|
-
def check_basemodel(type_to_check, desc):
|
542
|
+
def check_basemodel(type_to_check: Optional[Any], desc: str):
|
542
543
|
print(
|
543
544
|
f"[DEBUG Decorator] check_basemodel: Checking {desc} - Type: {type_to_check}"
|
544
545
|
)
|
@@ -634,6 +635,74 @@ def processor(
|
|
634
635
|
{function_source[:250]}...\n-------")
|
635
636
|
# --- End Function Source ---
|
636
637
|
|
638
|
+
# --- Get Before Function Source (if provided) ---
|
639
|
+
before_func_source = None
|
640
|
+
before_func_name = None
|
641
|
+
if before_func:
|
642
|
+
print(f"[DEBUG Decorator] Processing before_func: {before_func.__name__}")
|
643
|
+
before_func_name = before_func.__name__
|
644
|
+
# Validate signature (must take no arguments)
|
645
|
+
before_sig = inspect.signature(before_func)
|
646
|
+
if len(before_sig.parameters) != 0:
|
647
|
+
raise TypeError(
|
648
|
+
f"before_func '{before_func_name}' must take zero parameters"
|
649
|
+
)
|
650
|
+
|
651
|
+
# Try to get source using similar logic as the main function
|
652
|
+
before_explicit_source = getattr(
|
653
|
+
before_func, _NEBU_EXPLICIT_SOURCE_ATTR, None
|
654
|
+
)
|
655
|
+
if before_explicit_source:
|
656
|
+
print(
|
657
|
+
f"[DEBUG Decorator] Using explicit source (@include) for before_func {before_func_name}"
|
658
|
+
)
|
659
|
+
before_func_source = before_explicit_source
|
660
|
+
elif in_jupyter and notebook_code:
|
661
|
+
print(
|
662
|
+
f"[DEBUG Decorator] Attempting notebook history extraction for before_func '{before_func_name}'..."
|
663
|
+
)
|
664
|
+
before_func_source = extract_definition_source_from_string(
|
665
|
+
notebook_code, before_func_name, ast.FunctionDef
|
666
|
+
)
|
667
|
+
if before_func_source:
|
668
|
+
print(
|
669
|
+
f"[DEBUG Decorator] Found before_func '{before_func_name}' source in notebook history."
|
670
|
+
)
|
671
|
+
else:
|
672
|
+
print(
|
673
|
+
f"[DEBUG Decorator] Failed to find before_func '{before_func_name}' in notebook history, falling back to dill."
|
674
|
+
)
|
675
|
+
|
676
|
+
if before_func_source is None:
|
677
|
+
print(
|
678
|
+
f"[DEBUG Decorator] Using dill fallback for before_func '{before_func_name}'..."
|
679
|
+
)
|
680
|
+
try:
|
681
|
+
raw_before_func_source = dill.source.getsource(before_func)
|
682
|
+
before_func_source = textwrap.dedent(raw_before_func_source)
|
683
|
+
print(
|
684
|
+
f"[DEBUG Decorator] Successfully got source via dill for '{before_func_name}'."
|
685
|
+
)
|
686
|
+
except (IOError, TypeError, OSError) as e:
|
687
|
+
print(
|
688
|
+
f"[DEBUG Decorator] Dill fallback failed for '{before_func_name}': {e}"
|
689
|
+
)
|
690
|
+
# Raise error if we couldn't get the source by any means
|
691
|
+
raise ValueError(
|
692
|
+
f"Could not retrieve source for before_func '{before_func_name}': {e}"
|
693
|
+
) from e
|
694
|
+
|
695
|
+
if before_func_source is None: # Final check
|
696
|
+
raise ValueError(
|
697
|
+
f"Failed to obtain source code for before_func '{before_func_name}' using any method."
|
698
|
+
)
|
699
|
+
print(
|
700
|
+
f"[DEBUG Decorator] Final before_func source obtained for '{before_func_name}'."
|
701
|
+
)
|
702
|
+
else:
|
703
|
+
print("[DEBUG Decorator] No before_func provided.")
|
704
|
+
# --- End Before Function Source ---
|
705
|
+
|
637
706
|
# --- Get Model Sources ---
|
638
707
|
print("[DEBUG Decorator] Getting model sources...")
|
639
708
|
input_model_source = None
|
@@ -746,6 +815,14 @@ def processor(
|
|
746
815
|
add_source_to_env("CONTENT_TYPE", content_type_source)
|
747
816
|
add_source_to_env("STREAM_MESSAGE", stream_message_source)
|
748
817
|
|
818
|
+
# Add before_func source if available
|
819
|
+
if before_func_source and before_func_name:
|
820
|
+
print(
|
821
|
+
f"[DEBUG Decorator] Adding BEFORE_FUNC env vars for {before_func_name}"
|
822
|
+
)
|
823
|
+
all_env.append(V1EnvVar(key="BEFORE_FUNC_SOURCE", value=before_func_source))
|
824
|
+
all_env.append(V1EnvVar(key="BEFORE_FUNC_NAME", value=before_func_name))
|
825
|
+
|
749
826
|
print("[DEBUG Decorator] Adding type info env vars...")
|
750
827
|
all_env.append(V1EnvVar(key="PARAM_TYPE_STR", value=param_type_str_repr))
|
751
828
|
all_env.append(V1EnvVar(key="RETURN_TYPE_STR", value=str(return_type)))
|
nebu/processors/processor.py
CHANGED
@@ -157,7 +157,7 @@ class Processor:
|
|
157
157
|
|
158
158
|
response = requests.post(
|
159
159
|
url,
|
160
|
-
json=stream_data.model_dump(exclude_none=True),
|
160
|
+
json=stream_data.model_dump(mode="json", exclude_none=True),
|
161
161
|
headers={"Authorization": f"Bearer {self.api_key}"},
|
162
162
|
)
|
163
163
|
response.raise_for_status()
|
@@ -6,21 +6,21 @@ nebu/config.py,sha256=aZzQltkobtOLHFCGcIkpKoE3ITn3Z11Dp0E72w84TA0,5769
|
|
6
6
|
nebu/data.py,sha256=kIH9-JJ1-iO7P2t28bku6Gn0Y5tgQszGeTW_rpmO03A,38725
|
7
7
|
nebu/meta.py,sha256=CzFHMND9seuewzq9zNNx9WTr6JvrCBExe7BLqDSr7lM,745
|
8
8
|
nebu/chatx/convert.py,sha256=jIOuGXPfLkYf_cRqh739gsKKg7cBB2zEYm3Jpmf6Xvo,12535
|
9
|
-
nebu/chatx/openai.py,sha256=
|
9
|
+
nebu/chatx/openai.py,sha256=VsJvV2MbYeJj2Ita9Q9X3qj5r5F3P-aPDhpSFr-Q-dw,44950
|
10
10
|
nebu/containers/container.py,sha256=yb7KaPTVXnEEAlrpdlUi4HNqF6P7z9bmwAILGlq6iqU,13502
|
11
11
|
nebu/containers/decorator.py,sha256=uFtzlAXRHYZECJ-NPusY7oN9GXvdHrHDd_JNrIGr8aQ,3244
|
12
12
|
nebu/containers/models.py,sha256=0j6NGy4yto-enRDh_4JH_ZTbHrLdSpuMOqNQPnIrwC4,6815
|
13
13
|
nebu/containers/server.py,sha256=yFa2Y9PzBn59E1HftKiv0iapPonli2rbGAiU6r-wwe0,2513
|
14
|
-
nebu/processors/consumer.py,sha256=
|
15
|
-
nebu/processors/decorate.py,sha256=
|
14
|
+
nebu/processors/consumer.py,sha256=GxU-IM-U7B9Tq6eTwW2lBVe7jm-JfK0ux4ZR2HN3sfU,20693
|
15
|
+
nebu/processors/decorate.py,sha256=Jn7rJfhJFDlbFGxLDNJzL_GOthX_MWDl1rtktl1kYFM,38286
|
16
16
|
nebu/processors/default.py,sha256=W4slJenG59rvyTlJ7gRp58eFfXcNOTT2Hfi6zzJAobI,365
|
17
17
|
nebu/processors/models.py,sha256=y40HoW-MEzDWB2dm_tsYlUy3Nf3s6eiLC0iGO9BoNog,3956
|
18
|
-
nebu/processors/processor.py,sha256=
|
18
|
+
nebu/processors/processor.py,sha256=068hLQKapWabNlhb_DtzqAJ7N7MGdr5UcjfZrb_MkFo,9732
|
19
19
|
nebu/processors/remote.py,sha256=TeAIPGEMqnDIb7H1iett26IEZrBlcbPB_-DSm6jcH1E,1285
|
20
20
|
nebu/redis/models.py,sha256=coPovAcVXnOU1Xh_fpJL4PO3QctgK9nBe5QYoqEcnxg,1230
|
21
21
|
nebu/services/service.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
22
|
-
nebu-0.1.
|
23
|
-
nebu-0.1.
|
24
|
-
nebu-0.1.
|
25
|
-
nebu-0.1.
|
26
|
-
nebu-0.1.
|
22
|
+
nebu-0.1.36.dist-info/licenses/LICENSE,sha256=xx0jnfkXJvxRnG63LTGOxlggYnIysveWIZ6H3PNdCrQ,11357
|
23
|
+
nebu-0.1.36.dist-info/METADATA,sha256=ZS2pswd9_T1ElnlDNUSBzRxH7udOM8f3Nh-6N_VsKtk,1786
|
24
|
+
nebu-0.1.36.dist-info/WHEEL,sha256=CmyFI0kx5cdEMTLiONQRbGQwjIoR1aIYB7eCAQ4KPJ0,91
|
25
|
+
nebu-0.1.36.dist-info/top_level.txt,sha256=uLIbEKJeGSHWOAJN5S0i5XBGwybALlF9bYoB1UhdEgQ,5
|
26
|
+
nebu-0.1.36.dist-info/RECORD,,
|
File without changes
|
File without changes
|
File without changes
|