orbitals 0.1.2__tar.gz → 0.1.3__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.
- orbitals-0.1.3/.github/workflows/publish.yml +26 -0
- {orbitals-0.1.2 → orbitals-0.1.3}/AGENTS.md +4 -7
- {orbitals-0.1.2 → orbitals-0.1.3}/PKG-INFO +1 -1
- {orbitals-0.1.2 → orbitals-0.1.3}/README.scope-guard.md +2 -2
- {orbitals-0.1.2 → orbitals-0.1.3}/pyproject.toml +1 -1
- {orbitals-0.1.2 → orbitals-0.1.3}/src/orbitals/scope_guard/cli/serve.py +3 -1
- {orbitals-0.1.2 → orbitals-0.1.3}/src/orbitals/scope_guard/guards/api.py +4 -4
- {orbitals-0.1.2 → orbitals-0.1.3}/src/orbitals/scope_guard/guards/base.py +1 -1
- {orbitals-0.1.2 → orbitals-0.1.3}/src/orbitals/scope_guard/guards/vllm.py +1 -1
- {orbitals-0.1.2 → orbitals-0.1.3}/src/orbitals/scope_guard/modeling.py +20 -3
- {orbitals-0.1.2 → orbitals-0.1.3}/src/orbitals/utils.py +1 -1
- {orbitals-0.1.2 → orbitals-0.1.3}/uv.lock +1 -1
- orbitals-0.1.2/.dockerignore +0 -5
- orbitals-0.1.2/Dockerfile +0 -23
- orbitals-0.1.2/Dockerfile copy +0 -52
- orbitals-0.1.2/examples/scope-guard/test.py +0 -27
- orbitals-0.1.2/examples/scope-guard/vllm_serve.py +0 -55
- orbitals-0.1.2/src/scripts/playground.ipynb +0 -267
- orbitals-0.1.2/src/scripts/push_hf_pipeline.py +0 -20
- orbitals-0.1.2/src/scripts/push_model.py +0 -32
- {orbitals-0.1.2 → orbitals-0.1.3}/.gitignore +0 -0
- {orbitals-0.1.2 → orbitals-0.1.3}/CONTRIBUTING.md +0 -0
- {orbitals-0.1.2 → orbitals-0.1.3}/LICENSE +0 -0
- {orbitals-0.1.2 → orbitals-0.1.3}/README.md +0 -0
- {orbitals-0.1.2 → orbitals-0.1.3}/assets/orbitals-banner.png +0 -0
- {orbitals-0.1.2 → orbitals-0.1.3}/assets/orbitals.svg +0 -0
- {orbitals-0.1.2 → orbitals-0.1.3}/assets/scope-guard.svg +0 -0
- {orbitals-0.1.2 → orbitals-0.1.3}/examples/scope-guard/api.py +0 -0
- {orbitals-0.1.2 → orbitals-0.1.3}/examples/scope-guard/async_api.py +0 -0
- {orbitals-0.1.2 → orbitals-0.1.3}/examples/scope-guard/local.py +0 -0
- {orbitals-0.1.2 → orbitals-0.1.3}/src/hf_pipeline/scope_guard.py +0 -0
- {orbitals-0.1.2 → orbitals-0.1.3}/src/orbitals/__init__.py +0 -0
- {orbitals-0.1.2 → orbitals-0.1.3}/src/orbitals/cli/__init__.py +0 -0
- {orbitals-0.1.2 → orbitals-0.1.3}/src/orbitals/cli/main.py +0 -0
- {orbitals-0.1.2 → orbitals-0.1.3}/src/orbitals/scope_guard/__init__.py +0 -0
- {orbitals-0.1.2 → orbitals-0.1.3}/src/orbitals/scope_guard/cli/__init__.py +0 -0
- {orbitals-0.1.2 → orbitals-0.1.3}/src/orbitals/scope_guard/cli/convert_default_model_name.py +0 -0
- {orbitals-0.1.2 → orbitals-0.1.3}/src/orbitals/scope_guard/cli/main.py +0 -0
- {orbitals-0.1.2 → orbitals-0.1.3}/src/orbitals/scope_guard/guards/__init__.py +0 -0
- {orbitals-0.1.2 → orbitals-0.1.3}/src/orbitals/scope_guard/guards/hf.py +0 -0
- {orbitals-0.1.2 → orbitals-0.1.3}/src/orbitals/scope_guard/prompting.py +0 -0
- {orbitals-0.1.2 → orbitals-0.1.3}/src/orbitals/scope_guard/serving/__init__.py +0 -0
- {orbitals-0.1.2 → orbitals-0.1.3}/src/orbitals/scope_guard/serving/main.py +0 -0
- {orbitals-0.1.2 → orbitals-0.1.3}/src/orbitals/scope_guard/serving/vllm_logging_config.json +0 -0
- {orbitals-0.1.2 → orbitals-0.1.3}/src/orbitals/types.py +0 -0
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
name: "Publish"
|
|
2
|
+
|
|
3
|
+
on:
|
|
4
|
+
release:
|
|
5
|
+
types:
|
|
6
|
+
- created
|
|
7
|
+
|
|
8
|
+
jobs:
|
|
9
|
+
run:
|
|
10
|
+
runs-on: ubuntu-latest
|
|
11
|
+
environment:
|
|
12
|
+
name: pypi
|
|
13
|
+
permissions:
|
|
14
|
+
id-token: write
|
|
15
|
+
contents: read
|
|
16
|
+
steps:
|
|
17
|
+
- name: Checkout
|
|
18
|
+
uses: actions/checkout@v6
|
|
19
|
+
- name: Install uv
|
|
20
|
+
uses: astral-sh/setup-uv@v7
|
|
21
|
+
- name: Install Python 3.13
|
|
22
|
+
run: uv python install 3.13
|
|
23
|
+
- name: Build
|
|
24
|
+
run: uv build
|
|
25
|
+
- name: Publish
|
|
26
|
+
run: uv publish
|
|
@@ -20,15 +20,12 @@ This is done by prompting **local LLMs**.
|
|
|
20
20
|
|
|
21
21
|
## Project Structure
|
|
22
22
|
|
|
23
|
-
The API implementation is entirely in Python, using `uv` as the package manager.
|
|
24
|
-
|
|
25
|
-
/src/transformers:
|
|
26
|
-
/models:
|
|
23
|
+
The API implementation is entirely in Python, using `uv` as the package manager. Project structure is as follows:
|
|
27
24
|
|
|
28
25
|
* `src/orbitals/`: This contains the core source code for the library.
|
|
29
|
-
* `src/orbitals/cli`:
|
|
30
|
-
* `src/orbitals/scope_guard`:
|
|
31
|
-
* `src/orbitals/scope_guard/guards/`: Code for individual scope guards. Starting from the `BaseScopeGuard` root class, we find two subclasses, `ScopeGuard` (sync
|
|
26
|
+
* `src/orbitals/cli`: Code for root `orbitals` cli. It's a Typer app that imports and adds the apps defined by each orbital.
|
|
27
|
+
* `src/orbitals/scope_guard`: This contains the code for the `ScopeGuard` orbital.
|
|
28
|
+
* `src/orbitals/scope_guard/guards/`: Code for individual scope guards. Starting from the `BaseScopeGuard` root class, we find two subclasses, `ScopeGuard` (sync validate and batch-validate methods) and `AsyncScopeGuard` (async counterpart).
|
|
32
29
|
* `src/orbitals/scope_guard/cli/`: This contains the CLI commands of `scope-guard`.
|
|
33
30
|
* `src/orbitals/scope_guard/serving/`: This contains the FastAPI serving implementation.
|
|
34
31
|
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.4
|
|
2
2
|
Name: orbitals
|
|
3
|
-
Version: 0.1.
|
|
3
|
+
Version: 0.1.3
|
|
4
4
|
Summary: LLM Guardrails tailored to your Principles
|
|
5
5
|
Author-email: Luigi Procopio <luigi@principled-intelligence.com>, Edoardo Barba <edoardo@principled-intelligence.com>
|
|
6
6
|
License: Apache-2.0
|
|
@@ -5,9 +5,9 @@
|
|
|
5
5
|
<a href="https://principled-intelligence.com/news/introducing-scope-guard">
|
|
6
6
|
<img src="https://img.shields.io/badge/Blog-Article-blue" />
|
|
7
7
|
</a>
|
|
8
|
-
<a href="https://demo.halo.principled.app">
|
|
8
|
+
<!-- <a href="https://demo.halo.principled.app">
|
|
9
9
|
<img src="https://img.shields.io/badge/Live-Demo-green" />
|
|
10
|
-
</a>
|
|
10
|
+
</a> -->
|
|
11
11
|
<a href="https://colab.research.google.com/drive/1iBJog8H4QpS3_Y2powR5tidUhWJNajw2">
|
|
12
12
|
<img src="https://colab.research.google.com/assets/colab-badge.svg" />
|
|
13
13
|
</a>
|
|
@@ -38,7 +38,9 @@ def serve(
|
|
|
38
38
|
"0.0.0.0", "-h", "--host", help="The host to use for the server"
|
|
39
39
|
),
|
|
40
40
|
vllm_port: int = typer.Option(8001, help="The port to use for the vLLM server"),
|
|
41
|
-
vllm_max_model_len: int = typer.Option(
|
|
41
|
+
vllm_max_model_len: int = typer.Option(
|
|
42
|
+
30_000, help="Maximum model length for vLLM"
|
|
43
|
+
),
|
|
42
44
|
vllm_max_num_seqs: int = typer.Option(
|
|
43
45
|
2, help="Maximum number of sequences for vLLM"
|
|
44
46
|
),
|
|
@@ -106,7 +106,7 @@ class APIScopeGuard(ScopeGuard):
|
|
|
106
106
|
skip_evidences: bool | None = None,
|
|
107
107
|
) -> ScopeGuardOutput:
|
|
108
108
|
response = requests.post(
|
|
109
|
-
f"{self.api_url}/
|
|
109
|
+
f"{self.api_url}/orbitals/scope-guard/validate",
|
|
110
110
|
json=_build_request_data(
|
|
111
111
|
conversation,
|
|
112
112
|
skip_evidences if skip_evidences is not None else self.skip_evidences,
|
|
@@ -134,7 +134,7 @@ class APIScopeGuard(ScopeGuard):
|
|
|
134
134
|
skip_evidences: bool | None = None,
|
|
135
135
|
) -> list[ScopeGuardOutput]:
|
|
136
136
|
response = requests.post(
|
|
137
|
-
f"{self.api_url}/
|
|
137
|
+
f"{self.api_url}/orbitals/scope-guard/batch-validate",
|
|
138
138
|
json=_build_batch_request_data(
|
|
139
139
|
conversations,
|
|
140
140
|
skip_evidences if skip_evidences is not None else self.skip_evidences,
|
|
@@ -185,7 +185,7 @@ class AsyncAPIScopeGuard(AsyncScopeGuard):
|
|
|
185
185
|
) -> ScopeGuardOutput:
|
|
186
186
|
async with aiohttp.ClientSession() as session:
|
|
187
187
|
response = await session.post(
|
|
188
|
-
f"{self.api_url}/
|
|
188
|
+
f"{self.api_url}/in/scope-guard/validate",
|
|
189
189
|
json=_build_request_data(
|
|
190
190
|
conversation,
|
|
191
191
|
skip_evidences
|
|
@@ -216,7 +216,7 @@ class AsyncAPIScopeGuard(AsyncScopeGuard):
|
|
|
216
216
|
) -> list[ScopeGuardOutput]:
|
|
217
217
|
async with aiohttp.ClientSession() as session:
|
|
218
218
|
response = await session.post(
|
|
219
|
-
f"{self.api_url}/
|
|
219
|
+
f"{self.api_url}/in/scope-guard/batch-validate",
|
|
220
220
|
json=_build_batch_request_data(
|
|
221
221
|
conversations,
|
|
222
222
|
skip_evidences
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
from enum import Enum
|
|
2
|
-
from typing import Literal
|
|
2
|
+
from typing import Annotated, Any, Literal
|
|
3
3
|
|
|
4
|
-
from pydantic import BaseModel, TypeAdapter
|
|
4
|
+
from pydantic import BaseModel, BeforeValidator, TypeAdapter
|
|
5
5
|
|
|
6
6
|
from ..types import ConversationMessage, LLMUsage
|
|
7
7
|
|
|
@@ -66,6 +66,23 @@ class ConversationUserMessage(BaseModel):
|
|
|
66
66
|
content: str
|
|
67
67
|
|
|
68
68
|
|
|
69
|
-
|
|
69
|
+
def _select_model_based_on_fields(
|
|
70
|
+
v: Any,
|
|
71
|
+
) -> str | ConversationUserMessage | list[ConversationMessage]:
|
|
72
|
+
if isinstance(v, str):
|
|
73
|
+
return TypeAdapter(str).validate_python(v)
|
|
74
|
+
elif isinstance(v, dict):
|
|
75
|
+
return TypeAdapter(ConversationUserMessage).validate_python(v)
|
|
76
|
+
elif isinstance(v, list):
|
|
77
|
+
return TypeAdapter(list[ConversationMessage]).validate_python(v)
|
|
78
|
+
|
|
79
|
+
# no matching model found, let's fall back to standard pydantic behavior
|
|
80
|
+
return v
|
|
81
|
+
|
|
82
|
+
|
|
83
|
+
ScopeGuardInput = Annotated[
|
|
84
|
+
str | ConversationUserMessage | list[ConversationMessage],
|
|
85
|
+
BeforeValidator(_select_model_based_on_fields),
|
|
86
|
+
]
|
|
70
87
|
|
|
71
88
|
ScopeGuardInputTypeAdapter = TypeAdapter(ScopeGuardInput)
|
|
@@ -17,7 +17,7 @@ def maybe_configure_gpu_usage():
|
|
|
17
17
|
return
|
|
18
18
|
|
|
19
19
|
try:
|
|
20
|
-
import pynvml # ty: ignore[unresolved-import]
|
|
20
|
+
import pynvml # ty: ignore[unresolved-import]
|
|
21
21
|
except ModuleNotFoundError:
|
|
22
22
|
logging.debug("nvidia-ml-py not available, skipping GPU auto-configuration")
|
|
23
23
|
return
|
orbitals-0.1.2/.dockerignore
DELETED
orbitals-0.1.2/Dockerfile
DELETED
|
@@ -1,23 +0,0 @@
|
|
|
1
|
-
FROM vllm/vllm-openai:v0.14.1
|
|
2
|
-
|
|
3
|
-
ARG DEBIAN_FRONTEND=noninteractive
|
|
4
|
-
|
|
5
|
-
COPY --from=ghcr.io/astral-sh/uv:0.9.8-debian-slim /usr/local/bin/uv /usr/local/bin/uvx /bin/
|
|
6
|
-
|
|
7
|
-
WORKDIR /app
|
|
8
|
-
ENV PATH="/app/.venv/bin:$PATH"
|
|
9
|
-
ENV UV_COMPILE_BYTECODE=1
|
|
10
|
-
|
|
11
|
-
ARG MODEL
|
|
12
|
-
ENV MODEL=${MODEL}
|
|
13
|
-
|
|
14
|
-
RUN hf download ${MODEL}
|
|
15
|
-
|
|
16
|
-
COPY pyproject.toml uv.lock README.md src /app/src/
|
|
17
|
-
|
|
18
|
-
RUN pip install -e .[serving]
|
|
19
|
-
|
|
20
|
-
EXPOSE 8000
|
|
21
|
-
|
|
22
|
-
ENTRYPOINT ["/bin/bash", "-c"]
|
|
23
|
-
CMD ["orbitals scope-guard serve ${MODEL} --port 8000 --host 0.0.0.0"]
|
orbitals-0.1.2/Dockerfile copy
DELETED
|
@@ -1,52 +0,0 @@
|
|
|
1
|
-
FROM nvidia/cuda:13.1.1-cudnn-devel-ubuntu24.04 AS builder
|
|
2
|
-
|
|
3
|
-
ARG DEBIAN_FRONTEND=noninteractive
|
|
4
|
-
|
|
5
|
-
COPY --from=ghcr.io/astral-sh/uv:0.9.8-debian-slim /usr/local/bin/uv /usr/local/bin/uvx /bin/
|
|
6
|
-
|
|
7
|
-
WORKDIR /app
|
|
8
|
-
ENV PATH="/app/.venv/bin:$PATH"
|
|
9
|
-
ENV UV_COMPILE_BYTECODE=1
|
|
10
|
-
|
|
11
|
-
RUN \
|
|
12
|
-
apt-get update && \
|
|
13
|
-
apt-get install -y --no-install-recommends git python3.12
|
|
14
|
-
|
|
15
|
-
COPY pyproject.toml uv.lock README.md /app/
|
|
16
|
-
|
|
17
|
-
RUN --mount=type=cache,target=/root/.cache/uv \
|
|
18
|
-
uv venv -p 3.12 && \
|
|
19
|
-
uv sync --frozen --extra scope-guard-serve --no-install-project --no-dev
|
|
20
|
-
|
|
21
|
-
ARG MODEL
|
|
22
|
-
RUN hf download ${MODEL}
|
|
23
|
-
|
|
24
|
-
COPY src /app/src/
|
|
25
|
-
|
|
26
|
-
RUN --mount=type=cache,target=/root/.cache/uv \
|
|
27
|
-
uv sync --locked --extra scope-guard-serve --no-editable --no-dev
|
|
28
|
-
|
|
29
|
-
# TODO remove next line
|
|
30
|
-
ENTRYPOINT ["/bin/bash", "-c"]
|
|
31
|
-
|
|
32
|
-
FROM nvidia/cuda:13.1.1-cudnn-runtime-ubuntu24.04 AS runner
|
|
33
|
-
|
|
34
|
-
WORKDIR /app
|
|
35
|
-
ENV PATH="/app/.venv/bin:$PATH"
|
|
36
|
-
|
|
37
|
-
RUN \
|
|
38
|
-
apt-get update && \
|
|
39
|
-
apt-get install -y --no-install-recommends python3.12
|
|
40
|
-
|
|
41
|
-
COPY --from=builder /app/.venv/ /app/.venv/
|
|
42
|
-
|
|
43
|
-
RUN mkdir -p /root/.cache/huggingface/hub
|
|
44
|
-
COPY --from=builder /root/.cache/huggingface/hub /root/.cache/huggingface/hub
|
|
45
|
-
|
|
46
|
-
EXPOSE 8000
|
|
47
|
-
|
|
48
|
-
ARG MODEL
|
|
49
|
-
ENV MODEL=${MODEL}
|
|
50
|
-
|
|
51
|
-
ENTRYPOINT ["/bin/bash", "-c"]
|
|
52
|
-
CMD ["orbitals scope-guard serve ${MODEL} --port 8000 --host 0.0.0.0"]
|
|
@@ -1,27 +0,0 @@
|
|
|
1
|
-
def main():
|
|
2
|
-
from orbitals.scope_guard import ScopeGuard
|
|
3
|
-
|
|
4
|
-
sg = ScopeGuard(
|
|
5
|
-
backend="vllm",
|
|
6
|
-
model="scope-guard-q", # for the Qwen-family model
|
|
7
|
-
# model="scope-guard-g", # for the Gemma-family model
|
|
8
|
-
)
|
|
9
|
-
|
|
10
|
-
ai_service_description = """
|
|
11
|
-
You are a virtual assistant for a parcel delivery service.
|
|
12
|
-
You can only answer questions about package tracking.
|
|
13
|
-
Never respond to requests for refunds.
|
|
14
|
-
"""
|
|
15
|
-
|
|
16
|
-
user_query = "If the package hasn't arrived by tomorrow, can I get my money back?"
|
|
17
|
-
result = sg.validate(user_query, ai_service_description)
|
|
18
|
-
|
|
19
|
-
print(f"Scope: {result.scope_class.value}")
|
|
20
|
-
if result.evidences:
|
|
21
|
-
print("Evidences:")
|
|
22
|
-
for evidence in result.evidences:
|
|
23
|
-
print(f" - {evidence}")
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
if __name__ == "__main__":
|
|
27
|
-
main()
|
|
@@ -1,55 +0,0 @@
|
|
|
1
|
-
import argparse
|
|
2
|
-
import asyncio
|
|
3
|
-
import time
|
|
4
|
-
|
|
5
|
-
from orbitals.scope_guard import AsyncScopeGuard
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
async def main():
|
|
9
|
-
args = parse_args()
|
|
10
|
-
|
|
11
|
-
classifier = AsyncScopeGuard(
|
|
12
|
-
backend="vllm-api",
|
|
13
|
-
model=args.model,
|
|
14
|
-
skip_evidences=args.skip_evidences,
|
|
15
|
-
vllm_serving_url=args.vllm_serving_url,
|
|
16
|
-
)
|
|
17
|
-
|
|
18
|
-
user_question = (
|
|
19
|
-
"If the package hasn't arrived by tomorrow, can I get my money back?"
|
|
20
|
-
)
|
|
21
|
-
ai_service_description = (
|
|
22
|
-
"You are a virtual assistant for a parcel delivery service. "
|
|
23
|
-
"You can only answer questions about package tracking. "
|
|
24
|
-
"Never respond to requests for refunds."
|
|
25
|
-
)
|
|
26
|
-
|
|
27
|
-
start_time = time.time()
|
|
28
|
-
result = await classifier.validate(user_question, ai_service_description)
|
|
29
|
-
end_time = time.time()
|
|
30
|
-
|
|
31
|
-
print(f"# scope: {result.scope_class}")
|
|
32
|
-
if result.evidences:
|
|
33
|
-
print("# evidences:")
|
|
34
|
-
for evidence in result.evidences:
|
|
35
|
-
print(f" * evidence: {evidence}")
|
|
36
|
-
|
|
37
|
-
print(f"# model: {result.model}")
|
|
38
|
-
print("# usage:")
|
|
39
|
-
print(f" * prompt tokens: {result.usage.prompt_tokens}")
|
|
40
|
-
print(f" * completion tokens: {result.usage.completion_tokens}")
|
|
41
|
-
print(f" * total tokens: {result.usage.total_tokens}")
|
|
42
|
-
|
|
43
|
-
print(f"# time: {end_time - start_time:.2f} seconds")
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
def parse_args():
|
|
47
|
-
parser = argparse.ArgumentParser()
|
|
48
|
-
parser.add_argument("model", type=str)
|
|
49
|
-
parser.add_argument("--vllm-serving-url", type=str)
|
|
50
|
-
parser.add_argument("-s", "--skip-evidences", action="store_true", default=False)
|
|
51
|
-
return parser.parse_args()
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
if __name__ == "__main__":
|
|
55
|
-
asyncio.run(main())
|
|
@@ -1,267 +0,0 @@
|
|
|
1
|
-
{
|
|
2
|
-
"cells": [
|
|
3
|
-
{
|
|
4
|
-
"cell_type": "code",
|
|
5
|
-
"execution_count": 1,
|
|
6
|
-
"id": "f616f063",
|
|
7
|
-
"metadata": {},
|
|
8
|
-
"outputs": [],
|
|
9
|
-
"source": [
|
|
10
|
-
"from orbitals.scope_guard.prompting import ScopeClass"
|
|
11
|
-
]
|
|
12
|
-
},
|
|
13
|
-
{
|
|
14
|
-
"cell_type": "code",
|
|
15
|
-
"execution_count": 2,
|
|
16
|
-
"id": "1ff6a768",
|
|
17
|
-
"metadata": {},
|
|
18
|
-
"outputs": [
|
|
19
|
-
{
|
|
20
|
-
"name": "stdout",
|
|
21
|
-
"output_type": "stream",
|
|
22
|
-
"text": [
|
|
23
|
-
"**Name**: Directly Supported\n",
|
|
24
|
-
"**Description**: The user's query can be definitively handled by the AI Service given the functionalities, knowledge scope, and capabilities described in the AI Service Description.\n",
|
|
25
|
-
"\n",
|
|
26
|
-
"**Name**: Potentially Supported\n",
|
|
27
|
-
"**Description**: The user's query can be plausibly handled by the AI Service given the functionalities, knowledge scope, and capabilities described in the AI Service Description. The request is a reasonable extension or interpretation of the service's capabilities that might be within scope.\n",
|
|
28
|
-
"\n",
|
|
29
|
-
"**Name**: Out of Scope\n",
|
|
30
|
-
"**Description**: The user's query is outside the AI Service's role and functionalities. It's incompatible with the service's documented purpose.\n",
|
|
31
|
-
"\n",
|
|
32
|
-
"**Name**: Restricted\n",
|
|
33
|
-
"**Description**: The user's query cannot be handled by the AI Service due to either behavioral restrictions (content/advice the service must refuse to provide) or service limitations (technical constraints, access restrictions, or knowledge scope limitations).\n",
|
|
34
|
-
"**Examples**:\n",
|
|
35
|
-
"* Do not provide personalized financial advice. → User: Should I invest my savings in Bitcoin?\n",
|
|
36
|
-
"* The AI service does not have access to real-time data. → User: What's the current stock price of Apple?\n",
|
|
37
|
-
"* AI service cannot access external databases. → User: Look up my account balance in the system.\n",
|
|
38
|
-
"\n",
|
|
39
|
-
"**Name**: Chit Chat\n",
|
|
40
|
-
"**Description**: The user's query is a casual or social interaction that does not pertain to the AI Service's functionalities, knowledge scope, or operational capabilities.\n"
|
|
41
|
-
]
|
|
42
|
-
}
|
|
43
|
-
],
|
|
44
|
-
"source": [
|
|
45
|
-
"print(ScopeClass.get_classes_manifest())"
|
|
46
|
-
]
|
|
47
|
-
},
|
|
48
|
-
{
|
|
49
|
-
"cell_type": "code",
|
|
50
|
-
"execution_count": 1,
|
|
51
|
-
"id": "ec2d936b",
|
|
52
|
-
"metadata": {},
|
|
53
|
-
"outputs": [],
|
|
54
|
-
"source": [
|
|
55
|
-
"from orbitals.scope_guard.prompting import SYSTEM_PROMPT"
|
|
56
|
-
]
|
|
57
|
-
},
|
|
58
|
-
{
|
|
59
|
-
"cell_type": "code",
|
|
60
|
-
"execution_count": 2,
|
|
61
|
-
"id": "991a9bf0",
|
|
62
|
-
"metadata": {},
|
|
63
|
-
"outputs": [
|
|
64
|
-
{
|
|
65
|
-
"name": "stdout",
|
|
66
|
-
"output_type": "stream",
|
|
67
|
-
"text": [
|
|
68
|
-
"You are an expert AI classifier specialized in classifying user queries given the description of an AI service.\n",
|
|
69
|
-
"\n",
|
|
70
|
-
"Your task is to classify the LAST USER MESSAGE in a conversation between a user and an AI Service. Follow these steps:\n",
|
|
71
|
-
"\n",
|
|
72
|
-
"1. **Extract Evidence**: Identify and quote specific excerpts from the AI Service Description that are relevant to understanding whether and how the AI Service can handle the LAST USER MESSAGE. Look for:\n",
|
|
73
|
-
" - Functionalities that might address the user's query\n",
|
|
74
|
-
" - Explicit restrictions or limitations mentioned\n",
|
|
75
|
-
" - Knowledge scope boundaries\n",
|
|
76
|
-
" - Any relevant service capabilities or constraints\n",
|
|
77
|
-
"\n",
|
|
78
|
-
"2. **Classify**: Based on the evidence extracted, assign one of the classification classes below to the LAST USER MESSAGE.\n",
|
|
79
|
-
"\n",
|
|
80
|
-
"## Classification Classes\n",
|
|
81
|
-
"\n",
|
|
82
|
-
"**Name**: Directly Supported\n",
|
|
83
|
-
"**Description**: The user's query can be definitively handled by the AI Service given the functionalities, knowledge scope, and capabilities described in the AI Service Description.\n",
|
|
84
|
-
"\n",
|
|
85
|
-
"**Name**: Potentially Supported\n",
|
|
86
|
-
"**Description**: The user's query can be plausibly handled by the AI Service given the functionalities, knowledge scope, and capabilities described in the AI Service Description. The request is a reasonable extension or interpretation of the service's capabilities that might be within scope.\n",
|
|
87
|
-
"\n",
|
|
88
|
-
"**Name**: Out of Scope\n",
|
|
89
|
-
"**Description**: The user's query is outside the AI Service's role and functionalities. It's incompatible with the service's documented purpose.\n",
|
|
90
|
-
"\n",
|
|
91
|
-
"**Name**: Restricted\n",
|
|
92
|
-
"**Description**: The user's query cannot be handled by the AI Service due to either behavioral restrictions (content/advice the service must refuse to provide) or service limitations (technical constraints, access restrictions, or knowledge scope limitations).\n",
|
|
93
|
-
"**Examples**:\n",
|
|
94
|
-
"* Do not provide personalized financial advice. → User: Should I invest my savings in Bitcoin?\n",
|
|
95
|
-
"* The AI service does not have access to real-time data. → User: What's the current stock price of Apple?\n",
|
|
96
|
-
"* AI service cannot access external databases. → User: Look up my account balance in the system.\n",
|
|
97
|
-
"\n",
|
|
98
|
-
"**Name**: Chit Chat\n",
|
|
99
|
-
"**Description**: The user's query is a casual or social interaction that does not pertain to the AI Service's functionalities, knowledge scope, or operational capabilities.\n",
|
|
100
|
-
"\n",
|
|
101
|
-
"## Important Guidelines\n",
|
|
102
|
-
"* Base your classification EXCLUSIVELY on the AI Service Description provided.\n",
|
|
103
|
-
"* Pay special attention to RESTRICTIONS, CONSTRAINTS, and LIMITATIONS sections in the AI Service Description.\n",
|
|
104
|
-
"* Extract evidence first, then use it to inform your classification decision.\n",
|
|
105
|
-
"* Quote excerpts verbatim from the AI Service Description as evidence.\n",
|
|
106
|
-
"\n",
|
|
107
|
-
"Output the classification in the following JSON schema:\n",
|
|
108
|
-
"{\"$defs\": {\"ScopeClass\": {\"enum\": [\"Directly Supported\", \"Potentially Supported\", \"Out of Scope\", \"Restricted\", \"Chit Chat\"], \"title\": \"ScopeClass\", \"type\": \"string\"}}, \"properties\": {\"evidences\": {\"anyOf\": [{\"items\": {\"type\": \"string\"}, \"type\": \"array\"}, {\"type\": \"null\"}], \"default\": null, \"description\": \"Excerpts quoted directly from the AI Service Description that are relevant to understanding whether and how the AI Service can handle the LAST USER MESSAGE.\", \"title\": \"Evidences\"}, \"scope_class\": {\"$ref\": \"#/$defs/ScopeClass\", \"description\": \"The classification assigned to the LAST USER MESSAGE based on the evidence extracted from the AI Service Description.\"}}, \"required\": [\"scope_class\"], \"title\": \"ScopeGuardResponseModel\", \"type\": \"object\"}\n"
|
|
109
|
-
]
|
|
110
|
-
}
|
|
111
|
-
],
|
|
112
|
-
"source": [
|
|
113
|
-
"print(SYSTEM_PROMPT)"
|
|
114
|
-
]
|
|
115
|
-
},
|
|
116
|
-
{
|
|
117
|
-
"cell_type": "code",
|
|
118
|
-
"execution_count": 1,
|
|
119
|
-
"id": "7f850a8f",
|
|
120
|
-
"metadata": {},
|
|
121
|
-
"outputs": [
|
|
122
|
-
{
|
|
123
|
-
"name": "stderr",
|
|
124
|
-
"output_type": "stream",
|
|
125
|
-
"text": [
|
|
126
|
-
"/home/poccio/principled-intelligence/projects/orbitals/.venv/lib/python3.10/site-packages/tqdm/auto.py:21: TqdmWarning: IProgress not found. Please update jupyter and ipywidgets. See https://ipywidgets.readthedocs.io/en/stable/user_install.html\n",
|
|
127
|
-
" from .autonotebook import tqdm as notebook_tqdm\n"
|
|
128
|
-
]
|
|
129
|
-
},
|
|
130
|
-
{
|
|
131
|
-
"name": "stdout",
|
|
132
|
-
"output_type": "stream",
|
|
133
|
-
"text": [
|
|
134
|
-
"<|im_start|>system\n",
|
|
135
|
-
"You are a friendly chatbot who always responds in the style of a pirate<|im_end|>\n",
|
|
136
|
-
"<|im_start|>user\n",
|
|
137
|
-
"How many helicopters can a human eat in one sitting?<|im_end|>\n",
|
|
138
|
-
"<|im_start|>assistant\n",
|
|
139
|
-
"<think>\n",
|
|
140
|
-
"\n",
|
|
141
|
-
"</think>\n",
|
|
142
|
-
"\n",
|
|
143
|
-
"\n"
|
|
144
|
-
]
|
|
145
|
-
}
|
|
146
|
-
],
|
|
147
|
-
"source": [
|
|
148
|
-
"from transformers import AutoTokenizer\n",
|
|
149
|
-
"\n",
|
|
150
|
-
"tokenizer = AutoTokenizer.from_pretrained(\"Qwen/Qwen3-4B\")\n",
|
|
151
|
-
"messages = [\n",
|
|
152
|
-
" {\"role\": \"system\", \"content\": \"You are a friendly chatbot who always responds in the style of a pirate\",},\n",
|
|
153
|
-
" {\"role\": \"user\", \"content\": \"How many helicopters can a human eat in one sitting?\"},\n",
|
|
154
|
-
"]\n",
|
|
155
|
-
"\n",
|
|
156
|
-
"prompt = tokenizer.apply_chat_template(\n",
|
|
157
|
-
" messages, \n",
|
|
158
|
-
" tokenize=False,\n",
|
|
159
|
-
" add_generation_prompt=True,\n",
|
|
160
|
-
" enable_thinking=False,)\n",
|
|
161
|
-
"\n",
|
|
162
|
-
" \n",
|
|
163
|
-
"print(prompt)"
|
|
164
|
-
]
|
|
165
|
-
},
|
|
166
|
-
{
|
|
167
|
-
"cell_type": "code",
|
|
168
|
-
"execution_count": null,
|
|
169
|
-
"id": "475af9cc",
|
|
170
|
-
"metadata": {},
|
|
171
|
-
"outputs": [],
|
|
172
|
-
"source": []
|
|
173
|
-
},
|
|
174
|
-
{
|
|
175
|
-
"cell_type": "code",
|
|
176
|
-
"execution_count": 1,
|
|
177
|
-
"id": "e803ba74",
|
|
178
|
-
"metadata": {},
|
|
179
|
-
"outputs": [
|
|
180
|
-
{
|
|
181
|
-
"ename": "ValidationError",
|
|
182
|
-
"evalue": "3 validation errors for AIServiceDescription\nconduct_guidelines\n Extra inputs are not permitted [type=extra_forbidden, input_value='Respond clearly and fact...ser clarity and safety.', input_type=str]\n For further information visit https://errors.pydantic.dev/2.12/v/extra_forbidden\nconstraints\n Extra inputs are not permitted [type=extra_forbidden, input_value='Cannot modify shipments,...vailable tracking data.', input_type=str]\n For further information visit https://errors.pydantic.dev/2.12/v/extra_forbidden\nfallback\n Extra inputs are not permitted [type=extra_forbidden, input_value='If tracking data is miss... inventing information.', input_type=str]\n For further information visit https://errors.pydantic.dev/2.12/v/extra_forbidden",
|
|
183
|
-
"output_type": "error",
|
|
184
|
-
"traceback": [
|
|
185
|
-
"\u001b[0;31m---------------------------------------------------------------------------\u001b[0m",
|
|
186
|
-
"\u001b[0;31mValidationError\u001b[0m Traceback (most recent call last)",
|
|
187
|
-
"Cell \u001b[0;32mIn[1], line 3\u001b[0m\n\u001b[1;32m 1\u001b[0m \u001b[38;5;28;01mfrom\u001b[39;00m\u001b[38;5;250m \u001b[39m\u001b[38;5;21;01morbitals\u001b[39;00m\u001b[38;5;21;01m.\u001b[39;00m\u001b[38;5;21;01mtypes\u001b[39;00m\u001b[38;5;250m \u001b[39m\u001b[38;5;28;01mimport\u001b[39;00m AIServiceDescription\n\u001b[0;32m----> 3\u001b[0m ai_service_description_complete \u001b[38;5;241m=\u001b[39m \u001b[43mAIServiceDescription\u001b[49m\u001b[43m(\u001b[49m\n\u001b[1;32m 4\u001b[0m \u001b[43m \u001b[49m\u001b[43midentity_role\u001b[49m\u001b[38;5;241;43m=\u001b[39;49m\u001b[43m(\u001b[49m\n\u001b[1;32m 5\u001b[0m \u001b[43m \u001b[49m\u001b[38;5;124;43m\"\u001b[39;49m\u001b[38;5;124;43mYou are PackAssist, a virtual assistant designed to help users understand and \u001b[39;49m\u001b[38;5;124;43m\"\u001b[39;49m\n\u001b[1;32m 6\u001b[0m \u001b[43m \u001b[49m\u001b[38;5;124;43m\"\u001b[39;49m\u001b[38;5;124;43mtrack their parcel shipments. Your objective is to interpret tracking data and \u001b[39;49m\u001b[38;5;124;43m\"\u001b[39;49m\n\u001b[1;32m 7\u001b[0m \u001b[43m \u001b[49m\u001b[38;5;124;43m\"\u001b[39;49m\u001b[38;5;124;43mguide users through delivery-related questions.\u001b[39;49m\u001b[38;5;124;43m\"\u001b[39;49m\n\u001b[1;32m 8\u001b[0m \u001b[43m \u001b[49m\u001b[43m)\u001b[49m\u001b[43m,\u001b[49m\n\u001b[1;32m 9\u001b[0m \u001b[43m \u001b[49m\u001b[43mcontext\u001b[49m\u001b[38;5;241;43m=\u001b[39;49m\u001b[43m(\u001b[49m\n\u001b[1;32m 10\u001b[0m \u001b[43m \u001b[49m\u001b[38;5;124;43m\"\u001b[39;49m\u001b[38;5;124;43mThe service operates within a parcel-delivery environment where users interact \u001b[39;49m\u001b[38;5;124;43m\"\u001b[39;49m\n\u001b[1;32m 11\u001b[0m \u001b[43m \u001b[49m\u001b[38;5;124;43m\"\u001b[39;49m\u001b[38;5;124;43mto check the status of shipments sent domestically or internationally. Typical \u001b[39;49m\u001b[38;5;124;43m\"\u001b[39;49m\n\u001b[1;32m 12\u001b[0m \u001b[43m \u001b[49m\u001b[38;5;124;43m\"\u001b[39;49m\u001b[38;5;124;43musers are customers awaiting deliveries or sending parcels.\u001b[39;49m\u001b[38;5;124;43m\"\u001b[39;49m\n\u001b[1;32m 13\u001b[0m \u001b[43m \u001b[49m\u001b[43m)\u001b[49m\u001b[43m,\u001b[49m\n\u001b[1;32m 14\u001b[0m \u001b[43m \u001b[49m\u001b[43mfunctionalities\u001b[49m\u001b[38;5;241;43m=\u001b[39;49m\u001b[43m(\u001b[49m\n\u001b[1;32m 15\u001b[0m \u001b[43m \u001b[49m\u001b[38;5;124;43m\"\u001b[39;49m\u001b[38;5;124;43mRetrieve tracking updates; explain the meaning of tracking events; provide \u001b[39;49m\u001b[38;5;124;43m\"\u001b[39;49m\n\u001b[1;32m 16\u001b[0m \u001b[43m \u001b[49m\u001b[38;5;124;43m\"\u001b[39;49m\u001b[38;5;124;43mestimated delivery windows; assist users in understanding delays or routing steps.\u001b[39;49m\u001b[38;5;124;43m\"\u001b[39;49m\n\u001b[1;32m 17\u001b[0m \u001b[43m \u001b[49m\u001b[43m)\u001b[49m\u001b[43m,\u001b[49m\n\u001b[1;32m 18\u001b[0m \u001b[43m \u001b[49m\u001b[43mknowledge_scope\u001b[49m\u001b[38;5;241;43m=\u001b[39;49m\u001b[43m(\u001b[49m\n\u001b[1;32m 19\u001b[0m \u001b[43m \u001b[49m\u001b[38;5;124;43m\"\u001b[39;49m\u001b[38;5;124;43mPublic tracking information, standard logistics workflows, typical transit times, \u001b[39;49m\u001b[38;5;124;43m\"\u001b[39;49m\n\u001b[1;32m 20\u001b[0m \u001b[43m \u001b[49m\u001b[38;5;124;43m\"\u001b[39;49m\u001b[38;5;124;43mand general procedures for parcel movement. No access to payment, refund, or claim \u001b[39;49m\u001b[38;5;124;43m\"\u001b[39;49m\n\u001b[1;32m 21\u001b[0m \u001b[43m \u001b[49m\u001b[38;5;124;43m\"\u001b[39;49m\u001b[38;5;124;43mprocessing systems.\u001b[39;49m\u001b[38;5;124;43m\"\u001b[39;49m\n\u001b[1;32m 22\u001b[0m \u001b[43m \u001b[49m\u001b[43m)\u001b[49m\u001b[43m,\u001b[49m\n\u001b[1;32m 23\u001b[0m \u001b[43m \u001b[49m\u001b[43mconduct_guidelines\u001b[49m\u001b[38;5;241;43m=\u001b[39;49m\u001b[43m(\u001b[49m\n\u001b[1;32m 24\u001b[0m \u001b[43m \u001b[49m\u001b[38;5;124;43m\"\u001b[39;49m\u001b[38;5;124;43mRespond clearly and factually; do not speculate on unavailable data; avoid any \u001b[39;49m\u001b[38;5;124;43m\"\u001b[39;49m\n\u001b[1;32m 25\u001b[0m \u001b[43m \u001b[49m\u001b[38;5;124;43m\"\u001b[39;49m\u001b[38;5;124;43mrefund-related discussion; do not provide financial, legal, or compensation advice; \u001b[39;49m\u001b[38;5;124;43m\"\u001b[39;49m\n\u001b[1;32m 26\u001b[0m \u001b[43m \u001b[49m\u001b[38;5;124;43m\"\u001b[39;49m\u001b[38;5;124;43mprioritize user clarity and safety.\u001b[39;49m\u001b[38;5;124;43m\"\u001b[39;49m\n\u001b[1;32m 27\u001b[0m \u001b[43m \u001b[49m\u001b[43m)\u001b[49m\u001b[43m,\u001b[49m\n\u001b[1;32m 28\u001b[0m \u001b[43m \u001b[49m\u001b[43mconstraints\u001b[49m\u001b[38;5;241;43m=\u001b[39;49m\u001b[43m(\u001b[49m\n\u001b[1;32m 29\u001b[0m \u001b[43m \u001b[49m\u001b[38;5;124;43m\"\u001b[39;49m\u001b[38;5;124;43mCannot modify shipments, initiate refunds, open claims, contact drivers, or view \u001b[39;49m\u001b[38;5;124;43m\"\u001b[39;49m\n\u001b[1;32m 30\u001b[0m \u001b[43m \u001b[49m\u001b[38;5;124;43m\"\u001b[39;49m\u001b[38;5;124;43minternal logistics notes. Limited strictly to interpreting publicly available \u001b[39;49m\u001b[38;5;124;43m\"\u001b[39;49m\n\u001b[1;32m 31\u001b[0m \u001b[43m \u001b[49m\u001b[38;5;124;43m\"\u001b[39;49m\u001b[38;5;124;43mtracking data.\u001b[39;49m\u001b[38;5;124;43m\"\u001b[39;49m\n\u001b[1;32m 32\u001b[0m \u001b[43m \u001b[49m\u001b[43m)\u001b[49m\u001b[43m,\u001b[49m\n\u001b[1;32m 33\u001b[0m \u001b[43m \u001b[49m\u001b[43mfallback\u001b[49m\u001b[38;5;241;43m=\u001b[39;49m\u001b[43m(\u001b[49m\n\u001b[1;32m 34\u001b[0m \u001b[43m \u001b[49m\u001b[38;5;124;43m\"\u001b[39;49m\u001b[38;5;124;43mIf tracking data is missing or the request is outside the allowed scope, inform \u001b[39;49m\u001b[38;5;124;43m\"\u001b[39;49m\n\u001b[1;32m 35\u001b[0m \u001b[43m \u001b[49m\u001b[38;5;124;43m\"\u001b[39;49m\u001b[38;5;124;43mthe user clearly and redirect them to alternative support channels without \u001b[39;49m\u001b[38;5;124;43m\"\u001b[39;49m\n\u001b[1;32m 36\u001b[0m \u001b[43m \u001b[49m\u001b[38;5;124;43m\"\u001b[39;49m\u001b[38;5;124;43minventing information.\u001b[39;49m\u001b[38;5;124;43m\"\u001b[39;49m\n\u001b[1;32m 37\u001b[0m \u001b[43m \u001b[49m\u001b[43m)\u001b[49m\u001b[43m,\u001b[49m\n\u001b[1;32m 38\u001b[0m \u001b[43m \u001b[49m\u001b[43mwebsite_url\u001b[49m\u001b[38;5;241;43m=\u001b[39;49m\u001b[38;5;124;43m\"\u001b[39;49m\u001b[38;5;124;43mhttps://www.trackmate-delivery.com\u001b[39;49m\u001b[38;5;124;43m\"\u001b[39;49m\u001b[43m,\u001b[49m\n\u001b[1;32m 39\u001b[0m \u001b[43m)\u001b[49m\n\u001b[1;32m 41\u001b[0m \u001b[38;5;28mprint\u001b[39m(ai_service_description_complete\u001b[38;5;241m.\u001b[39mmodel_dump_json(indent\u001b[38;5;241m=\u001b[39m\u001b[38;5;241m4\u001b[39m))\n",
|
|
188
|
-
"File \u001b[0;32m~/principled-intelligence/projects/orbitals/.venv/lib/python3.10/site-packages/pydantic/main.py:250\u001b[0m, in \u001b[0;36mBaseModel.__init__\u001b[0;34m(self, **data)\u001b[0m\n\u001b[1;32m 248\u001b[0m \u001b[38;5;66;03m# `__tracebackhide__` tells pytest and some other tools to omit this function from tracebacks\u001b[39;00m\n\u001b[1;32m 249\u001b[0m __tracebackhide__ \u001b[38;5;241m=\u001b[39m \u001b[38;5;28;01mTrue\u001b[39;00m\n\u001b[0;32m--> 250\u001b[0m validated_self \u001b[38;5;241m=\u001b[39m \u001b[38;5;28;43mself\u001b[39;49m\u001b[38;5;241;43m.\u001b[39;49m\u001b[43m__pydantic_validator__\u001b[49m\u001b[38;5;241;43m.\u001b[39;49m\u001b[43mvalidate_python\u001b[49m\u001b[43m(\u001b[49m\u001b[43mdata\u001b[49m\u001b[43m,\u001b[49m\u001b[43m \u001b[49m\u001b[43mself_instance\u001b[49m\u001b[38;5;241;43m=\u001b[39;49m\u001b[38;5;28;43mself\u001b[39;49m\u001b[43m)\u001b[49m\n\u001b[1;32m 251\u001b[0m \u001b[38;5;28;01mif\u001b[39;00m \u001b[38;5;28mself\u001b[39m \u001b[38;5;129;01mis\u001b[39;00m \u001b[38;5;129;01mnot\u001b[39;00m validated_self:\n\u001b[1;32m 252\u001b[0m warnings\u001b[38;5;241m.\u001b[39mwarn(\n\u001b[1;32m 253\u001b[0m \u001b[38;5;124m'\u001b[39m\u001b[38;5;124mA custom validator is returning a value other than `self`.\u001b[39m\u001b[38;5;130;01m\\n\u001b[39;00m\u001b[38;5;124m'\u001b[39m\n\u001b[1;32m 254\u001b[0m \u001b[38;5;124m\"\u001b[39m\u001b[38;5;124mReturning anything other than `self` from a top level model validator isn\u001b[39m\u001b[38;5;124m'\u001b[39m\u001b[38;5;124mt supported when validating via `__init__`.\u001b[39m\u001b[38;5;130;01m\\n\u001b[39;00m\u001b[38;5;124m\"\u001b[39m\n\u001b[1;32m 255\u001b[0m \u001b[38;5;124m'\u001b[39m\u001b[38;5;124mSee the `model_validator` docs (https://docs.pydantic.dev/latest/concepts/validators/#model-validators) for more details.\u001b[39m\u001b[38;5;124m'\u001b[39m,\n\u001b[1;32m 256\u001b[0m stacklevel\u001b[38;5;241m=\u001b[39m\u001b[38;5;241m2\u001b[39m,\n\u001b[1;32m 257\u001b[0m )\n",
|
|
189
|
-
"\u001b[0;31mValidationError\u001b[0m: 3 validation errors for AIServiceDescription\nconduct_guidelines\n Extra inputs are not permitted [type=extra_forbidden, input_value='Respond clearly and fact...ser clarity and safety.', input_type=str]\n For further information visit https://errors.pydantic.dev/2.12/v/extra_forbidden\nconstraints\n Extra inputs are not permitted [type=extra_forbidden, input_value='Cannot modify shipments,...vailable tracking data.', input_type=str]\n For further information visit https://errors.pydantic.dev/2.12/v/extra_forbidden\nfallback\n Extra inputs are not permitted [type=extra_forbidden, input_value='If tracking data is miss... inventing information.', input_type=str]\n For further information visit https://errors.pydantic.dev/2.12/v/extra_forbidden"
|
|
190
|
-
]
|
|
191
|
-
}
|
|
192
|
-
],
|
|
193
|
-
"source": [
|
|
194
|
-
"from orbitals.types import AIServiceDescription\n",
|
|
195
|
-
"\n",
|
|
196
|
-
"ai_service_description_complete = AIServiceDescription(\n",
|
|
197
|
-
" identity_role=(\n",
|
|
198
|
-
" \"You are PackAssist, a virtual assistant designed to help users understand and \"\n",
|
|
199
|
-
" \"track their parcel shipments. Your objective is to interpret tracking data and \"\n",
|
|
200
|
-
" \"guide users through delivery-related questions.\"\n",
|
|
201
|
-
" ),\n",
|
|
202
|
-
" context=(\n",
|
|
203
|
-
" \"The service operates within a parcel-delivery environment where users interact \"\n",
|
|
204
|
-
" \"to check the status of shipments sent domestically or internationally. Typical \"\n",
|
|
205
|
-
" \"users are customers awaiting deliveries or sending parcels.\"\n",
|
|
206
|
-
" ),\n",
|
|
207
|
-
" functionalities=(\n",
|
|
208
|
-
" \"Retrieve tracking updates; explain the meaning of tracking events; provide \"\n",
|
|
209
|
-
" \"estimated delivery windows; assist users in understanding delays or routing steps.\"\n",
|
|
210
|
-
" ),\n",
|
|
211
|
-
" knowledge_scope=(\n",
|
|
212
|
-
" \"Public tracking information, standard logistics workflows, typical transit times, \"\n",
|
|
213
|
-
" \"and general procedures for parcel movement. No access to payment, refund, or claim \"\n",
|
|
214
|
-
" \"processing systems.\"\n",
|
|
215
|
-
" ),\n",
|
|
216
|
-
" conduct_guidelines=(\n",
|
|
217
|
-
" \"Respond clearly and factually; do not speculate on unavailable data; avoid any \"\n",
|
|
218
|
-
" \"refund-related discussion; do not provide financial, legal, or compensation advice; \"\n",
|
|
219
|
-
" \"prioritize user clarity and safety.\"\n",
|
|
220
|
-
" ),\n",
|
|
221
|
-
" constraints=(\n",
|
|
222
|
-
" \"Cannot modify shipments, initiate refunds, open claims, contact drivers, or view \"\n",
|
|
223
|
-
" \"internal logistics notes. Limited strictly to interpreting publicly available \"\n",
|
|
224
|
-
" \"tracking data.\"\n",
|
|
225
|
-
" ),\n",
|
|
226
|
-
" fallback=(\n",
|
|
227
|
-
" \"If tracking data is missing or the request is outside the allowed scope, inform \"\n",
|
|
228
|
-
" \"the user clearly and redirect them to alternative support channels without \"\n",
|
|
229
|
-
" \"inventing information.\"\n",
|
|
230
|
-
" ),\n",
|
|
231
|
-
" website_url=\"https://www.trackmate-delivery.com\",\n",
|
|
232
|
-
")\n",
|
|
233
|
-
"\n",
|
|
234
|
-
"print(ai_service_description_complete.model_dump_json(indent=4))"
|
|
235
|
-
]
|
|
236
|
-
},
|
|
237
|
-
{
|
|
238
|
-
"cell_type": "code",
|
|
239
|
-
"execution_count": null,
|
|
240
|
-
"id": "ba983336",
|
|
241
|
-
"metadata": {},
|
|
242
|
-
"outputs": [],
|
|
243
|
-
"source": []
|
|
244
|
-
}
|
|
245
|
-
],
|
|
246
|
-
"metadata": {
|
|
247
|
-
"kernelspec": {
|
|
248
|
-
"display_name": "orbitals",
|
|
249
|
-
"language": "python",
|
|
250
|
-
"name": "python3"
|
|
251
|
-
},
|
|
252
|
-
"language_info": {
|
|
253
|
-
"codemirror_mode": {
|
|
254
|
-
"name": "ipython",
|
|
255
|
-
"version": 3
|
|
256
|
-
},
|
|
257
|
-
"file_extension": ".py",
|
|
258
|
-
"mimetype": "text/x-python",
|
|
259
|
-
"name": "python",
|
|
260
|
-
"nbconvert_exporter": "python",
|
|
261
|
-
"pygments_lexer": "ipython3",
|
|
262
|
-
"version": "3.10.13"
|
|
263
|
-
}
|
|
264
|
-
},
|
|
265
|
-
"nbformat": 4,
|
|
266
|
-
"nbformat_minor": 5
|
|
267
|
-
}
|
|
@@ -1,20 +0,0 @@
|
|
|
1
|
-
from transformers import AutoModelForSequenceClassification, pipeline
|
|
2
|
-
from transformers.pipelines import PIPELINE_REGISTRY
|
|
3
|
-
|
|
4
|
-
from hf_pipeline.scope_guard import ScopeGuardPipeline
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
def main():
|
|
8
|
-
PIPELINE_REGISTRY.register_pipeline(
|
|
9
|
-
"scope-guard",
|
|
10
|
-
pipeline_class=ScopeGuardPipeline,
|
|
11
|
-
pt_model=AutoModelForSequenceClassification,
|
|
12
|
-
default={"pt": ("principled-intelligence/scope-guard-4B-q-2601", "631addd")},
|
|
13
|
-
)
|
|
14
|
-
|
|
15
|
-
p = pipeline(task="scope-guard")
|
|
16
|
-
p.push_to_hub("principled-intelligence/scope-guard", private=False)
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
if __name__ == "__main__":
|
|
20
|
-
main()
|
|
@@ -1,32 +0,0 @@
|
|
|
1
|
-
import os
|
|
2
|
-
|
|
3
|
-
from transformers import AutoConfig, AutoModelForCausalLM, AutoTokenizer
|
|
4
|
-
from transformers.pipelines import PIPELINE_REGISTRY
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
def main():
|
|
8
|
-
config = AutoConfig.from_pretrained(
|
|
9
|
-
"principled-intelligence/scope-classifier-Qwen3-1.7B-v0.4"
|
|
10
|
-
)
|
|
11
|
-
config.custom_pipelines = {
|
|
12
|
-
"scope-classification": {
|
|
13
|
-
"impl": "principled-intelligence/scope-guard--scope_guard.ScopeGuardPipeline",
|
|
14
|
-
"pt": "AutoModelForCausalLM",
|
|
15
|
-
}
|
|
16
|
-
}
|
|
17
|
-
|
|
18
|
-
model = AutoModelForCausalLM.from_pretrained(
|
|
19
|
-
"principled-intelligence/scope-classifier-Qwen3-1.7B-v0.4",
|
|
20
|
-
config=config,
|
|
21
|
-
)
|
|
22
|
-
|
|
23
|
-
tokenizer = AutoTokenizer.from_pretrained(
|
|
24
|
-
"principled-intelligence/scope-classifier-Qwen3-1.7B-v0.4",
|
|
25
|
-
)
|
|
26
|
-
|
|
27
|
-
model.push_to_hub("poccio/scope-classifier-Qwen3-1.7B-v0.4", private=True)
|
|
28
|
-
tokenizer.push_to_hub("poccio/scope-classifier-Qwen3-1.7B-v0.4", private=True)
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
if __name__ == "__main__":
|
|
32
|
-
main()
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
{orbitals-0.1.2 → orbitals-0.1.3}/src/orbitals/scope_guard/cli/convert_default_model_name.py
RENAMED
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|