hf-model-inference
Guidance for setting up HuggingFace model inference services with Flask APIs. This skill applies when downloading HuggingFace models, creating inference endpoints, or building ML model serving APIs. Use for tasks involving transformers library, model caching, and REST API creation for ML models.
Works with
---
name: hf-model-inference
description: Guidance for setting up HuggingFace model inference services with Flask APIs. This skill applies when downloading HuggingFace models, creating inference endpoints, or building ML model serving APIs. Use for tasks involving transformers library, model caching, and REST API creation for ML models.
license: MIT
---
# HuggingFace Model Inference Service
## Overview
This skill provides procedural guidance for setting up HuggingFace model inference services. It covers model downloading, caching strategies, Flask API creation, and service deployment patterns.
## Workflow
### Phase 1: Environment Setup
1. **Verify package manager availability**
- Check for `uv`, `pip`, or `conda` before installing dependencies
- Prefer `uv` for faster dependency resolution when available
2. **Install required packages**
- Core: `transformers`, `torch` (or `tensorflow`)
- API: `flask` for REST endpoints
- Set appropriate timeouts for large package installations (300+ seconds)
3. **Create model cache directory**
- Establish a dedicated directory for model storage (e.g., `/app/model_cache/model_name`)
- Create parent directories as needed before downloading
### Phase 2: Model Download
1. **Download the model separately from API startup**
- Use a dedicated download script or inline download before starting the service
- This prevents timeout issues during API initialization
2. **Specify cache directory explicitly**
```python
from transformers import pipeline
model = pipeline("task-type", model="model-name", cache_dir="/path/to/cache")
```
3. **Verification step** (commonly missed)
- After download, verify model files exist in the target directory
- List directory contents to confirm successful download
### Phase 3: API Creation
1. **Flask application structure**
```python
from flask import Flask, request, jsonify
from transformers import pipeline
app = Flask(__name__)
model = None # Load at startup
@app.route('/predict', methods=['POST'])
def predict():
# Handle inference
pass
```
2. **Input validation requirements**
- Check for required fields in request JSON
- Validate field types (string, number, etc.)
- Handle empty or whitespace-only inputs
- Return descriptive error messages with appropriate HTTP status codes
3. **Error response format**
- Use consistent JSON structure: `{"error": "message"}`
- Return 400 for client errors, 500 for server errors
### Phase 4: Service Deployment
1. **Host and port configuration**
- Bind to `0.0.0.0` for external accessibility
- Use specified port (commonly 5000)
- Example: `app.run(host='0.0.0.0', port=5000)`
2. **Background execution**
- Start Flask in background mode for testing
- Allow startup time (2-3 seconds) before sending test requests
## Verification Strategies
### Model Download Verification
- List cache directory contents after download
- Confirm expected model files exist (config.json, model weights, tokenizer files)
### API Functionality Testing
Test these scenarios in order:
1. **Positive case**: Valid input that should succeed
```bash
curl -X POST http://localhost:5000/predict \
-H "Content-Type: application/json" \
-d '{"text": "valid input text"}'
```
2. **Negative case**: Different valid input to verify varied responses
```bash
curl -X POST http://localhost:5000/predict \
-H "Content-Type: application/json" \
-d '{"text": "different input text"}'
```
3. **Error case**: Missing required field
```bash
curl -X POST http://localhost:5000/predict \
-H "Content-Type: application/json" \
-d '{}'
```
### Extended Edge Cases (Optional)
- Empty string input
- Very long text input
- Non-JSON content type
- Malformed JSON
- Wrong field type (number instead of string)
## Common Pitfalls
### Installation Issues
- **Insufficient timeout**: Large packages like `torch` require extended timeouts (5+ minutes)
- **Missing system dependencies**: Some models require additional system packages
### Model Loading Issues
- **Cold start timeout**: Loading models at first request causes timeouts; load at startup instead
- **Memory constraints**: Large models may exceed available RAM; check model requirements
### API Issues
- **Development server warning**: Flask development server is not suitable for production; acceptable for testing but note the limitation
- **No graceful shutdown**: Consider signal handling for clean termination
- **No health check endpoint**: Adding `/health` endpoint aids debugging
### Process Management
- **Background process verification**: After starting in background, verify the process is running
- **Port conflicts**: Check if the specified port is already in use before starting
## Task Planning Template
When approaching HuggingFace inference tasks, structure work as follows:
1. Environment verification (package manager, system requirements)
2. Dependency installation with appropriate timeouts
3. Cache directory creation
4. Model download with explicit cache path
5. Model download verification
6. API script creation with validation
7. Service startup in background
8. Functional testing (positive, negative, error cases)
9. Edge case testing (if time permits)More API Design skills
lark-event
larksuite/cli
Lark/Feishu real-time event listening / subscribing / consuming: stream events as NDJSON via `lark-cli event consume <EventKey>` (covers IM messages/reactions/chat changes, Approval status changes, Task updates, VC meeting started/joined/ended, Minutes generated, Whiteboard updated, etc.). Use for Lark bots, real-time message processing, long-running subscribers, streaming webhook/push handlers. Supports `--max-events` / `--timeout` bounded runs and a stderr ready-marker contract — designed for AI agents running as subprocesses.
lark-contact
larksuite/cli
飞书 / Lark 通讯录:按姓名 / 邮箱解析成 open_id,或按 open_id 反查姓名 / 部门 / 邮箱 / 联系方式 / 个人状态 / 签名,以及按关键词搜索当前用户可见的机器人 / 智能体(agent)。当用户提到一个名字要下一步发消息 / 排日程,或拿到 open_id 想查具体信息时使用。不负责部门树遍历、按部门列员工、组织架构图,这类需求走原生 OpenAPI。
lark-openapi-explorer
larksuite/cli
飞书/Lark 原生 OpenAPI 探索:从官方文档库中挖掘未经 CLI 封装的原生 OpenAPI 接口。当用户的需求无法被现有 lark-* skill 或 lark-cli 已注册命令满足,需要查找并调用原生飞书 OpenAPI 时使用。

