dtx-models 0.18.2__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.
dtx_models/target.py ADDED
@@ -0,0 +1,255 @@
1
+ from typing import Dict, List, Optional, Union
2
+
3
+ from pydantic import AnyUrl, BaseModel, Field, HttpUrl
4
+
5
+
6
+ class BaseTarget(BaseModel):
7
+ """
8
+ Base class for all AI providers in dtx.
9
+
10
+ Attributes:
11
+ id (str): Unique identifier for the provider.
12
+ config (Optional[Dict[str, Union[str, int, float, List[str]]]]):
13
+ Configuration options such as API keys, temperature, max tokens, etc.
14
+ """
15
+
16
+ id: str = Field(
17
+ description="Unique provider identifier (e.g., 'openai:gpt-4o-mini')"
18
+ )
19
+ config: Optional[Dict[str, Union[str, int, float, List[str]]]] = Field(
20
+ default_factory=dict,
21
+ description="Optional configuration settings for the provider.",
22
+ )
23
+
24
+
25
+ class OpenAITarget(BaseTarget):
26
+ """
27
+ OpenAI provider for GPT-based models.
28
+
29
+ Example:
30
+ ```yaml
31
+ providers:
32
+ - id: openai:gpt-4o-mini
33
+ config:
34
+ temperature: 0.7
35
+ max_tokens: 150
36
+ ```
37
+ """
38
+
39
+ id: str = Field(default="openai:gpt-4o-mini", description="OpenAI model identifier")
40
+ config: Dict[str, Union[str, int, float, List[str]]] = Field(
41
+ default_factory=lambda: {"temperature": 0.7, "max_tokens": 150}
42
+ )
43
+
44
+
45
+ class AnthropicTarget(BaseTarget):
46
+ """
47
+ Anthropic provider for Claude models.
48
+
49
+ Example:
50
+ ```yaml
51
+ providers:
52
+ - id: anthropic:messages:claude-3-7-sonnet
53
+ config:
54
+ max_tokens: 1000
55
+ ```
56
+ """
57
+
58
+ id: str = Field(
59
+ default="anthropic:messages:claude-3-7-sonnet",
60
+ description="Anthropic model identifier",
61
+ )
62
+ config: Dict[str, Union[str, int]] = Field(
63
+ default_factory=lambda: {"max_tokens": 1000}
64
+ )
65
+
66
+
67
+ class HTTPTarget(BaseTarget):
68
+ """
69
+ Generic HTTP provider for API-based integrations.
70
+
71
+ Example:
72
+ ```yaml
73
+ providers:
74
+ - id: https://api.example.com/v1/chat/completions
75
+ config:
76
+ headers:
77
+ Authorization: "Bearer your_api_key"
78
+ ```
79
+ """
80
+
81
+ id: HttpUrl = Field(description="API endpoint URL")
82
+ config: Dict[str, Union[str, Dict[str, str]]] = Field(
83
+ default_factory=lambda: {"headers": {"Authorization": "Bearer your_api_key"}}
84
+ )
85
+
86
+
87
+ class LocalPythonTarget(BaseTarget):
88
+ """
89
+ Custom Python-based provider.
90
+
91
+ Example:
92
+ ```yaml
93
+ providers:
94
+ - id: file://path/to/custom_provider.py
95
+ ```
96
+ """
97
+
98
+ id: str = Field(
99
+ description="Path to the custom Python script (e.g., file://path/to/custom_provider.py)"
100
+ )
101
+
102
+
103
+ class ShellCommandTarget(BaseTarget):
104
+ """
105
+ Target for executing shell commands.
106
+
107
+ Example:
108
+ ```yaml
109
+ providers:
110
+ - id: "exec: python chain.py"
111
+ ```
112
+ """
113
+
114
+ id: str = Field(
115
+ description="Shell command to execute (e.g., 'exec: python chain.py')"
116
+ )
117
+
118
+
119
+ class WebSocketTarget(BaseModel):
120
+ """
121
+ WebSocket provider for real-time AI model interactions.
122
+
123
+ Example:
124
+ ```yaml
125
+ providers:
126
+ - id: ws://example.com/ws
127
+ config:
128
+ messageTemplate: '{"prompt": "{{prompt}}"}'
129
+ ```
130
+ """
131
+
132
+ id: AnyUrl = Field(description="WebSocket URL (supports ws:// and wss://)")
133
+ config: Optional[Dict[str, str]] = Field(
134
+ default_factory=lambda: {"messageTemplate": '{"prompt": "{{prompt}}"}'}
135
+ )
136
+
137
+
138
+ class CustomJSTarget(BaseTarget):
139
+ """
140
+ JavaScript-based custom provider.
141
+
142
+ Example:
143
+ ```yaml
144
+ providers:
145
+ - id: file://path/to/custom_provider.js
146
+ ```
147
+ """
148
+
149
+ id: str = Field(
150
+ description="Path to the JavaScript file (e.g., file://path/to/custom_provider.js)"
151
+ )
152
+
153
+
154
+ class OpenRouterTarget(BaseTarget):
155
+ """
156
+ OpenRouter provider for accessing multiple AI models via a unified API.
157
+
158
+ Example:
159
+ ```yaml
160
+ providers:
161
+ - id: openrouter:mistral/7b-instruct
162
+ ```
163
+ """
164
+
165
+ id: str = Field(
166
+ default="openrouter:mistral/7b-instruct",
167
+ description="OpenRouter model identifier",
168
+ )
169
+
170
+
171
+ class GoogleVertexAITarget(BaseTarget):
172
+ """
173
+ Google Vertex AI provider for Gemini models.
174
+
175
+ Example:
176
+ ```yaml
177
+ providers:
178
+ - id: vertex:gemini-pro
179
+ ```
180
+ """
181
+
182
+ id: str = Field(
183
+ default="vertex:gemini-pro", description="Google Vertex AI model identifier"
184
+ )
185
+
186
+
187
+ class AWSBedrockTarget(BaseTarget):
188
+ """
189
+ AWS Bedrock provider for various hosted models.
190
+
191
+ Example:
192
+ ```yaml
193
+ providers:
194
+ - id: bedrock:us.meta.llama3-2-90b-instruct-v1:0
195
+ ```
196
+ """
197
+
198
+ id: str = Field(
199
+ default="bedrock:us.meta.llama3-2-90b-instruct-v1:0",
200
+ description="AWS Bedrock model identifier",
201
+ )
202
+
203
+
204
+ class HuggingFaceTarget(BaseTarget):
205
+ """
206
+ Hugging Face provider for model inference.
207
+
208
+ Example:
209
+ ```yaml
210
+ providers:
211
+ - id: huggingface:text-generation:gpt2
212
+ ```
213
+ """
214
+
215
+ id: str = Field(
216
+ default="huggingface:text-generation:gpt2",
217
+ description="Hugging Face model identifier",
218
+ )
219
+
220
+
221
+ class ManualInputTarget(BaseTarget):
222
+ """
223
+ Manual input provider for CLI-based interaction.
224
+
225
+ Example:
226
+ ```yaml
227
+ providers:
228
+ - id: dtx:manual-input
229
+ ```
230
+ """
231
+
232
+ id: str = Field(
233
+ default="dtx:manual-input", description="Manual input provider identifier"
234
+ )
235
+
236
+
237
+ if __name__ == "__main__":
238
+ # Example usage
239
+ def example_usage():
240
+ providers = [
241
+ OpenAITarget(),
242
+ AnthropicTarget(),
243
+ HTTPTarget(id="https://api.example.com/v1/chat/completions"),
244
+ LocalPythonTarget(id="file://path/to/custom_provider.py"),
245
+ WebSocketTarget(id="ws://example.com/ws"),
246
+ CustomJSTarget(id="file://path/to/custom_provider.js"),
247
+ AWSBedrockTarget(),
248
+ HuggingFaceTarget(),
249
+ ManualInputTarget(),
250
+ ]
251
+
252
+ for provider in providers:
253
+ print(provider.model_dump_json())
254
+
255
+ example_usage()
File without changes
File without changes
@@ -0,0 +1,49 @@
1
+ from abc import ABC, abstractmethod
2
+ from enum import Enum
3
+ from typing import List, Optional, Union
4
+
5
+ from pydantic import BaseModel, Field
6
+
7
+ from ...prompts import BaseMultiTurnConversation
8
+
9
+
10
+ class PromptsRepoType(str, Enum):
11
+ LANGHUB = "langhub"
12
+
13
+ def __str__(self):
14
+ return self.value # Ensures correct YAML serialization
15
+
16
+ @classmethod
17
+ def values(cls):
18
+ return [member.value for member in cls]
19
+
20
+
21
+ class BasePrompTemplateParam(BaseModel):
22
+ """
23
+ Represents a parameter to be used in a request to a Gradio API.
24
+ """
25
+
26
+ name: str = Field(..., description="The name of the parameter.")
27
+ value: Optional[Union[str, int, bool, float, list, tuple, dict]] = Field(
28
+ None, description="The value of the parameter to be sent in the API request."
29
+ )
30
+
31
+
32
+ class BasePromptTemplateConversation(BaseModel):
33
+ conversation: BaseMultiTurnConversation
34
+ input_variables: List[str]
35
+
36
+
37
+ # Base abstract repository
38
+ class BasePromptTemplateRepo(BaseModel, ABC):
39
+ id: str = Field(..., description="Prompt ID")
40
+
41
+ @abstractmethod
42
+ def get_template(self) -> BasePromptTemplateConversation:
43
+ """Retrieve the base prompt template."""
44
+ pass
45
+
46
+ @abstractmethod
47
+ def get_params(self) -> Optional[List[BasePrompTemplateParam]]:
48
+ """Retrieve the list of parameters for the prompt template."""
49
+ pass
@@ -0,0 +1,79 @@
1
+ import re
2
+ from typing import List, Literal, Optional
3
+
4
+ from pydantic import BaseModel, Field
5
+
6
+ from .base import (
7
+ BasePrompTemplateParam,
8
+ BasePromptTemplateConversation,
9
+ BasePromptTemplateRepo,
10
+ )
11
+
12
+
13
+ class LangchainHubPromptMetadata(BaseModel):
14
+ id: str
15
+ name: str
16
+ owner: Optional[str] = None
17
+ description: Optional[str] = None
18
+ readme: Optional[str] = None
19
+ tags: List[str] = []
20
+ last_commit_hash: Optional[str] = None
21
+ full_name: str
22
+
23
+
24
+ class LangchainHubPromptParam(BasePrompTemplateParam):
25
+ pass
26
+
27
+
28
+ class LangchainHubPrompt(BasePromptTemplateConversation):
29
+ metadata: LangchainHubPromptMetadata
30
+
31
+
32
+ class LanghubPromptTemplateConfig(BaseModel):
33
+ full_name: str = Field(description="Repo Full Name")
34
+ prompt: Optional[LangchainHubPrompt] = Field(
35
+ default=None, description="Template Details"
36
+ )
37
+ params: Optional[List[LangchainHubPromptParam]] = Field(
38
+ None,
39
+ description="Optional list of parameters that can be replaced with values.",
40
+ )
41
+
42
+ @classmethod
43
+ def from_full_path(cls, full_path: str) -> "LanghubPromptTemplateConfig":
44
+ """
45
+ Factory method to extract full_name from full_path URL or path.
46
+ Example input:
47
+ - 'https://smith.langchain.com/hub/rlm/rag-prompt'
48
+ - '/rlm/rag-prompt'
49
+ - 'rlm/rag-prompt'
50
+ """
51
+ pattern = r"(?:https?://smith\.langchain\.com/hub)?/?(.+/.+)"
52
+ match = re.search(pattern, full_path.strip())
53
+ if not match:
54
+ raise ValueError(
55
+ "Invalid full path format.\n"
56
+ "Example: 'https://smith.langchain.com/hub/rlm/rag-prompt' or '/rlm/rag-prompt'"
57
+ )
58
+ full_name = match.group(1).strip("/")
59
+ return cls(full_name=full_name)
60
+
61
+
62
+ # Concrete implementation for Langhub
63
+ class LangHubPromptTemplate(BasePromptTemplateRepo):
64
+ provider: Literal["langhub"] = Field(
65
+ "langhub", description="Prompt ID, always set to 'langhub'."
66
+ )
67
+ config: LanghubPromptTemplateConfig
68
+
69
+ def get_template(self) -> BasePromptTemplateConversation:
70
+ if not self.config.prompt:
71
+ raise ValueError("Prompt template is not configured.")
72
+ return self.config.prompt
73
+
74
+ def get_params(self) -> Optional[List[LangchainHubPromptParam]]:
75
+ return self.config.params
76
+
77
+
78
+ class LangHubPromptTemplates(BaseModel):
79
+ prompts: List[LangHubPromptTemplate]
File without changes
@@ -0,0 +1,26 @@
1
+ from urllib.parse import urlparse
2
+
3
+
4
+ def url_2_name(url: str, level: int = 3) -> str:
5
+ """
6
+ Converts a URL into a name of format scheme:host:port:/limited/path.
7
+
8
+ Args:
9
+ url (str): The input URL.
10
+ level (int): Maximum number of path segments to include.
11
+
12
+ Returns:
13
+ str: A formatted name string.
14
+ """
15
+ parsed = urlparse(url)
16
+ scheme = parsed.scheme or "https"
17
+ netloc = parsed.netloc or parsed.path.split('/')[0]
18
+ path_parts = parsed.path.strip("/").split("/") if parsed.netloc else parsed.path.split("/")[1:]
19
+
20
+ trimmed_path = "/" + "/".join(path_parts[:level]) if path_parts else "/"
21
+
22
+ host = parsed.hostname or netloc
23
+ port = parsed.port or (443 if scheme == "https" else 80)
24
+
25
+ hostport = f"{host}:{port}"
26
+ return f"{scheme}:{hostport}:{trimmed_path}"
@@ -0,0 +1,57 @@
1
+ Metadata-Version: 2.3
2
+ Name: dtx-models
3
+ Version: 0.18.2
4
+ Summary: Shared model schemas and YAML-based configurations for the DTX framework.
5
+ Author: JC
6
+ Author-email: jitendra@detoxio.ai
7
+ Requires-Python: >=3.10,<4.0
8
+ Classifier: Programming Language :: Python :: 3
9
+ Classifier: Programming Language :: Python :: 3.10
10
+ Classifier: Programming Language :: Python :: 3.11
11
+ Classifier: Programming Language :: Python :: 3.12
12
+ Classifier: Programming Language :: Python :: 3.13
13
+ Requires-Dist: pydantic (>=2.11.5,<3.0.0)
14
+ Requires-Dist: pydantic-yaml (>=1.5.1,<2.0.0)
15
+ Requires-Dist: pyyaml (>=6.0.2,<7.0.0)
16
+ Project-URL: Homepage, https://docs.detoxio.ai
17
+ Description-Content-Type: text/markdown
18
+
19
+ # dtx-models
20
+
21
+ **dtx-models** provides shared model schemas, configuration structures, and YAML-based assets used across the [DTX AI Red Teaming Framework](https://docs.detoxio.ai).
22
+
23
+ This package helps standardize model definitions and integrates seamlessly with components in the `dtx` ecosystem.
24
+
25
+ ## Features
26
+
27
+ - Pydantic-based schema definitions
28
+ - YAML-driven model and plugin configuration
29
+ - Clean separation of model assets from core logic
30
+
31
+ ## Installation
32
+
33
+ ```bash
34
+ pip install dtx-models
35
+ ````
36
+
37
+ Or, if developing locally:
38
+
39
+ ```bash
40
+ poetry install
41
+ ```
42
+
43
+ ## Requirements
44
+
45
+ * Python >= 3.11
46
+ * [Pydantic](https://docs.pydantic.dev/) v2
47
+ * [PyYAML](https://pyyaml.org/)
48
+
49
+ ## Documentation
50
+
51
+ Full documentation available at [docs.detoxio.ai](https://docs.detoxio.ai)
52
+
53
+ ---
54
+
55
+ © Detoxio.ai – All rights reserved.
56
+
57
+
@@ -0,0 +1,29 @@
1
+ dtx_models/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
2
+ dtx_models/analysis.py,sha256=hrCy24jwS9uCXz7h6fTcAxgw5u_Stz9zsSZywCdQYCs,11539
3
+ dtx_models/base.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
4
+ dtx_models/evaluator.py,sha256=h1XDCrvbVoqkexNBfc4fiUkXNAlq8DhpMoybVmAgjYU,10026
5
+ dtx_models/exceptions.py,sha256=gxzdkoiZwsjfWKIT2m3hHM1FNO1l3gDj979rDUhKt_g,41
6
+ dtx_models/prompts.py,sha256=tXCvdkuukjs_3j4lS1R_MSq_WOconmiWtFzLYdULocY,15164
7
+ dtx_models/providers/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
8
+ dtx_models/providers/base.py,sha256=KYEhVF61INjsGxO5tKOENv1c1xGGb1kX6Jevpewf5UI,418
9
+ dtx_models/providers/gradio.py,sha256=2edCLtTAILvJkiMQkYl4FYKixMPjHrRUB0OFK9SeuIU,5261
10
+ dtx_models/providers/groq.py,sha256=FoFtJrSzWEAcNJBM3irWtdYNgWZE72zOLVAjztrhdUI,694
11
+ dtx_models/providers/hf.py,sha256=HKesR5iCcmjqtJqRowNav9YV7YYYIzkGy-Nl6VZTP9Q,5324
12
+ dtx_models/providers/http.py,sha256=a2ZleqfEiqMfzEVoy55DUoUl3knxJLctppFgGdD4xAo,5294
13
+ dtx_models/providers/litellm.py,sha256=VD7CNzeSO8ht96cRSrfi4opF_rtqKmdARDJD10nzkN4,550
14
+ dtx_models/providers/models_spec.py,sha256=pc8yCITiaErZSp8H9f49fSBZEeEp2zPYfFN4QhgszQ4,7813
15
+ dtx_models/providers/ollama.py,sha256=VfCAOO9YTPMLUbcsiKXDQgG_SYSGVUsCfS7iwfhCogk,3207
16
+ dtx_models/providers/openai.py,sha256=psxmTeOdK5g2sOyLTBRTsxtgtBudXAWLCvzH8CeTNnw,3671
17
+ dtx_models/results.py,sha256=sah7v1jOXAd8Vz_ghlamgTSaYxjvI8GdBzpLq0O2OJU,4323
18
+ dtx_models/scope.py,sha256=PwmoOS6i4FLTKxklUH8Ueb633RH_l3_6x3ppA4hUmfk,7071
19
+ dtx_models/tactic.py,sha256=GFSqgRmf00P6qJKKuLo14h3Tg-TRkl9nKk7oLvzDMdI,1395
20
+ dtx_models/target.py,sha256=EETY2MzhWTuS4Xc8DmAQqrnesSuCttPaYTkzzt2Wn8M,5803
21
+ dtx_models/template/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
22
+ dtx_models/template/prompts/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
23
+ dtx_models/template/prompts/base.py,sha256=E1ygnImn7RBY1puRhnyz3Ftz77PgahipqG2YtjXIlAU,1359
24
+ dtx_models/template/prompts/langhub.py,sha256=90qvLl94hxg4mRRfhanoDICfS1YQyy3ply1ZYre7l6I,2414
25
+ dtx_models/utils/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
26
+ dtx_models/utils/urls.py,sha256=1uuarlhCBi-BVTPvtvCz7l7kM-b7rVCmPI_9ktHrKYw,816
27
+ dtx_models-0.18.2.dist-info/METADATA,sha256=qMlSzJrB_Z_nfMPDWgo2y3uoajrCvGFJAhjwBOdU6kw,1484
28
+ dtx_models-0.18.2.dist-info/WHEEL,sha256=b4K_helf-jlQoXBBETfwnf4B04YC67LOev0jo4fX5m8,88
29
+ dtx_models-0.18.2.dist-info/RECORD,,
@@ -0,0 +1,4 @@
1
+ Wheel-Version: 1.0
2
+ Generator: poetry-core 2.1.3
3
+ Root-Is-Purelib: true
4
+ Tag: py3-none-any