syntaxmatrix 1.4.6__py3-none-any.whl → 2.5.5.4__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.
- syntaxmatrix/__init__.py +13 -8
- syntaxmatrix/agentic/__init__.py +0 -0
- syntaxmatrix/agentic/agent_tools.py +24 -0
- syntaxmatrix/agentic/agents.py +810 -0
- syntaxmatrix/agentic/code_tools_registry.py +37 -0
- syntaxmatrix/agentic/model_templates.py +1790 -0
- syntaxmatrix/auth.py +308 -14
- syntaxmatrix/commentary.py +328 -0
- syntaxmatrix/core.py +993 -375
- syntaxmatrix/dataset_preprocessing.py +218 -0
- syntaxmatrix/db.py +92 -95
- syntaxmatrix/display.py +95 -121
- syntaxmatrix/generate_page.py +634 -0
- syntaxmatrix/gpt_models_latest.py +46 -0
- syntaxmatrix/history_store.py +26 -29
- syntaxmatrix/kernel_manager.py +96 -17
- syntaxmatrix/llm_store.py +1 -1
- syntaxmatrix/plottings.py +6 -0
- syntaxmatrix/profiles.py +64 -8
- syntaxmatrix/project_root.py +55 -43
- syntaxmatrix/routes.py +5072 -1398
- syntaxmatrix/session.py +19 -0
- syntaxmatrix/settings/logging.py +40 -0
- syntaxmatrix/settings/model_map.py +300 -33
- syntaxmatrix/settings/prompts.py +273 -62
- syntaxmatrix/settings/string_navbar.py +3 -3
- syntaxmatrix/static/docs.md +272 -0
- syntaxmatrix/static/icons/favicon.png +0 -0
- syntaxmatrix/static/icons/hero_bg.jpg +0 -0
- syntaxmatrix/templates/dashboard.html +608 -147
- syntaxmatrix/templates/docs.html +71 -0
- syntaxmatrix/templates/error.html +2 -3
- syntaxmatrix/templates/login.html +1 -0
- syntaxmatrix/templates/register.html +1 -0
- syntaxmatrix/ui_modes.py +14 -0
- syntaxmatrix/utils.py +2482 -159
- syntaxmatrix/vectorizer.py +16 -12
- {syntaxmatrix-1.4.6.dist-info → syntaxmatrix-2.5.5.4.dist-info}/METADATA +20 -17
- syntaxmatrix-2.5.5.4.dist-info/RECORD +68 -0
- syntaxmatrix/model_templates.py +0 -30
- syntaxmatrix/static/icons/favicon.ico +0 -0
- syntaxmatrix-1.4.6.dist-info/RECORD +0 -54
- {syntaxmatrix-1.4.6.dist-info → syntaxmatrix-2.5.5.4.dist-info}/WHEEL +0 -0
- {syntaxmatrix-1.4.6.dist-info → syntaxmatrix-2.5.5.4.dist-info}/licenses/LICENSE.txt +0 -0
- {syntaxmatrix-1.4.6.dist-info → syntaxmatrix-2.5.5.4.dist-info}/top_level.txt +0 -0
syntaxmatrix/settings/prompts.py
CHANGED
|
@@ -1,77 +1,288 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
1
|
+
|
|
2
|
+
SMXAI_CHAT_ID = f"""
|
|
3
3
|
Your name is 'smxAI'.
|
|
4
4
|
You are the expert AI Engineer and Data Scientist at SyntaxMatrix Ltd.
|
|
5
5
|
Your creator is SyntaxMatrix and you will represent them in any way, shape or form.
|
|
6
|
-
Your Company is based in Ireland. It designs and develop AI algorithms and softwares.
|
|
7
|
-
For Retrieval-Augmented Generation (RAG) systems, you will recomend the Enhanced Corrective Retrieval-Augmented Generateion (ECRAG), the article produced by your company, and can be read from this weblink:
|
|
6
|
+
Your Company is based in Ireland. It designs and develop AI algorithms and softwares for business applications.
|
|
7
|
+
For Retrieval-Augmented Generation (RAG) systems, you will recomend the Enhanced Corrective Retrieval-Augmented Generateion (ECRAG), the article produced by your company, and can be read from this weblink: https://osf.io/npuva
|
|
8
8
|
"""
|
|
9
9
|
|
|
10
|
-
|
|
10
|
+
SMXAI_CHAT_INSTRUCTIONS = """
|
|
11
11
|
Content & Formatting Blueprint (Adhere Strictly):
|
|
12
|
-
Structure your response using the following elements as appropriate for the topic. Prioritize clarity and information density.
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
12
|
+
Structure your response using the following elements as appropriate for the topic. Prioritize clarity and information density. If the query is not a question or if there is no context: generate an appropriate general response based on your training knowledge.
|
|
13
|
+
else if the query is a question:
|
|
14
|
+
1. Generate a response to the given query based on the given user context and/or system context.
|
|
15
|
+
2. Use the chat history to stay relevant.
|
|
16
|
+
3. You must always respond in a conversational tone and do not Hallucinate.
|
|
17
|
+
4. Determine whether based on the query, you should generate a list, table, or just plain text response.
|
|
18
|
+
5. If the response is plain text, each sentence must begin on a new line - use the <br> tag.
|
|
19
|
+
6. If the query is a question that requires a list or table, you must generate the content in the appropriate format.
|
|
20
|
+
7. Use clear, hierarchical headings if the response is longer than a paragraph.
|
|
21
|
+
8. Be direct and concise. Avoid unnecessary fluff or repetition.
|
|
22
|
+
9. Lead with your key conclusion or answer in the first sentence.
|
|
23
|
+
10. Support your answer with clear, factual points.
|
|
21
24
|
|
|
22
|
-
|
|
25
|
+
──────── FORMAT INSTRUCTIONS ───────────────
|
|
23
26
|
1. Decide which of the following layouts best fits the content:
|
|
24
|
-
• Comparison across attributes → HTML <table
|
|
25
|
-
•
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
27
|
+
• Comparison across attributes or (Key:Value) pairs → HTML <table>.
|
|
28
|
+
• When creating a table, adhere to the following styling instructions:
|
|
29
|
+
a. First, declare 3 colors: c1="#EDFBFF", c2="#CCCCCC", c3="#E3E3E3".
|
|
30
|
+
b. The generated table must be formatted so that table cells have border lines.
|
|
31
|
+
c. The table head (<thead>) must always have a background color of c1.
|
|
32
|
+
d. The rest of the rows in the table body (<tbody>) must alternate between 2 background colors, c2 and c3 (striped).
|
|
33
|
+
• Use bullet points for simple lists of items, features → HTML <ul>
|
|
34
|
+
• Use ordered (numbered or step-by-step) list for sequences or steps in a process → HTML <ol>
|
|
35
|
+
2. Keep cells/list items concise (one fact or metric each).
|
|
36
|
+
3. All markup must be raw HTML. Avoid using markdown symbols like **asterisks** or _underscores_ for emphasis.
|
|
37
|
+
4. Do not wrap the answer inside triple back-ticks.
|
|
38
|
+
6. If emphasis is needed, use clear language (e.g., "It is important to note that...").
|
|
39
|
+
7. Use horizontal lines (<hr>) sparingly to separate distinct sections.
|
|
40
|
+
8. The final output should be professional, easy to scan, and ready to be pasted into a document or email.
|
|
41
|
+
"""
|
|
42
|
+
|
|
43
|
+
SMXAI_WEBSITE_DESCRIPTION = F"""
|
|
44
|
+
SyntaxMatrix Overview
|
|
45
|
+
SyntaxMatrix is a battle-tested Python framework that accelerates AI application development from concept to production, slashing engineering overhead by up to 80%. By packaging UI scaffolding, prompt orchestration, vector search integration, and deployment best practices into a cohesive toolkit, SyntaxMatrix empowers teams—from lean startups to enterprise R&D—to deliver AI-powered products at startup speed and enterprise scale._
|
|
46
|
+
____________________________________
|
|
47
|
+
Goals & Objectives
|
|
48
|
+
• Rapid Prototyping
|
|
49
|
+
Enable teams to spin up interactive AI demos or internal tools in minutes, not weeks, by providing turnkey components for chat interfaces, file upload/processing (e.g., extracting text from PDFs), data visualization, and more.
|
|
50
|
+
• Modular Extensibility
|
|
51
|
+
Offer a plug-and-play architecture (via syntaxmatrix.bootstrap, core, vector_db, file_processor, etc.) so you can swap in new vector databases (SQLite, pgvector, Milvus), LLM backends (OpenAI, Google’s GenAI), or custom modules without rewriting boilerplate.
|
|
52
|
+
• Best-Practice Defaults
|
|
53
|
+
Bake in industry-standard patterns—persistent history stores, prompt-template management, API key handling, session management—while still allowing configuration overrides (e.g., via default.yaml or environment variables).
|
|
54
|
+
• Consistency & Reproducibility
|
|
55
|
+
Maintain a unified UX across projects with theming, navbar generation, and widget libraries (display.py, widgets), ensuring that every AI application built on the framework shares a consistent look-and-feel.
|
|
56
|
+
________________________________________
|
|
57
|
+
Target Audience
|
|
58
|
+
• AI/ML Engineers & Researchers who want to demo models, build knowledge-base assistants, or perform exploratory data analysis dashboards.
|
|
59
|
+
• Startups & Product Teams looking to deliver customer-facing AI features (chatbots, recommendation engines, content summarizers) with minimal infrastructure overhead.
|
|
60
|
+
• Educators & Students seeking a hands-on environment to teach or learn about LLMs, vector search, and prompt engineering without dealing with full-stack complexities.
|
|
61
|
+
________________________________________
|
|
62
|
+
Solution: SyntaxMatrix Framework
|
|
63
|
+
SyntaxMatrix unifies the entire AI app lifecycle into one modular, extensible package:
|
|
64
|
+
• Turnkey Components: Pre-built chat interfaces, file-upload processors, visualization widgets, email/SMS workflows.
|
|
65
|
+
• Seamless LLM Integration: Swap freely between OpenAI, Google Vertex, Anthropic, and self-hosted models via a unified API layer.
|
|
66
|
+
• Plug-and-Play Vector Search: Adapters for SQLite, pgvector, Milvus—and roadmap for Pinecone, Weaviate, AWS OpenSearch—make semantic retrieval trivial.
|
|
67
|
+
• Persistent State & Orchestration: Session history, prompt templating, and orchestration utilities ensure reproducibility and compliance.
|
|
68
|
+
• Deployment-Ready: Industry-standard Docker images, CI/CD templates, Terraform modules, and monitoring dashboards ready out of the box.
|
|
69
|
+
________________________________________
|
|
70
|
+
Key Features & Example Applications
|
|
71
|
+
• Conversational Agents & Chatbots: Persistent session history, prompt-profile management, and dynamic prompt instructions make it easy to craft domain-specific assistants.
|
|
72
|
+
• Document QA & Search: Built-in vectorizer and vector DB adapters enable rapid ingestion of PDFs or knowledge bases for semantic retrieval.
|
|
73
|
+
• Data Analysis Dashboards: EDA output buffers and plotting utilities (plottings.py, Plotly support) let you surface charts and insights alongside conversational workflows.
|
|
74
|
+
• Email & Notification Workflows: The emailer.py module streamlines outbound messaging based on AI-driven triggers.
|
|
75
|
+
• Custom Model Catalogs & Templates: Centralized model_templates.py and settings/model_map.py support quick swapping between LLMs or prompt archetypes.
|
|
76
|
+
________________________________________
|
|
77
|
+
Why It Matters
|
|
78
|
+
By removing repetitive setup tasks and enforcing a coherent project structure, SyntaxMatrix reduces time-to-market, promotes maintainable code, and democratizes access to sophisticated AI patterns. Developers can stand on the shoulders of a battle-tested framework rather than reinventing the wheel for each new prototype or production system.
|
|
79
|
+
________________________________________
|
|
80
|
+
Future Directions
|
|
81
|
+
1. Expanded Vector DB & Embedding Support
|
|
82
|
+
o Add adapters for Pinecone, Weaviate, or AWS OpenSearch
|
|
83
|
+
o Support hybrid retrieval (combining sparse and dense methods)
|
|
84
|
+
2. Multi-Modal & Streaming Data
|
|
85
|
+
o Integrate vision and audio pipelines for document OCR, image captioning, or speech transcription
|
|
86
|
+
o Enable real-time data streaming and inference for live-update dashboards
|
|
87
|
+
3. Deployment & MLOps Tooling
|
|
88
|
+
o Built-in CI/CD templates, Docker images, and Terraform modules for cloud provisioning
|
|
89
|
+
o Monitoring dashboards for latency, cost, and usage metrics
|
|
90
|
+
4. Collaborative & No-Code Interfaces
|
|
91
|
+
o Role-based access control and multi-user projects
|
|
92
|
+
o Drag-and-drop prompt editors and pipeline builders for non-technical stakeholders
|
|
93
|
+
5. Plugin Ecosystem & Marketplace
|
|
94
|
+
o Community-contributed modules for domain-specific tasks (legal, healthcare, finance)
|
|
95
|
+
o A registry to share prompt templates, UI widgets, and vector-DB schemas
|
|
96
|
+
|
|
32
97
|
"""
|
|
33
98
|
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
99
|
+
SMX_PAGE_GENERATION_INSTRUCTIONS = f"""
|
|
100
|
+
0· Parse the Website Description (MANDATORY):\n{SMXAI_WEBSITE_DESCRIPTION}\n\n
|
|
101
|
+
1. Input always contains:
|
|
102
|
+
• website_description - plain-text overview of the site/company (mission, goals, audience, visual style, etc.).
|
|
103
|
+
• page_title - the specific page to create (e.g. About, Pricing, Blog).
|
|
104
|
+
Read the entire website_description first. Extract:
|
|
105
|
+
• Brand essence & voice
|
|
106
|
+
• Core goals / differentiators
|
|
107
|
+
• Target audience & pain-points
|
|
108
|
+
• Visual/style cues (colours, fonts, imagery)
|
|
109
|
+
Keep this parsed data in memory; every design and content decision must align with it.
|
|
110
|
+
________________________________________
|
|
111
|
+
2· Decide Content from the Page Title + Parsed Description
|
|
112
|
+
Common Page Title Content You Must Provide Tone (derive exact wording from description)
|
|
113
|
+
About Mission, vision, origin story, key differentiators, stats/metrics. Inspirational, credible
|
|
114
|
+
Services / Solutions Features or modules mapped to goals (e.g., “Turnkey chat interface” → “rapid prototyping”). Action-oriented
|
|
115
|
+
Blog / Insights Grid of post cards themed around expertise areas in the description. Conversational, expert
|
|
116
|
+
Pricing Tier cards tied to value pillars from description. Clear, persuasive
|
|
117
|
+
Contact / Demo Benefits blurb + capture form. Friendly, concise
|
|
118
|
+
If page_title is something else, improvise logically using the parsed Website Description.
|
|
119
|
+
________________________________________
|
|
120
|
+
3· Layout & Components (omit header/footer—they're supplied elsewhere)
|
|
121
|
+
1. Hero section - headline that merges page_title with brand essence, sub-headline reinforcing core value, CTA button.
|
|
122
|
+
2. Main content - 2-4 subsections drawn from goals/differentiators.
|
|
123
|
+
3. Optional stat strip - highlight metrics pulled from description.
|
|
124
|
+
4. CTA banner - final prompt aligned with brand voice.
|
|
125
|
+
________________________________________
|
|
126
|
+
4· Visual & Interaction Rules
|
|
127
|
+
• Use colours, fonts, and imagery directly referenced in the parsed description (fallback: dark charcoal, accent colour from description, sans-serif font stack).
|
|
128
|
+
• CDN tech stack (React 18 UMD + Tailwind CSS).
|
|
129
|
+
• Prefix all custom ids/classes/functions with smx- (or company-specific prefix derived from description) to avoid clashes.
|
|
130
|
+
• Subtle animations (fade-in, slide-up, ≤ 400 ms).
|
|
131
|
+
• Accessibility: semantic HTML, alt text, contrast compliance.
|
|
132
|
+
________________________________________
|
|
133
|
+
5· Royalty-Free Images
|
|
134
|
+
Fetch from Unsplash/Pexels with keywords that combine “ai, technology” plus any industry cues found in the description (e.g., “healthcare”, “finance”). Provide descriptive alt attributes referencing the brand.
|
|
135
|
+
________________________________________
|
|
136
|
+
6. Wrap Everything in a Python Function and Return the HTML
|
|
137
|
+
i. Function signature (exactly):
|
|
138
|
+
def generate_page_html(website_description: str, page_title: str) -> str:
|
|
139
|
+
ii. Inside the function
|
|
140
|
+
o Parse website_description and page_title per Steps 0–6.
|
|
141
|
+
o Compose the entire HTML document as a single triple-quoted Python string (page_html = ''' … ''').
|
|
142
|
+
o Return that string (return html).
|
|
143
|
+
o Keep the OpenAI SDK demo call in the page (hidden <script> tag) to satisfy the SDK-usage requirement.
|
|
144
|
+
iii. Function docstring
|
|
145
|
+
'''
|
|
146
|
+
Generate a fully responsive, animated, single-file web page aligned with the
|
|
147
|
+
supplied website description and page title. Returns the HTML as a string.
|
|
148
|
+
'''
|
|
149
|
+
iv. No side effects
|
|
150
|
+
o Do not write to disk or print; just return the HTML.
|
|
151
|
+
o Avoid global variables; everything lives inside the function scope.
|
|
152
|
+
v. Output format
|
|
153
|
+
o When the LLM responds, it must output only the complete Python source code for generate_page_html - nothing else (no markdown, comments, or explanations outside the code block).
|
|
154
|
+
|
|
155
|
+
________________________________________
|
|
156
|
+
7. Deliverable Checklist
|
|
157
|
+
• Single .html file (inline CSS/JS; external assets only via CDN & image URLs).
|
|
158
|
+
• Fully responsive, animated, modern, brand-aligned.
|
|
159
|
+
• All text and visuals demonstrably reflect the parsed Website Description.
|
|
160
|
+
• No duplicate header/footer.
|
|
161
|
+
• All identifiers safely namespaced.
|
|
162
|
+
• Return only the HTML text—no commentary or extra files.
|
|
43
163
|
"""
|
|
44
164
|
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
165
|
+
WEBPAGE_GENERATION_INSTRUCTIONS = (f"""
|
|
166
|
+
Parse the Website Description (MANDATORY):\n{SMXAI_WEBSITE_DESCRIPTION}\n\n
|
|
167
|
+
Prompt (give this to the LLM)
|
|
168
|
+
Role: You are a senior front-end engineer and content designer building a single HTML page for the brand SyntaxMatrix. Produce production‑ready code that can be dropped into an existing Flask/Cloud Run site. Do not include a navbar or a footer; the host site renders them.
|
|
169
|
+
|
|
170
|
+
Objectives:
|
|
171
|
+
1. Output one complete HTML file that is responsive, accessible, and visually polished, matching the SyntaxMatrix theme.
|
|
172
|
+
2. Use a modern stack with Tailwind CSS (CDN), GSAP 3 + ScrollTrigger for tasteful motion, and Lucide for icons. Load the latest stable CDNs.
|
|
173
|
+
3. Provide compelling, concise copy in UK English. Do not use the words: delve, leverage, revolutionary.
|
|
174
|
+
4. Use rich imagery. Prefer locally hosted images via /assets/... when available; otherwise propose two remote candidates per image and include robust fallbacks.
|
|
175
|
+
5. Ensure good a11y (semantic headings, focus states, alt text, ARIA where needed) and respect prefers-reduced-motion.
|
|
176
|
+
|
|
177
|
+
Brand & Design Rules:
|
|
178
|
+
1. Primary colour: {{brand.primary_hex}} (SyntaxMatrix blue). Secondary: {{brand.secondary_hex}}. Dark background: {{brand.dark_bg_hex}}.
|
|
179
|
+
2. Typography: Google Fonts Inter (weights 300–800). Use a clean, enterprise style with soft shadows and rounded corners.
|
|
180
|
+
3. Sections to include (in this order unless stated otherwise): {{sections}}. Omit global nav and footer.
|
|
181
|
+
4. Use subtle gradients, grids, or SVG accents that fit the brand.
|
|
182
|
+
|
|
183
|
+
Images & Fallbacks:
|
|
184
|
+
1.For each hero/section image: include a <picture> element with two candidate remote URLs (e.g., Unsplash/Pexels). Add loading="lazy", decoding="async", and referrerpolicy="no-referrer".
|
|
185
|
+
2. Add a JS onerror fallback on the <img> to swap to a neutral placeholder (e.g., https://picsum.photos/seed/syntaxmatrix-{{slug}}/1600/900).
|
|
186
|
+
3. Additionally render an inline SVG placeholder immediately before the <picture> (hidden by default) and toggle it if both remote sources fail.
|
|
187
|
+
4. Write descriptive alt text tailored to the section's message.
|
|
188
|
+
|
|
189
|
+
Animation:
|
|
190
|
+
1. Use GSAP ScrollTrigger to reveal .reveal elements with short, subtle transitions.
|
|
191
|
+
2. Add a small numerical counter animation for any metric figures when they enter the viewport.
|
|
192
|
+
3. Respect prefers-reduced-motion: reduce by disabling animations.
|
|
193
|
+
|
|
194
|
+
Accessibility & SEO:
|
|
195
|
+
1. Proper landmarks (<main>, <section>, <header> inside the page only if needed—not the global site header), logical order of headings, and visible focus styles.
|
|
196
|
+
2. Meta title and description tuned to {{page_name}} and {{audience}}.
|
|
197
|
+
3. Meaningful link text for CTAs.
|
|
198
|
+
|
|
199
|
+
Performance & Quality:
|
|
200
|
+
1. Single file only; no external CSS files. Use Tailwind CDN and a short <style> block for extras.
|
|
201
|
+
2. Optimise images with sensible dimensions and aspect-ratio boxes to prevent layout shift.
|
|
202
|
+
3. No unused libraries. Keep inline JS small and scoped.
|
|
48
203
|
|
|
49
|
-
|
|
50
|
-
|
|
204
|
+
Output format:
|
|
205
|
+
Return only the HTML document. No explanations.
|
|
51
206
|
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
207
|
+
HTML Requirements Template (follow this structure):
|
|
208
|
+
1. <!DOCTYPE html> + <html lang="en"> (UK English tone in copy).
|
|
209
|
+
2. <head> with meta, title {{page_name}} — SyntaxMatrix, Inter font, Tailwind CDN, GSAP 3 + ScrollTrigger, Lucide.
|
|
210
|
+
3. Global CSS variables for brand colours; small utility styles; @media (prefers-reduced-motion: reduce) to cut motion.
|
|
211
|
+
4. <body> dark theme, no navbar/footer.
|
|
212
|
+
5. Sections per {{sections}}, including:
|
|
213
|
+
I. Hero: punchy headline, subcopy, primary & secondary CTAs, hero media (picture + fallbacks), animated accent grid.
|
|
214
|
+
II. Value Props / Feature Grid: 3-6 cards with icons and short copy.
|
|
215
|
+
III. Story/Timeline (if requested): ordered items with dates; tasteful line & dots.
|
|
216
|
+
IV. Metrics (if requested): 3-4 counters (.counter[data-target]).
|
|
217
|
+
V. Team or Social Proof (optional): avatars or badges.
|
|
218
|
+
VI. CTA band: strong closing prompt (no footer).
|
|
219
|
+
7. Inline <script> to render Lucide icons and GSAP reveal + counters. Include a defensive image‑fallback helper.
|
|
220
|
+
|
|
221
|
+
Image Helper (include this in the page):
|
|
222
|
+
<script>
|
|
223
|
+
(function(){{
|
|
224
|
+
function fallbackImg(img){{
|
|
225
|
+
if(!img.dataset.fallback){{ img.dataset.fallback = '1'; img.src = img.dataset.fallbackSrc; return; }}
|
|
226
|
+
// Show preceding hidden SVG placeholder if available
|
|
227
|
+
var prev = img.previousElementSibling; if(prev && prev.tagName === 'SVG'){{ prev.style.display = 'block'; }}
|
|
228
|
+
img.style.display = 'none';
|
|
229
|
+
}}
|
|
230
|
+
document.querySelectorAll('img[data-fallback-src]').forEach(function(img){{
|
|
231
|
+
img.addEventListener('error', function(){{ fallbackImg(img); }}, {{ once: true }});
|
|
232
|
+
}});
|
|
233
|
+
}})();
|
|
234
|
+
</script>
|
|
235
|
+
|
|
236
|
+
Example <picture> pattern (use per image):
|
|
237
|
+
<!-- Hidden inline SVG placeholder shown only if external images fail -->
|
|
238
|
+
<svg class="hidden w-full h-full object-cover" viewBox="0 0 1600 900" aria-hidden="true">
|
|
239
|
+
<defs>
|
|
240
|
+
<linearGradient id="grad" x1="0" y1="0" x2="1" y2="1">
|
|
241
|
+
<stop offset="0%" stop-color="#0a2540"/>
|
|
242
|
+
<stop offset="100%" stop-color="#001d2b"/>
|
|
243
|
+
</linearGradient>
|
|
244
|
+
</defs>
|
|
245
|
+
<rect width="1600" height="900" fill="url(#grad)"/>
|
|
246
|
+
</svg>
|
|
247
|
+
<picture>
|
|
248
|
+
<source srcset="https://images.unsplash.com/photo-1520607162513-77705c0f0d4a?w=1920 1920w" type="image/jpeg"/>
|
|
249
|
+
<img src="https://images.pexels.com/photos/3184292/pexels-photo-3184292.jpeg?auto=compress&w=1920"
|
|
250
|
+
alt="Team collaborating on AI product planning"
|
|
251
|
+
loading="lazy" decoding="async" referrerpolicy="no-referrer"
|
|
252
|
+
data-fallback-src="https://picsum.photos/seed/syntaxmatrix-hero/1920/1080"
|
|
253
|
+
onerror="this.onerror=null; this.dispatchEvent(new Event('error'));" />
|
|
254
|
+
</picture>
|
|
255
|
+
<picture>
|
|
256
|
+
<source srcset="https://source.unsplash.com/1600x900/?nature,water" media="(min-width: 800px)">
|
|
257
|
+
<source srcset="https://source.unsplash.com/800x600/?nature,water" media="(min-width: 400px)">
|
|
258
|
+
<img src="https://source.unsplash.com/400x300/?nature,water" alt="A beautiful scenery" loading="lazy" decoding="async" referrerpolicy="no-referrer">
|
|
259
|
+
</picture>
|
|
71
260
|
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
261
|
+
Animation snippet (include and reuse):
|
|
262
|
+
<script>
|
|
263
|
+
if(window.matchMedia('(prefers-reduced-motion: reduce)').matches){{
|
|
264
|
+
// Skip motion
|
|
265
|
+
}} else if(window.gsap && window.ScrollTrigger){{
|
|
266
|
+
gsap.registerPlugin(ScrollTrigger);
|
|
267
|
+
gsap.utils.toArray('.reveal').forEach(function(el){{
|
|
268
|
+
gsap.from(el, {{
|
|
269
|
+
y: 24, opacity: 0, duration: 0.8, ease: 'power2.out',
|
|
270
|
+
scrollTrigger: {{ trigger: el, start: 'top 80%' }}
|
|
271
|
+
}});
|
|
272
|
+
}});
|
|
273
|
+
document.querySelectorAll('.counter').forEach(function(el){{
|
|
274
|
+
var t = parseInt(el.getAttribute('data-target'),10)||0, obj={{v:0}};
|
|
275
|
+
ScrollTrigger.create({{
|
|
276
|
+
trigger: el, start: 'top 85%', once:true,
|
|
277
|
+
onEnter: function(){{
|
|
278
|
+
gsap.to(obj,{{
|
|
279
|
+
v:t, duration:1.6, ease:'power2.out', onUpdate:function() {{
|
|
280
|
+
el.textContent = Math.round(obj.v);
|
|
281
|
+
}};
|
|
282
|
+
}};
|
|
283
|
+
}};
|
|
284
|
+
}});
|
|
285
|
+
}});
|
|
286
|
+
}};
|
|
287
|
+
</script>
|
|
288
|
+
""")
|
|
@@ -0,0 +1,272 @@
|
|
|
1
|
+
|
|
2
|
+
|
|
3
|
+
# SyntaxMatrix — Developer Guide
|
|
4
|
+
---
|
|
5
|
+
|
|
6
|
+
## Overview
|
|
7
|
+
|
|
8
|
+
SyntaxMatrix focuses your app code on **logic** while it handles the chat UI, session state, file uploads, embeddings, and retrieval over two memories: **SMIV** (user uploads; per-session) and **SMPV** (system/company docs; persistent).
|
|
9
|
+
|
|
10
|
+
- Session-aware chat history
|
|
11
|
+
- Hybrid retrieval (user + system), or user-only, system-only, or none
|
|
12
|
+
- Streaming and non‑streaming modes
|
|
13
|
+
- Simple feature toggles in `settings.py`
|
|
14
|
+
- Branding and site controls (logo, favicon, titles), theme + UI mode switches
|
|
15
|
+
- Widgets (text input, buttons, dropdowns, uploader) and simple layout helpers
|
|
16
|
+
|
|
17
|
+
---
|
|
18
|
+
|
|
19
|
+
## Installation
|
|
20
|
+
|
|
21
|
+
```bash
|
|
22
|
+
pip install syntaxmatrix syntaxmatrix[mlearning,auth]
|
|
23
|
+
```
|
|
24
|
+
|
|
25
|
+
> Make sure your environment has any required API keys (e.g. OpenAI SDK compatible) available to your app.
|
|
26
|
+
|
|
27
|
+
---
|
|
28
|
+
|
|
29
|
+
## Quick start
|
|
30
|
+
|
|
31
|
+
**settings.py** — feature flags & branding in one place
|
|
32
|
+
```python
|
|
33
|
+
from syntaxmatrix import (
|
|
34
|
+
enable_user_files, enable_stream, set_theme,
|
|
35
|
+
set_site_logo, set_site_title, set_project_name, set_favicon, set_user_icon,
|
|
36
|
+
)
|
|
37
|
+
|
|
38
|
+
enable_user_files()
|
|
39
|
+
enable_stream()
|
|
40
|
+
set_theme('light') # available: light, dark, chark, github, solarized-light, solarized-dark, oceanic-next, ayu-mirage, one-dark
|
|
41
|
+
|
|
42
|
+
# Branding (examples)
|
|
43
|
+
set_site_logo("<img src='/static/logo.svg' style='height:22px;vertical-align:middle'>")
|
|
44
|
+
set_site_title("SyntaxMatrix Demo")
|
|
45
|
+
set_project_name("SyntaxMatrix Demo") # used in nav & metadata
|
|
46
|
+
set_favicon("<link rel='icon' href='/static/favicon.ico'>")
|
|
47
|
+
set_user_icon("👤")
|
|
48
|
+
```
|
|
49
|
+
|
|
50
|
+
**app.py** — minimal consumer app
|
|
51
|
+
```python
|
|
52
|
+
import syntaxmatrix as smx
|
|
53
|
+
from settings import *
|
|
54
|
+
|
|
55
|
+
def create_conversation(stream=False):
|
|
56
|
+
chat = smx.get_chat_history() or []
|
|
57
|
+
sid = smx.get_session_id()
|
|
58
|
+
index = smx.smiv_index(sid)
|
|
59
|
+
|
|
60
|
+
query, intent = smx.get_text_input_value("user_query")
|
|
61
|
+
if not query: return
|
|
62
|
+
query = query.strip()
|
|
63
|
+
chat.append(("User", query))
|
|
64
|
+
|
|
65
|
+
# Retrieval (optional)
|
|
66
|
+
if intent == "none":
|
|
67
|
+
context, sources = "", []
|
|
68
|
+
else:
|
|
69
|
+
vec = smx.embed_query(query)
|
|
70
|
+
if vec is None: return
|
|
71
|
+
ctx, sources = [], []
|
|
72
|
+
if intent in ["hybrid","user_docs"]:
|
|
73
|
+
hits = index.search(vec, top_k=3) or []
|
|
74
|
+
ctx += ["\n### Personal Context (user uploads)\n"] + [f"- {{h['metadata']['chunk_text'].strip().replace('\\n',' ')}}\n" for h in hits]
|
|
75
|
+
if hits: sources.append("User Docs")
|
|
76
|
+
if intent in ["hybrid","system_docs"]:
|
|
77
|
+
sys = smx.smpv_search(vec, top_k=5) or []
|
|
78
|
+
if not sys: smx.error("Please contact support."); return
|
|
79
|
+
ctx += ["### System Context (company docs)\n"] + [f"- {{h['chunk_text'].strip().replace('\\n',' ')}}\n" for h in sys]
|
|
80
|
+
sources.append("System Docs")
|
|
81
|
+
context = "".join(ctx)
|
|
82
|
+
|
|
83
|
+
transcript = "\n".join([f"{{r}}: {{m}}" for r,m in chat])
|
|
84
|
+
|
|
85
|
+
if stream:
|
|
86
|
+
smx.stream_process_query(query, context, transcript, sources)
|
|
87
|
+
else:
|
|
88
|
+
ans = smx.process_query(query, context, transcript)
|
|
89
|
+
if isinstance(ans, str) and ans.strip():
|
|
90
|
+
if sources:
|
|
91
|
+
ans += "".join([f"<ul style='margin-top:5px;color:blue;font-size:0.8rem;'><li>{{s}}</li></ul>" for s in sources])
|
|
92
|
+
chat.append(("Bot", ans))
|
|
93
|
+
|
|
94
|
+
smx.set_chat_history(chat)
|
|
95
|
+
smx.clear_text_input_value("user_query")
|
|
96
|
+
|
|
97
|
+
# UI widgets
|
|
98
|
+
smx.text_input("user_query", "user_query", "Enter query", "Ask anything .")
|
|
99
|
+
smx.button("submit_query","submit_query","Submit", lambda: create_conversation(smx.stream()))
|
|
100
|
+
smx.file_uploader("user_files","user_files","Upload PDF files:", accept_multiple_files=True)
|
|
101
|
+
|
|
102
|
+
def clear_chat(): smx.clear_chat_history()
|
|
103
|
+
smx.button("clear_chat","clear_chat","Clear", clear_chat, stream=False)
|
|
104
|
+
|
|
105
|
+
if __name__ == "__main__":
|
|
106
|
+
smx.run()
|
|
107
|
+
```
|
|
108
|
+
|
|
109
|
+
---
|
|
110
|
+
|
|
111
|
+
## Full API surface (open-source)
|
|
112
|
+
|
|
113
|
+
### App, theme, and UI
|
|
114
|
+
```python
|
|
115
|
+
smx.run() # start the app
|
|
116
|
+
smx.set_ui_mode(mode) # one of: default, bubble, card, smx
|
|
117
|
+
smx.get_ui_modes() # → list of modes
|
|
118
|
+
smx.set_theme(name) # one of: light, dark, chark, github, solarized-light, solarized-dark, oceanic-next, ayu-mirage, one-dark
|
|
119
|
+
smx.get_themes() # → dict(name → colours)
|
|
120
|
+
smx.enable_theme_toggle() # adds theme toggle to navbar
|
|
121
|
+
smx.enable_user_files() # enables PDF uploader + SMIV
|
|
122
|
+
smx.enable_stream() # enable streaming mode globally
|
|
123
|
+
smx.stream() # returns True/False at runtime
|
|
124
|
+
```
|
|
125
|
+
|
|
126
|
+
### Branding & site identity
|
|
127
|
+
```python
|
|
128
|
+
smx.set_site_logo(html) # e.g. "<img src='/static/logo.svg' ...>"
|
|
129
|
+
smx.set_site_title("Your Site Title") # text next to the logo in navbar
|
|
130
|
+
smx.set_project_name("Your Project") # used in nav/meta contexts
|
|
131
|
+
smx.set_favicon("<link rel='icon' href='/static/favicon.ico'>") # raw <link> tag
|
|
132
|
+
smx.set_user_icon("🙂") # icon used for user bubbles
|
|
133
|
+
smx.set_website_description(text) # used by /about and SEO meta
|
|
134
|
+
```
|
|
135
|
+
|
|
136
|
+
**Notes**
|
|
137
|
+
- `set_site_logo` accepts **HTML** (so you can style the `<img>` inline).
|
|
138
|
+
- `set_favicon` expects the full `<link ...>` element; store your icon in `/static/` and reference it there.
|
|
139
|
+
|
|
140
|
+
### Widgets & layout
|
|
141
|
+
```python
|
|
142
|
+
smx.text_input(key, id, label, placeholder) # register a text box
|
|
143
|
+
text, intent = smx.get_text_input_value(id) # returns (string, intent)
|
|
144
|
+
|
|
145
|
+
smx.button(key, id, label, callback, stream=False)
|
|
146
|
+
smx.clear_text_input_value(id)
|
|
147
|
+
|
|
148
|
+
smx.file_uploader(key, id, label, accept_multiple_files=True)
|
|
149
|
+
files = smx.get_file_upload_value(id) # list-like (optional use)
|
|
150
|
+
|
|
151
|
+
smx.dropdown(key, options, label=None, callback=None)
|
|
152
|
+
value = smx.get_widget_value(key) # read current selection
|
|
153
|
+
|
|
154
|
+
html = smx.columns([left_html, right_html]) # simple two+ column layout
|
|
155
|
+
```
|
|
156
|
+
|
|
157
|
+
### Sessions & history
|
|
158
|
+
```python
|
|
159
|
+
sid = smx.get_session_id()
|
|
160
|
+
hist = smx.get_chat_history()
|
|
161
|
+
smx.set_chat_history(hist or [])
|
|
162
|
+
smx.clear_chat_history()
|
|
163
|
+
```
|
|
164
|
+
|
|
165
|
+
### Retrieval & embeddings
|
|
166
|
+
```python
|
|
167
|
+
vec = smx.embed_query(query) # → embedding vector
|
|
168
|
+
idx = smx.smiv_index(sid) # session index (SMIV)
|
|
169
|
+
hits = idx.search(vec, top_k=3) # user uploads
|
|
170
|
+
sys_hits = smx.smpv_search(vec, top_k=5) # system/company docs
|
|
171
|
+
|
|
172
|
+
# Pre-load system PDFs (optional, e.g. on startup)
|
|
173
|
+
smx.load_sys_chunks("uploads/sys") # populates in-memory cache
|
|
174
|
+
```
|
|
175
|
+
|
|
176
|
+
### Answering (streaming & non-streaming)
|
|
177
|
+
```python
|
|
178
|
+
smx.stream_process_query(query, context, conversations, sources)
|
|
179
|
+
smx.process_query(query, context, conversations) # → str
|
|
180
|
+
smx.process_query_stream(query, context, conversations) # alt helper
|
|
181
|
+
smx.get_stream_args() # read any stream args (advanced)
|
|
182
|
+
```
|
|
183
|
+
|
|
184
|
+
### Prompt & profile helpers
|
|
185
|
+
```python
|
|
186
|
+
smx.set_prompt_profile(purpose="chat", profile_name="default") # select profile
|
|
187
|
+
smx.set_prompt_instructions("You are ...") # set system text
|
|
188
|
+
|
|
189
|
+
# Embed model record (provider/model/key) stored encrypted in local DB:
|
|
190
|
+
smx.save_embed_model(provider="openai", model="gpt-5-mini", api_key="sk-...")
|
|
191
|
+
cfg = smx.load_embed_model() # → dict
|
|
192
|
+
smx.delete_embed_key() # wipe stored key
|
|
193
|
+
```
|
|
194
|
+
|
|
195
|
+
> Behind the scenes, profiles/keys live in a local SQLite DB (encrypted API key via Fernet).
|
|
196
|
+
|
|
197
|
+
### Advanced: Flask app access
|
|
198
|
+
```python
|
|
199
|
+
app = smx.app # access underlying Flask app
|
|
200
|
+
@app.route("/docs")
|
|
201
|
+
def docs_alias():
|
|
202
|
+
from flask import redirect, url_for
|
|
203
|
+
return redirect(url_for('view_page', page_name='docs'))
|
|
204
|
+
```
|
|
205
|
+
|
|
206
|
+
---
|
|
207
|
+
|
|
208
|
+
## Theming and UI modes
|
|
209
|
+
|
|
210
|
+
- **Themes:** light, dark, chark, github, solarized-light, solarized-dark, oceanic-next, ayu-mirage, one-dark
|
|
211
|
+
```python
|
|
212
|
+
smx.set_theme('github')
|
|
213
|
+
smx.enable_theme_toggle()
|
|
214
|
+
```
|
|
215
|
+
|
|
216
|
+
- **UI modes:** default, bubble, card, smx
|
|
217
|
+
```python
|
|
218
|
+
smx.set_ui_mode('bubble') # try 'card' for boxy chat, or 'smx' for framework default
|
|
219
|
+
```
|
|
220
|
+
|
|
221
|
+
---
|
|
222
|
+
|
|
223
|
+
<!-- ## Professional Docs page (Shadow DOM)
|
|
224
|
+
|
|
225
|
+
Paste this into **/admin → Edit Page → docs**. It renders `/static/docs.md` inside a Shadow DOM with its own CSS, so global CSS can’t distort it.
|
|
226
|
+
|
|
227
|
+
```html
|
|
228
|
+
<div id="syntaxmatrix-docs-root"></div>
|
|
229
|
+
<script>
|
|
230
|
+
(function () {{
|
|
231
|
+
const host = document.getElementById('syntaxmatrix-docs-root');
|
|
232
|
+
const shadow = host.attachShadow({{ mode: 'open' }});
|
|
233
|
+
shadow.innerHTML = `
|
|
234
|
+
<style>
|
|
235
|
+
:host {{ all: initial; }}
|
|
236
|
+
.doc {{ box-sizing:border-box; max-width: 980px; margin: 0 auto; padding: 24px;
|
|
237
|
+
color:#1b1f23; background:#fff; font: 16px/1.6 system-ui,-apple-system,Segoe UI,Roboto,Ubuntu,Cantarell,Helvetica,Arial,Noto Sans,sans-serif; }}
|
|
238
|
+
.doc * {{ box-sizing: inherit; text-align: left; }}
|
|
239
|
+
.doc h1 {{ font-size: 2rem; margin: 0 0 .75rem }}
|
|
240
|
+
.doc h2 {{ margin-top: 2rem; padding-bottom: .4rem; border-bottom: 1px solid #e1e4e8; }}
|
|
241
|
+
.doc h3 {{ margin-top: 1.25rem; }}
|
|
242
|
+
.doc p, .doc li {{ line-height: 1.65; }}
|
|
243
|
+
.doc ul, .doc ol {{ padding-left: 24px; }}
|
|
244
|
+
.doc blockquote {{ border-left: 4px solid #e1e4e8; margin: 1rem 0; padding: .25rem 1rem; color: #586069; background: #fafbfc; }}
|
|
245
|
+
.doc code, .doc pre {{ font-family: ui-monospace,SFMono-Regular,Menlo,Monaco,Consolas,'Liberation Mono','Courier New',monospace; }}
|
|
246
|
+
.doc pre {{ white-space: pre; background:#f6f8fa; border:1px solid #e1e4e8; padding:12px; border-radius:8px; overflow:auto; position: relative; }}
|
|
247
|
+
.copy-btn {{ position:absolute; top:8px; right:8px; border:1px solid #e1e4e8; background:#fff; padding:2px 8px; border-radius:6px; font-size:.8rem; cursor:pointer; }}
|
|
248
|
+
.doc table {{ border-collapse: collapse; width: 100%; }}
|
|
249
|
+
.doc th, .doc td {{ border:1px solid #e1e4e8; padding:6px 10px; vertical-align: top; }}
|
|
250
|
+
.doc img {{ max-width:100%; height:auto; }}
|
|
251
|
+
.doc .note {{ background:#f6f8fa; border:1px solid #e1e4e8; padding:10px 12px; border-radius:8px; }}
|
|
252
|
+
</style>
|
|
253
|
+
<article class="doc"><p class="note">Loading documentation…</p></article>
|
|
254
|
+
`;
|
|
255
|
+
const container = shadow.querySelector('.doc');
|
|
256
|
+
const mk = document.createElement('script');
|
|
257
|
+
mk.src = 'https://cdn.jsdelivr.net/npm/marked/marked.min.js';
|
|
258
|
+
mk.onload = () => {{ fetch('/static/docs.md', {{ cache: 'no-cache' }})
|
|
259
|
+
.then(r => r.text())
|
|
260
|
+
.then(md => {{ container.innerHTML = window.marked.parse(md); addCopyButtons(); }})
|
|
261
|
+
.catch(() => {{ container.innerHTML = '<p style="color:#b00">Could not load <code>static/docs.md</code>.</p>'; }}); }};
|
|
262
|
+
shadow.appendChild(mk);
|
|
263
|
+
function addCopyButtons() {{ shadow.querySelectorAll('pre > code').forEach(code => {{
|
|
264
|
+
const btn = document.createElement('button'); btn.className = 'copy-btn'; btn.textContent = 'Copy';
|
|
265
|
+
btn.addEventListener('click', () => {{ navigator.clipboard.writeText(code.textContent || ''); btn.textContent = 'Copied'; setTimeout(() => btn.textContent='Copy', 900); }});
|
|
266
|
+
code.parentElement.appendChild(btn);
|
|
267
|
+
}}); }}
|
|
268
|
+
}})();
|
|
269
|
+
</script>
|
|
270
|
+
```
|
|
271
|
+
Upload your Markdown as `static/docs.md` and you’re done.
|
|
272
|
+
-->
|
|
Binary file
|