Skip to content

Commit 2c856e8

Browse files
authored
Feature/improve db studio (#4)
* feat: Enhance Promptix Studio with improved prompt management and UI - Refactor prompt library, dashboard, and playground pages for better UX - Add comprehensive schema and tools configuration support - Improve version management with more robust metadata handling - Enhance error handling and debugging capabilities - Update data management to support more flexible prompt configurations * feat: Enhance Tools Configuration UI and Improve Prompt Studio Interaction - Completely redesign tools configuration page with dynamic tool management - Add support for adding, editing, and deleting tools with real-time preview - Implement advanced tools template editing with normalization and formatting - Improve user experience with expanded tool explanation and example sections - Remove debug print statements and add more user-friendly status indicators - Optimize tool configuration saving and rendering process * docs: Update README with refined prompt generation and builder pattern examples - Revamp README with clearer, more concise code examples for prompt generation - Introduce Promptix Studio dashboard screenshot and detailed explanation - Refactor code snippets to showcase dynamic system instruction generation - Enhance examples for multi-provider model configuration - Add context-aware prompting section with improved syntax - Update quick start guide with more intuitive usage patterns * license: Add Commons Clause Restriction to MIT License
1 parent dab871d commit 2c856e8

File tree

11 files changed

+1865
-336
lines changed

11 files changed

+1865
-336
lines changed

LICENSE

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,15 @@ furnished to do so, subject to the following conditions:
1212
The above copyright notice and this permission notice shall be included in all
1313
copies or substantial portions of the Software.
1414

15+
Commons Clause Restriction:
16+
Without limiting the foregoing, the permission granted above does not include
17+
the right to Sell the Software. For the purposes of this license, "Sell" means
18+
providing the Software, or any product or service substantially derived from it,
19+
to third parties for a fee or other consideration, including but not limited to
20+
offering it as a hosted or managed service that competes with the original
21+
functionality of the Software. This restriction does not apply to the use of the
22+
Software for internal purposes or within an organization.
23+
1524
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
1625
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
1726
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE

README.md

Lines changed: 76 additions & 55 deletions
Original file line numberDiff line numberDiff line change
@@ -19,84 +19,96 @@ Managing prompts across multiple applications, models, and use cases can quickly
1919

2020
## ✨ Key Features
2121

22-
### 🎯 Dynamic Prompt Generation
23-
Create versatile prompts with Promptix's templating system, allowing for context-aware adjustments:
22+
### 🔄 Static Prompt Retrieval and Version Control
23+
Fetch your static prompts and manage different versions without dynamic templating:
2424

2525
```python
26-
support_prompt = Promptix.get_prompt(
27-
prompt_template="CustomerSupport",
28-
# These variables dynamically modify the prompt
29-
department="Billing",
30-
customer_tier="Premium",
31-
issue_type="refund request",
32-
agent_name="Alex"
33-
)
34-
```
35-
36-
### 🔄 Version Control Built-in
37-
Keep track of prompt iterations and test new versions without breaking production:
38-
39-
```python
40-
# Get the latest live version (for production)
41-
live_prompt = Promptix.get_prompt("CustomerSupport")
26+
# Get the latest live version of a static prompt
27+
live_prompt = Promptix.get_prompt("CustomerSupportStatic")
4228

4329
# Test a new draft version in development
4430
draft_prompt = Promptix.get_prompt(
45-
prompt_template="CustomerSupport",
31+
prompt_template="CustomerSupportStatic",
4632
version="v2"
4733
)
4834
```
4935

50-
### 🎨 Promptix Studio
51-
Manage prompts through a clean web interface by simply running:
52-
53-
```bash
54-
promptix studio
55-
```
56-
57-
### 🛠️ Fluent Builder API
58-
Create sophisticated prompt configurations with an intuitive builder pattern:
36+
### 🎯 Dynamic Templating with Builder Pattern
37+
Create sophisticated, context-aware system instructions using the fluent builder API:
5938

6039
```python
61-
config = (
40+
# Generate a dynamic system instruction
41+
system_instruction = (
6242
Promptix.builder("CustomerSupport")
6343
.with_customer_name("Jane Doe")
6444
.with_department("Technical Support")
6545
.with_priority("high")
66-
.with_tool("ticket_history") # Enable specific tools
46+
.with_tool("ticket_history")
6747
.with_tool_parameter("ticket_history", "max_tickets", 5)
68-
.with_memory(conversation_history)
69-
.build()
48+
.system_instruction() # Returns the system instruction string
7049
)
7150
```
7251

73-
### 🤖 Multi-Provider Support
74-
Send your prompts to any LLM provider while maintaining a consistent interface:
52+
### 🤖 Model Configuration for API Calls
53+
Prepare complete configurations for different LLM providers:
7554

7655
```python
7756
# OpenAI integration
78-
openai_config = Promptix.builder("AgentPrompt").build()
57+
openai_config = (
58+
Promptix.builder("AgentPrompt")
59+
.with_customer_context(customer_data)
60+
.with_issue_details(issue)
61+
.for_client("openai")
62+
.build()
63+
)
7964
openai_response = openai_client.chat.completions.create(**openai_config)
8065

8166
# Anthropic integration
8267
anthropic_config = (
8368
Promptix.builder("AgentPrompt")
69+
.with_customer_context(customer_data)
70+
.with_issue_details(issue)
8471
.for_client("anthropic")
8572
.build()
8673
)
8774
anthropic_response = anthropic_client.messages.create(**anthropic_config)
8875
```
8976

77+
### 🎨 Promptix Studio
78+
Manage prompts through a clean web interface by simply running:
79+
80+
```bash
81+
promptix studio
82+
```
83+
84+
When you run this command, you'll get access to the Promptix Studio dashboard:
85+
86+
![Promptix Studio Dashboard](https://raw.githubusercontent.com/username/promptix/main/docs/images/promptix-studio-dashboard.png)
87+
88+
The Studio interface provides:
89+
90+
- **Dashboard overview** with prompt usage statistics
91+
- **Prompt Library** for browsing and managing all your prompts
92+
- **Version management** to track prompt iterations and mark releases as live
93+
- **Quick creation** of new prompts with a visual editor
94+
- **Usage statistics** showing which models and providers are most used
95+
- **Live editing** with immediate validation and preview
96+
97+
Studio makes it easy to collaborate on prompts, test variations, and manage your prompt library without touching code.
98+
99+
> **Note**: To include the screenshot in your README, save the image to your repository (e.g., in a `docs/images/` directory) and update the image path accordingly.
100+
90101
### 🧠 Context-Aware Prompting
91102
Adapt prompts based on dynamic conditions to create truly intelligent interactions:
92103

93104
```python
94-
# Prompt adapts based on user context
95-
prompt = Promptix.get_prompt(
96-
prompt_template="CustomerSupport",
97-
customer_history_length="long" if customer.interactions > 5 else "short",
98-
sentiment="frustrated" if sentiment_score < 0.3 else "neutral",
99-
technical_level=customer.technical_proficiency
105+
# Build system instruction with conditional logic
106+
system_instruction = (
107+
Promptix.builder("CustomerSupport")
108+
.with_history_context("long" if customer.interactions > 5 else "short")
109+
.with_sentiment("frustrated" if sentiment_score < 0.3 else "neutral")
110+
.with_technical_level(customer.technical_proficiency)
111+
.system_instruction()
100112
)
101113
```
102114

@@ -117,27 +129,34 @@ promptix studio
117129

118130
2. **Create your first prompt template** in the Studio UI or in your YAML file.
119131

120-
3. **Use the prompt in your code**:
132+
3. **Use prompts in your code**:
121133
```python
122134
from promptix import Promptix
123135

124-
# Basic usage
125-
greeting = Promptix.get_prompt(
126-
prompt_template="Greeting",
127-
user_name="Alex"
136+
# Static prompt retrieval
137+
greeting = Promptix.get_prompt("SimpleGreeting")
138+
139+
# Dynamic system instruction
140+
system_instruction = (
141+
Promptix.builder("CustomerSupport")
142+
.with_customer_name("Alex")
143+
.with_issue_type("billing")
144+
.system_instruction()
128145
)
129146

130147
# With OpenAI
131148
from openai import OpenAI
132149
client = OpenAI()
133150

134-
model_config = Promptix.prepare_model_config(
135-
prompt_template="CustomerSupport",
136-
customer_name="Jordan Smith",
137-
issue="billing question"
151+
openai_config = (
152+
Promptix.builder("CustomerSupport")
153+
.with_customer_name("Jordan Smith")
154+
.with_issue("billing question")
155+
.for_client("openai")
156+
.build()
138157
)
139158

140-
response = client.chat.completions.create(**model_config)
159+
response = client.chat.completions.create(**openai_config)
141160
```
142161

143162
## 📊 Real-World Use Cases
@@ -174,6 +193,7 @@ security_review_config = (
174193
.with_review_focus("security")
175194
.with_tool("vulnerability_scanner")
176195
.with_tool("dependency_checker")
196+
.for_client("openai")
177197
.build()
178198
)
179199
```
@@ -184,10 +204,11 @@ Promptix automatically validates your prompt variables against defined schemas:
184204

185205
```python
186206
try:
187-
# Will raise error if technical_level isn't one of the allowed values
188-
prompt = Promptix.get_prompt(
189-
prompt_template="TechnicalSupport",
190-
technical_level="expert" # Must be in ["beginner", "intermediate", "advanced"]
207+
# Dynamic system instruction with validation
208+
system_instruction = (
209+
Promptix.builder("TechnicalSupport")
210+
.with_technical_level("expert") # Must be in ["beginner", "intermediate", "advanced", "expert"]
211+
.system_instruction()
191212
)
192213
except ValueError as e:
193214
print(f"Validation Error: {str(e)}")
451 KB
Loading

examples/03_builder_usage.py

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -18,25 +18,25 @@ def main():
1818

1919
# Example 1: Basic builder usage with SimpleChat
2020
print("Example 1: Basic Builder (SimpleChat)")
21-
config1 = (
21+
SystemPrompt = (
2222
Promptix.builder("SimpleChat")
2323
.with_user_name("Alice")
2424
.with_assistant_name("Helper")
25-
.build()
25+
.system_instruction()
2626
)
27-
print_config(config1)
27+
print_config(SystemPrompt)
2828

2929
# Example 2: Builder with version specification
3030
print("Example 2: Builder with Version (SimpleChat v2)")
31-
config2 = (
31+
config1 = (
3232
Promptix.builder("SimpleChat")
3333
.with_version("v2")
3434
.with_user_name("Bob")
3535
.with_assistant_name("Advisor")
3636
.with_personality_type("professional")
3737
.build()
3838
)
39-
print_config(config2)
39+
print_config(config1)
4040

4141
# Example 3: Builder with memory (conversation history)
4242
print("Example 3: Builder with Memory")
@@ -45,21 +45,21 @@ def main():
4545
{"role": "assistant", "content": "I'd be happy to help! Could you share some code with me?"}
4646
]
4747

48-
config3 = (
48+
config2 = (
4949
Promptix.builder("CodeReviewer")
5050
.with_code_snippet("def add(a, b): return a + b")
5151
.with_programming_language("Python")
5252
.with_review_focus("Best practices")
5353
.with_memory(memory)
5454
.build()
5555
)
56-
print_config(config3)
56+
print_config(config2)
5757

5858

5959
# Example 4: Builder for specific client
6060
print("Example 4: Builder for Specific Client (Anthropic)")
6161
try:
62-
config5 = (
62+
config3 = (
6363
Promptix.builder("CodeReviewer")
6464
.with_version("v2") # Anthropic-compatible version
6565
.with_code_snippet("def process(data): return [x for x in data if x > 0]")
@@ -69,13 +69,13 @@ def main():
6969
.for_client("anthropic") # Specify client type
7070
.build()
7171
)
72-
print_config(config5)
72+
print_config(config3)
7373
except ValueError as e:
7474
print(f"Error: {str(e)}")
7575

7676
# Example 5: Complex tool configuration
7777
print("Example 5: Complex Tool Configuration")
78-
config5 = (
78+
config4 = (
7979
Promptix.builder("ComplexCodeReviewer")
8080
.with_programming_language("Python")
8181
.with_severity("high")
@@ -88,7 +88,7 @@ def main():
8888
.disable_tools("style_checker")
8989
.build()
9090
)
91-
print_config(config5)
91+
print_config(config4)
9292

9393
if __name__ == "__main__":
9494
main()

src/promptix/core/builder.py

Lines changed: 24 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -296,8 +296,16 @@ def _process_tools_template(self) -> List[Dict[str, Any]]:
296296
self._logger.warning(f"Error processing tools: {str(e)}\nDetails: {error_details}")
297297
return [] # Return empty list on error
298298

299-
def build(self) -> Dict[str, Any]:
300-
"""Build the final configuration using the appropriate adapter."""
299+
def build(self, system_only: bool = False) -> Union[Dict[str, Any], str]:
300+
"""Build the final configuration using the appropriate adapter.
301+
302+
Args:
303+
system_only: If True, returns only the system instruction string instead of the full model config.
304+
305+
Returns:
306+
Either the full model configuration dictionary or just the system instruction string,
307+
depending on the value of system_only.
308+
"""
301309
# Validate all required fields are present and have correct types
302310
missing_fields = []
303311
for field, props in self.properties.items():
@@ -324,6 +332,10 @@ def build(self) -> Dict[str, Any]:
324332
# Provide a fallback basic message when template rendering fails
325333
system_message = f"You are an AI assistant for {self.prompt_template}."
326334

335+
# If system_only is True, just return the system message
336+
if system_only:
337+
return system_message
338+
327339
# Initialize the base configuration
328340
model_config = {}
329341

@@ -358,6 +370,16 @@ def build(self) -> Dict[str, Any]:
358370

359371
return model_config
360372

373+
def system_instruction(self) -> str:
374+
"""Get only the system instruction/prompt as a string.
375+
376+
This is a convenient shorthand for build(system_only=True).
377+
378+
Returns:
379+
The rendered system instruction string
380+
"""
381+
return self.build(system_only=True)
382+
361383
def debug_tools(self) -> Dict[str, Any]:
362384
"""Debug method to inspect the tools configuration.
363385

0 commit comments

Comments
 (0)