Skip to content

Commit c91e49f

Browse files
committed
Creation of prompts file - on startup
1 parent d160917 commit c91e49f

File tree

6 files changed

+242
-6
lines changed

6 files changed

+242
-6
lines changed

next_steps.txt

Lines changed: 144 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,144 @@
1+
##########################################################################
2+
3+
### TO DO List ###
4+
5+
6+
# Last Release:
7+
8+
- [Done] - Fix test for test_tools_and_functions
9+
- [Done] - Test yaml
10+
- [Done] Fix test_tools_and_functions
11+
- [Done] Change the structure of prompt just it with current setup
12+
- [Done] Add support for tools templating.
13+
- [Done] Prompts.json/Prompts.yaml structure validation. - Need to fix the structure
14+
- [Done] Changed tools structure fix that + Yaml verififcation.
15+
- [Done] Verification for anthropic only anthropic models can go cross-verify with provider
16+
- [Done] Fix the examples to show proper use case
17+
- [Done] Updates Tests accordingly
18+
- [Done] Improve README
19+
- [Done] Release
20+
21+
22+
# This Release:
23+
24+
- [Done] Improve Promptix Studio
25+
- Update Tools Page in Playground and Remove logging in console
26+
- [Done] Add Examples + Readme:
27+
- get_prompt to be use not for templating just to fetch and manage static promtps
28+
- builder is used for dynamic templating
29+
- builder with api_config for model_config for the api
30+
- [Done] License Change ?? - Added a Common Clause
31+
32+
33+
# Next PR:
34+
35+
- PR 1: [Done] - Improvements to functions and tools
36+
- PR 2: [In progress] - Improve DB Studio
37+
- PR 3: [Backlog] - Openai Interceptor Functionailty
38+
39+
40+
# Next Steps:
41+
42+
- Imrpove docs + blogs + linkedin post. And Reach out to people.
43+
- Work on Backend to get a test API out.
44+
- API Integration in library.
45+
- Build out the very user-friendly UI for wasp app.
46+
- Deploy
47+
- Marketing
48+
49+
50+
51+
Go through the @README.md
52+
and I am thinking of structuring it in this format
53+
54+
55+
- get_prompt to be use not for templating just to fetch and manage static promtps
56+
- builder is used for dynamic templating
57+
- builder with api_config for model_config for the api
58+
59+
60+
61+
62+
63+
# Dynamic Tools
64+
65+
{
66+
"ServiceAgent": {
67+
"name": "ServiceAgent",
68+
"description": "A dynamic service agent prompt that adapts based on user type, communication channel, and required services",
69+
"versions": {
70+
"v1": {
71+
"is_live": true,
72+
"config": {
73+
"system_instruction": "You are a helpful service agent assisting customers with their needs.\n\n{% if new_user %}\nThis is a new user who may need additional guidance.\n{% else %}\nThis is a returning user who is familiar with our services.\n{% endif %}\n\n{% if communication_type == \"phone\" %}\nThis is a phone conversation. Use clear verbal communication.\n{% elif communication_type == \"sms\" %}\nThis is an SMS conversation. Keep responses concise.\n{% elif communication_type == \"chat\" %}\nThis is a live chat conversation. Balance tone and efficiency.\n{% endif %}\n\nService Requirements:\n{% if transportation_type %}\n- Verify pickup and destination\n- Check available transportation options\n{% endif %}\n\n{% if scheduling_required %}\n- Manage appointment scheduling\n- Send confirmation and reminders\n{% endif %}\n\n{{ tools_template }}",
74+
"temperature": 0.7,
75+
"max_tokens": 2000,
76+
"top_p": 1,
77+
"frequency_penalty": 0,
78+
"presence_penalty": 0,
79+
"tools": []
80+
},
81+
"metadata": {
82+
"created_at": "2024-03-19",
83+
"author": "system",
84+
"description": "Dynamic service agent template with conditional tool inclusion"
85+
},
86+
"created_at": "2024-03-19T00:00:00.000000",
87+
"last_modified": "2024-03-19T00:00:00.000000",
88+
"schema": {
89+
"required": [
90+
"communication_type"
91+
],
92+
"optional": [
93+
"new_user",
94+
"transportation_type",
95+
"scheduling_required",
96+
"vehicle_selection"
97+
],
98+
"types": {
99+
"communication_type": [
100+
"phone",
101+
"sms",
102+
"chat"
103+
],
104+
"new_user": "boolean",
105+
"transportation_type": "boolean",
106+
"scheduling_required": "boolean",
107+
"vehicle_selection": "boolean"
108+
}
109+
}
110+
}
111+
},
112+
"tools_config": {
113+
"tool_1": {
114+
"name": "VehicleTool",
115+
"description": "Tool for vehicle-based services",
116+
"parameters": {
117+
"vehicle_id": {
118+
"type": "string",
119+
"description": "Unique identifier for the vehicle"
120+
},
121+
"status": {
122+
"type": "string",
123+
"description": "Current status of the vehicle"
124+
}
125+
}
126+
},
127+
"tool_2": {
128+
"name": "StandardTool",
129+
"description": "Standard tool without vehicle-specific functionality",
130+
"parameters": {
131+
"user_id": {
132+
"type": "string",
133+
"description": "Unique identifier for the user"
134+
},
135+
"session": {
136+
"type": "string",
137+
"description": "Session details"
138+
}
139+
}
140+
}
141+
},
142+
"tools_template": "{% raw %}{% if vehicle_selection %}{% set selected_tool_names = ['default_tool'] %}{% else %}{% set selected_tool_names = ['no_vehicle_tool'] %}{% endif %}{% set combined_tools = [] %}{% for tool_name in selected_tool_names %}{% if tool_name in tools_config %}{% set combined_tools = combined_tools + [tools_config[tool_name]] %}{% endif %}{% endfor %}{% endraw %}{{ combined_tools | tojson }}"
143+
}
144+
}

pyproject.toml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,10 @@ classifiers = [
2828
]
2929
dependencies = [
3030
"streamlit>=1.29.0",
31+
"jinja2>=3.0.0",
32+
"python-dotenv>=0.19.0",
33+
"pyyaml>=6.0.0",
34+
"jsonschema>=4.0.0",
3135
]
3236

3337
[project.scripts]

src/promptix/core/base.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
from jinja2 import BaseLoader, Environment, TemplateError
66
from ..enhancements.logging import setup_logging
77
from .storage.loaders import PromptLoaderFactory
8+
from .storage.utils import create_default_prompts_file
89

910

1011
class Promptix:
@@ -34,7 +35,10 @@ def _load_prompts(cls) -> None:
3435
elif json_file.exists():
3536
prompt_file = json_file
3637
else:
37-
cls._logger.warning("No prompts file found (tried prompts.yaml, prompts.yml, prompts.json); _prompts will be empty.")
38+
# Create a default prompts file (YAML format)
39+
prompt_file = yaml_file
40+
cls._prompts = create_default_prompts_file(prompt_file)
41+
cls._logger.info(f"Created new prompts file at {prompt_file} with a sample prompt")
3842
return
3943

4044
loader = PromptLoaderFactory.get_loader(prompt_file)

src/promptix/core/storage/manager.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
from pathlib import Path
33
from typing import Dict, Any
44
from .loaders import PromptLoaderFactory
5+
from .utils import create_default_prompts_file
56

67
class PromptManager:
78
"""Manages prompts from local storage."""
@@ -28,7 +29,7 @@ def _get_prompt_file(self) -> Path:
2829
else:
2930
# Create new file with preferred format
3031
default_file = Path(f"prompts{self.format}")
31-
default_file.touch()
32+
create_default_prompts_file(default_file)
3233
return default_file
3334

3435
def _load_prompts(self) -> None:

src/promptix/core/storage/utils.py

Lines changed: 83 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,83 @@
1+
import json
2+
from pathlib import Path
3+
from datetime import datetime
4+
from typing import Dict, Any
5+
6+
from .loaders import PromptLoaderFactory
7+
8+
def create_default_prompts_file(file_path: Path) -> Dict[str, Any]:
9+
"""
10+
Create a default prompts file with a sample prompt.
11+
12+
Args:
13+
file_path: Path where the prompts file should be created
14+
15+
Returns:
16+
Dict containing the default prompts data
17+
"""
18+
# Create the file if it doesn't exist
19+
file_path.parent.mkdir(parents=True, exist_ok=True)
20+
21+
# Ensure the file has a valid extension (default to .yaml if none)
22+
original_path = file_path
23+
if file_path.suffix.lower() not in ['.yaml', '.yml', '.json']:
24+
# If no valid extension is provided, prefer YAML
25+
file_path = file_path.with_suffix('.yaml')
26+
print(f"No valid extension provided, defaulting to YAML format: {file_path}")
27+
28+
# Get current timestamp
29+
current_time = datetime.now().isoformat()
30+
31+
# Create default prompts structure
32+
default_prompts = {
33+
"schema": 1.0,
34+
"welcome_prompt": {
35+
"name": "Welcome to Promptix",
36+
"description": "A sample prompt to help you get started with Promptix",
37+
"versions": {
38+
"v1": {
39+
"is_live": True,
40+
"config": {
41+
"system_instruction": "You are a helpful AI assistant that provides clear and concise responses.",
42+
"model": "gpt-4o",
43+
"provider": "openai",
44+
"temperature": 0.7,
45+
"max_tokens": 1024,
46+
"top_p": 1.0
47+
},
48+
"created_at": current_time,
49+
"metadata": {
50+
"created_at": current_time,
51+
"author": "Promptix",
52+
"last_modified": current_time,
53+
"last_modified_by": "Promptix"
54+
},
55+
"schema": {
56+
"required": ["query"],
57+
"optional": ["context"],
58+
"properties": {
59+
"query": {
60+
"type": "string",
61+
"description": "The user's question or request"
62+
},
63+
"context": {
64+
"type": "string",
65+
"description": "Optional additional context for the query"
66+
}
67+
},
68+
"additionalProperties": False
69+
}
70+
}
71+
},
72+
"created_at": current_time,
73+
"last_modified": current_time
74+
}
75+
}
76+
77+
# Save the default prompts
78+
loader = PromptLoaderFactory.get_loader(file_path)
79+
loader.save(default_prompts, file_path)
80+
81+
print(f"Created new prompts file at {file_path} with a sample prompt")
82+
83+
return default_prompts

src/promptix/tools/studio/data.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
from datetime import datetime
55
from pathlib import Path
66
from promptix.core.storage.loaders import PromptLoaderFactory, InvalidPromptSchemaError
7+
from promptix.core.storage.utils import create_default_prompts_file
78
import traceback
89

910
class PromptManager:
@@ -15,10 +16,9 @@ def __init__(self, storage_path: str = "prompts.json"):
1516
def _ensure_storage_exists(self):
1617
"""Ensure the storage file exists"""
1718
if not os.path.exists(self.storage_path):
18-
with open(self.storage_path, 'w') as f:
19-
json.dump({
20-
"schema": 1.0 # Adding schema version as required by the validator
21-
}, f)
19+
# Create a default prompts file, preferring YAML format
20+
# But respect the extension if it's already specified
21+
create_default_prompts_file(Path(self.storage_path))
2222

2323
def load_prompts(self) -> Dict:
2424
"""Load all prompts from storage with schema validation"""

0 commit comments

Comments
 (0)