🔍 Code Extractor

function get_instruction_templates

Maturity: 44

Flask API endpoint that returns a dictionary of predefined instruction templates for different document types including SOPs, work instructions, quality forms, and document comparison guidelines.

File:
/tf/active/vicechatdev/docchat/app.py
Lines:
1530 - 1680
Complexity:
simple

Purpose

Provides a GET endpoint at '/api/instructions/templates' that serves as a template library for users to access standardized instruction formats. These templates guide users in creating various quality management and manufacturing documents with consistent structure and formatting. The templates include detailed guidelines for SOPs (following ISO 9001 standards), work instructions for floor operators, quality inspection forms, and document comparison/rewriting instructions.

Source Code

def get_instruction_templates():
    """Get available instruction templates"""
    templates = {
        'sop': {
            'name': 'Standard Operating Procedure (SOP)',
            'content': '''# Instructions for Writing a Standard Operating Procedure

## Output Requirements:
- Create a comprehensive SOP document following ISO 9001 standards
- Use clear, numbered steps for each procedure
- Include safety warnings where applicable
- Define roles and responsibilities
- Specify required tools, materials, and equipment

## Document Structure:
1. **Title and Identification**
   - SOP Number
   - Revision number and date
   - Purpose statement

2. **Scope and Applicability**
   - Who should use this SOP
   - When it applies

3. **Definitions and Acronyms**

4. **Procedure Steps**
   - Numbered sequential steps
   - Sub-steps where needed
   - Decision points clearly marked

5. **Quality Control Points**
   - Verification steps
   - Acceptance criteria

6. **References**
   - Related SOPs
   - Standards and regulations

Format the output as a formal document suitable for quality management systems.'''
        },
        'work_instructions': {
            'name': 'Work Instructions',
            'content': '''# Instructions for Creating Work Instructions

## Output Format:
Create detailed work instructions that can be used by operators on the floor.

## Requirements:
- **Visual clarity**: Use bullet points and numbered lists
- **Step-by-step**: Each action should be a separate, clear step
- **Safety first**: Highlight safety precautions with ⚠️ WARNING markers
- **Quality checks**: Include inspection points with ✓ CHECK markers
- **Tools/Materials**: List at the beginning of each section

## Structure:
### 1. Purpose
Brief statement of what this instruction accomplishes

### 2. Prerequisites
- Required skills/training
- Safety equipment needed
- Tools and materials

### 3. Step-by-Step Instructions
Number each step. Use active voice. Be specific about:
- What to do
- How to do it
- What the expected result is

### 4. Quality Verification
- Inspection criteria
- Measurements to take
- Pass/fail conditions

### 5. Troubleshooting
Common problems and solutions

Make it practical and easy to follow for floor personnel.'''
        },
        'quality_form': {
            'name': 'Quality Inspection Form',
            'content': '''# Instructions for Creating a Quality Inspection Form

## Form Design Requirements:

### Header Section:
- Part/Product Name and Number
- Inspection Date and Inspector Name
- Batch/Lot Number
- Purchase Order or Work Order

### Inspection Items:
For each characteristic to inspect, include:
1. **Item Number**: Sequential numbering
2. **Characteristic**: What is being measured/checked
3. **Specification**: Target value and tolerances
4. **Measurement Method**: How to measure/verify
5. **Result Field**: Space to record actual measurement
6. **Pass/Fail**: Clear checkbox or indicator

### Organization:
- Group related characteristics together
- Use tables for dimensional checks
- Use checklists for visual/functional checks
- Include space for notes/observations

### Footer Section:
- Overall result (Accept/Reject)
- Inspector signature and date
- Reviewer signature and date
- Disposition (Use as-is/Rework/Scrap)

Create a form that is:
- Easy to fill out
- Leaves no ambiguity
- Provides clear acceptance criteria
- Is suitable for record keeping'''
        },
        'document_comparison': {
            'name': 'Document Comparison & Rewrite',
            'content': '''# Instructions for Document Comparison and Rewriting

## Task:
Compare the provided documents and rewrite one document based on the structure, style, and format of another.

## Analysis Steps:
1. **Identify the reference document** (the model/template)
2. **Identify the document to be rewritten**
3. **Analyze the reference structure**:
   - Section organization
   - Heading levels and formatting
   - Tone and style (formal/technical/instructional)
   - Level of detail
   - Use of examples, diagrams, tables

4. **Extract content** from the document to be rewritten

5. **Restructure** the content to match the reference format

## Output Requirements:
- Preserve all important information from the original
- Match the structure and style of the reference document
- Maintain consistent formatting throughout
- Use the same level of technical detail
- Keep the same tone (formal, technical, instructional, etc.)

When referring to specific documents in your query, use the document names shown in the references (e.g., "Rewrite Document A following the structure of Document B").'''
        }
    }
    return jsonify(templates)

Return Value

Returns a Flask JSON response containing a dictionary with four template objects. Each template has a 'name' (string describing the template type) and 'content' (string containing detailed markdown-formatted instructions). The templates are keyed as 'sop', 'work_instructions', 'quality_form', and 'document_comparison'. The response has HTTP status 200 and Content-Type application/json.

Dependencies

  • flask

Required Imports

from flask import jsonify

Usage Example

# Assuming Flask app is set up
from flask import Flask, jsonify

app = Flask(__name__)

@app.route('/api/instructions/templates', methods=['GET'])
def get_instruction_templates():
    templates = {
        'sop': {
            'name': 'Standard Operating Procedure (SOP)',
            'content': '''# Instructions for Writing a Standard Operating Procedure...'''
        },
        'work_instructions': {
            'name': 'Work Instructions',
            'content': '''# Instructions for Creating Work Instructions...'''
        },
        'quality_form': {
            'name': 'Quality Inspection Form',
            'content': '''# Instructions for Creating a Quality Inspection Form...'''
        },
        'document_comparison': {
            'name': 'Document Comparison & Rewrite',
            'content': '''# Instructions for Document Comparison and Rewriting...'''
        }
    }
    return jsonify(templates)

if __name__ == '__main__':
    app.run()

# Client-side usage:
# GET http://localhost:5000/api/instructions/templates
# Response: JSON object with all template definitions

Best Practices

  • This endpoint requires no authentication in the current implementation - consider adding authentication if templates contain sensitive information
  • The templates are hardcoded in the function - consider moving them to a configuration file or database for easier maintenance
  • Template content uses triple-quoted strings with markdown formatting - ensure client applications can properly render or parse markdown
  • The endpoint only supports GET requests - this is appropriate for read-only template retrieval
  • Consider adding caching headers to the response since templates are static content
  • Template content includes special markers (⚠️, ✓) - ensure client encoding supports Unicode characters
  • Consider versioning the API endpoint (e.g., /api/v1/instructions/templates) for future compatibility

Similar Components

AI-powered semantic similarity - components with related functionality:

  • function api_templates_v2 74.2% similar

    Flask API endpoint that retrieves and returns a list of available instruction templates from the chat engine.

    From: /tf/active/vicechatdev/vice_ai/app.py
  • function api_templates 72.4% similar

    Flask API endpoint that retrieves and returns a list of available instruction templates from the chat engine.

    From: /tf/active/vicechatdev/vice_ai/complex_app.py
  • function api_load_template_v2 70.3% similar

    Flask API endpoint that retrieves and returns an instruction template by name from the chat engine.

    From: /tf/active/vicechatdev/vice_ai/complex_app.py
  • function api_save_template_v1 69.0% similar

    Flask API endpoint that saves a new instruction template by accepting a POST request with template name and instructions, then persisting it via the chat_engine.

    From: /tf/active/vicechatdev/vice_ai/complex_app.py
  • function api_load_template 68.9% similar

    Flask API endpoint that loads and returns instruction template content by template name, with authentication required.

    From: /tf/active/vicechatdev/vice_ai/app.py
← Back to Browse