smart_prompt 0.5.0 → 0.5.1
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.
- checksums.yaml +4 -4
- data/CHANGELOG.md +18 -2
- data/README.cn.md +55 -4
- data/README.md +55 -4
- data/docs/ANTHROPIC_EXAMPLES.md +559 -0
- data/docs/CONVERSATION_INTEGRATION_SUMMARY.md +155 -0
- data/docs/HISTORY_EXAMPLES_README.md +533 -0
- data/docs/HISTORY_MANAGEMENT_GUIDE.md +797 -0
- data/docs/MONITORING_GUIDE.md +278 -0
- data/docs/MULTIMODAL_README.md +265 -0
- data/docs/RELEVANCE_BASED_STRATEGY_IMPLEMENTATION.md +124 -0
- data/docs/STT_README.md +302 -0
- data/docs/TTS_README.md +303 -0
- data/docs/VIDEO_GENERATION_README.md +246 -0
- data/docs/delete_files_list.md +124 -0
- data/lib/smart_prompt/anthropic_adapter.rb +167 -140
- data/lib/smart_prompt/conversation.rb +195 -42
- data/lib/smart_prompt/engine.rb +20 -10
- data/lib/smart_prompt/openai_adapter.rb +25 -1
- data/lib/smart_prompt/version.rb +1 -1
- data/lib/smart_prompt/worker.rb +5 -2
- data/lib/smart_prompt.rb +2 -1
- metadata +33 -22
|
@@ -0,0 +1,246 @@
|
|
|
1
|
+
# SmartPrompt Video Generation Guide
|
|
2
|
+
|
|
3
|
+
This guide explains how to use the new Video Generation capabilities in SmartPrompt.
|
|
4
|
+
|
|
5
|
+
## Overview
|
|
6
|
+
|
|
7
|
+
The Video Generation feature adds support for:
|
|
8
|
+
- **Text-to-Video Generation**: Generate videos from text prompts
|
|
9
|
+
- **Image-to-Video Generation**: Create videos from existing images
|
|
10
|
+
- **Asynchronous Processing**: Handle long-running video generation jobs
|
|
11
|
+
- **Status Monitoring**: Check progress and download completed videos
|
|
12
|
+
|
|
13
|
+
## Installation
|
|
14
|
+
|
|
15
|
+
Make sure you have the required dependencies:
|
|
16
|
+
|
|
17
|
+
```bash
|
|
18
|
+
gem install openai
|
|
19
|
+
```
|
|
20
|
+
|
|
21
|
+
## Configuration
|
|
22
|
+
|
|
23
|
+
Add the Video Generation adapter to your configuration:
|
|
24
|
+
|
|
25
|
+
```yaml
|
|
26
|
+
# config.yml
|
|
27
|
+
adapters:
|
|
28
|
+
multimodal: "MultimodalAdapter"
|
|
29
|
+
image_generation: "ImageGenerationAdapter"
|
|
30
|
+
video_generation: "VideoGenerationAdapter"
|
|
31
|
+
|
|
32
|
+
llms:
|
|
33
|
+
video_gen:
|
|
34
|
+
adapter: "video_generation"
|
|
35
|
+
url: "https://api.siliconflow.cn/v1/"
|
|
36
|
+
api_key: "ENV[SILICONFLOW_API_KEY]"
|
|
37
|
+
model: "Wan-AI/Wan2.2-T2V-A14B"
|
|
38
|
+
|
|
39
|
+
default_llm: "video_gen"
|
|
40
|
+
template_path: "./templates"
|
|
41
|
+
worker_path: "./workers"
|
|
42
|
+
logger_file: "./logs/smart_prompt.log"
|
|
43
|
+
```
|
|
44
|
+
|
|
45
|
+
## Available Workers
|
|
46
|
+
|
|
47
|
+
### 1. Video Generator Worker
|
|
48
|
+
Generate videos from text prompts.
|
|
49
|
+
|
|
50
|
+
```ruby
|
|
51
|
+
result = engine.call_worker(:video_generator, {
|
|
52
|
+
prompt: "A beautiful sunset over ocean waves",
|
|
53
|
+
duration: 4, # Optional: Video duration in seconds (1-10)
|
|
54
|
+
resolution: "720p", # Optional: "480p", "720p", "1080p"
|
|
55
|
+
fps: 24, # Optional: Frames per second
|
|
56
|
+
seed: 12345, # Optional: Random seed for reproducibility
|
|
57
|
+
wait_for_completion: false, # Optional: Wait for job completion
|
|
58
|
+
download_to_file: false, # Optional: Download video when completed
|
|
59
|
+
output_dir: "./videos", # Optional: Output directory
|
|
60
|
+
filename_prefix: "video" # Optional: Filename prefix
|
|
61
|
+
})
|
|
62
|
+
```
|
|
63
|
+
|
|
64
|
+
### 2. Image-to-Video Generator Worker
|
|
65
|
+
Create videos from existing images.
|
|
66
|
+
|
|
67
|
+
```ruby
|
|
68
|
+
result = engine.call_worker(:image_to_video_generator, {
|
|
69
|
+
image_file: "./input.jpg",
|
|
70
|
+
prompt: "Make the image come to life with animation",
|
|
71
|
+
duration: 4,
|
|
72
|
+
resolution: "720p",
|
|
73
|
+
wait_for_completion: false,
|
|
74
|
+
download_to_file: true
|
|
75
|
+
})
|
|
76
|
+
```
|
|
77
|
+
|
|
78
|
+
### 3. Video Status Checker Worker
|
|
79
|
+
Check the status of a video generation job.
|
|
80
|
+
|
|
81
|
+
```ruby
|
|
82
|
+
result = engine.call_worker(:video_status_checker, {
|
|
83
|
+
job_id: "job_123456789",
|
|
84
|
+
download_to_file: true, # Optional: Download if completed
|
|
85
|
+
output_dir: "./videos",
|
|
86
|
+
filename_prefix: "completed_video"
|
|
87
|
+
})
|
|
88
|
+
```
|
|
89
|
+
|
|
90
|
+
### 4. Creative Video Generator Worker
|
|
91
|
+
Generate artistic videos with style control.
|
|
92
|
+
|
|
93
|
+
```ruby
|
|
94
|
+
result = engine.call_worker(:creative_video_generator, {
|
|
95
|
+
prompt: "A magical forest with glowing fairies",
|
|
96
|
+
video_style: "fantasy animation, Studio Ghibli style",
|
|
97
|
+
duration: 4,
|
|
98
|
+
resolution: "720p",
|
|
99
|
+
wait_for_completion: true,
|
|
100
|
+
download_to_file: true
|
|
101
|
+
})
|
|
102
|
+
```
|
|
103
|
+
|
|
104
|
+
### 5. Product Video Generator Worker
|
|
105
|
+
Generate professional product videos.
|
|
106
|
+
|
|
107
|
+
```ruby
|
|
108
|
+
result = engine.call_worker(:product_video_generator, {
|
|
109
|
+
prompt: "Modern smartphone rotating on marble surface",
|
|
110
|
+
duration: 4,
|
|
111
|
+
resolution: "720p",
|
|
112
|
+
wait_for_completion: true,
|
|
113
|
+
download_to_file: true
|
|
114
|
+
})
|
|
115
|
+
```
|
|
116
|
+
|
|
117
|
+
### 6. Batch Video Generator Worker
|
|
118
|
+
Generate multiple videos from multiple prompts.
|
|
119
|
+
|
|
120
|
+
```ruby
|
|
121
|
+
result = engine.call_worker(:batch_video_generator, {
|
|
122
|
+
prompts: [
|
|
123
|
+
"A cat playing with yarn",
|
|
124
|
+
"A dog running in a field",
|
|
125
|
+
"A bird flying in the sky"
|
|
126
|
+
],
|
|
127
|
+
duration: 3,
|
|
128
|
+
resolution: "720p",
|
|
129
|
+
wait_for_completion: false
|
|
130
|
+
})
|
|
131
|
+
```
|
|
132
|
+
|
|
133
|
+
## Direct Adapter Usage
|
|
134
|
+
|
|
135
|
+
You can also use the adapter directly without workers:
|
|
136
|
+
|
|
137
|
+
```ruby
|
|
138
|
+
# Get the adapter
|
|
139
|
+
adapter = engine.llms["video_gen"]
|
|
140
|
+
|
|
141
|
+
# Generate video
|
|
142
|
+
video_data = adapter.generate_video(
|
|
143
|
+
"A butterfly flying through a garden",
|
|
144
|
+
duration: 4,
|
|
145
|
+
resolution: "720p",
|
|
146
|
+
fps: 24
|
|
147
|
+
)
|
|
148
|
+
|
|
149
|
+
# Check status
|
|
150
|
+
status = adapter.check_video_status(video_data[:job_id])
|
|
151
|
+
|
|
152
|
+
# Wait for completion
|
|
153
|
+
completed_video = adapter.wait_for_video_completion(
|
|
154
|
+
video_data[:job_id],
|
|
155
|
+
check_interval: 10, # Check every 10 seconds
|
|
156
|
+
timeout: 600 # Timeout after 10 minutes
|
|
157
|
+
)
|
|
158
|
+
|
|
159
|
+
# Download video
|
|
160
|
+
if completed_video[:video_url]
|
|
161
|
+
downloaded_file = adapter.download_video(
|
|
162
|
+
completed_video[:video_url],
|
|
163
|
+
"./videos/my_video.mp4"
|
|
164
|
+
)
|
|
165
|
+
end
|
|
166
|
+
```
|
|
167
|
+
|
|
168
|
+
## Response Format
|
|
169
|
+
|
|
170
|
+
Video generation responses return video data objects:
|
|
171
|
+
|
|
172
|
+
```ruby
|
|
173
|
+
{
|
|
174
|
+
job_id: "job_123456789", # Unique job identifier
|
|
175
|
+
status: "processing", # "queued", "processing", "completed", "failed"
|
|
176
|
+
video_url: "https://...", # Video URL when completed
|
|
177
|
+
progress: 50, # Progress percentage
|
|
178
|
+
created_at: "2024-01-01...", # Job creation timestamp
|
|
179
|
+
updated_at: "2024-01-01..." # Last update timestamp
|
|
180
|
+
}
|
|
181
|
+
```
|
|
182
|
+
|
|
183
|
+
## Supported Models
|
|
184
|
+
|
|
185
|
+
SiliconFlow supports various video generation models:
|
|
186
|
+
- `Wan-AI/Wan2.2-T2V-A14B` - Text-to-video generation
|
|
187
|
+
- `Wan-AI/Wan2.2-I2V-A14B` - Image-to-video generation
|
|
188
|
+
|
|
189
|
+
## Video Specifications
|
|
190
|
+
|
|
191
|
+
- **Duration**: 1-10 seconds
|
|
192
|
+
- **Resolution**: 480p, 720p, 1080p
|
|
193
|
+
- **FPS**: 24, 30, 60 frames per second
|
|
194
|
+
- **Format**: MP4
|
|
195
|
+
|
|
196
|
+
## Asynchronous Processing
|
|
197
|
+
|
|
198
|
+
Video generation is an asynchronous process:
|
|
199
|
+
|
|
200
|
+
1. **Submit Job**: Returns immediately with job ID
|
|
201
|
+
2. **Check Status**: Monitor progress periodically
|
|
202
|
+
3. **Wait for Completion**: Optionally wait for job to finish
|
|
203
|
+
4. **Download Result**: Download video when completed
|
|
204
|
+
|
|
205
|
+
## Error Handling
|
|
206
|
+
|
|
207
|
+
```ruby
|
|
208
|
+
begin
|
|
209
|
+
result = engine.call_worker(:video_generator, params)
|
|
210
|
+
rescue SmartPrompt::LLMAPIError => e
|
|
211
|
+
puts "API Error: #{e.message}"
|
|
212
|
+
rescue SmartPrompt::Error => e
|
|
213
|
+
puts "General Error: #{e.message}"
|
|
214
|
+
rescue => e
|
|
215
|
+
puts "Unexpected Error: #{e.message}"
|
|
216
|
+
end
|
|
217
|
+
```
|
|
218
|
+
|
|
219
|
+
## Best Practices
|
|
220
|
+
|
|
221
|
+
1. **Prompt Engineering**: Use detailed, time-sequential descriptions
|
|
222
|
+
2. **Video Length**: Keep videos under 10 seconds for best results
|
|
223
|
+
3. **Resolution**: Use 720p for good quality and reasonable processing time
|
|
224
|
+
4. **Batch Processing**: Use batch generation for multiple videos
|
|
225
|
+
5. **Status Monitoring**: Check status periodically for long-running jobs
|
|
226
|
+
6. **Error Recovery**: Implement retry logic for failed jobs
|
|
227
|
+
|
|
228
|
+
## Example
|
|
229
|
+
|
|
230
|
+
See `examples/video_generation_example.rb` for complete working examples.
|
|
231
|
+
|
|
232
|
+
## Troubleshooting
|
|
233
|
+
|
|
234
|
+
**Common Issues:**
|
|
235
|
+
- **API Key Error**: Ensure `SILICONFLOW_API_KEY` environment variable is set
|
|
236
|
+
- **Model Not Found**: Check that the specified model is available on SiliconFlow
|
|
237
|
+
- **Timeout Errors**: Video generation can take several minutes
|
|
238
|
+
- **Network Issues**: Check internet connectivity and API endpoint availability
|
|
239
|
+
- **File Permissions**: Ensure write permissions for output directories
|
|
240
|
+
|
|
241
|
+
**Job Status Meanings:**
|
|
242
|
+
- `queued`: Job is waiting to be processed
|
|
243
|
+
- `processing`: Job is currently being processed
|
|
244
|
+
- `completed`: Job finished successfully, video is available
|
|
245
|
+
- `failed`: Job failed, check error message
|
|
246
|
+
- `cancelled`: Job was cancelled by user or system
|
|
@@ -0,0 +1,124 @@
|
|
|
1
|
+
# 待删除文件列表
|
|
2
|
+
|
|
3
|
+
## 高优先级删除(安全且推荐)
|
|
4
|
+
|
|
5
|
+
### 构建产物
|
|
6
|
+
```bash
|
|
7
|
+
smart_prompt-0.3.4.gem
|
|
8
|
+
```
|
|
9
|
+
|
|
10
|
+
### 生成的媒体文件(占用空间较大)
|
|
11
|
+
```bash
|
|
12
|
+
generated_images/sunset_1.png
|
|
13
|
+
art_images/fantasy_forest_1.png
|
|
14
|
+
direct_images/cartoon_cat_1.png
|
|
15
|
+
direct_images/cartoon_cat_2.png
|
|
16
|
+
product_images/smartphone_1.png
|
|
17
|
+
```
|
|
18
|
+
|
|
19
|
+
### 日志文件
|
|
20
|
+
```bash
|
|
21
|
+
logs/smart_prompt.log
|
|
22
|
+
```
|
|
23
|
+
|
|
24
|
+
---
|
|
25
|
+
|
|
26
|
+
## 中优先级删除(开发辅助文件)
|
|
27
|
+
|
|
28
|
+
### 开发工具缓存和配置
|
|
29
|
+
```bash
|
|
30
|
+
.ruby-lsp/
|
|
31
|
+
.claude/settings.local.json
|
|
32
|
+
.vscode/launch.json
|
|
33
|
+
.kiro/
|
|
34
|
+
```
|
|
35
|
+
|
|
36
|
+
### 重复的文档文件(主文档已涵盖相关内容)
|
|
37
|
+
```bash
|
|
38
|
+
ANTHROPIC_EXAMPLES.md
|
|
39
|
+
IMAGE_GENERATION_README.md
|
|
40
|
+
TTS_README.md
|
|
41
|
+
STT_README.md
|
|
42
|
+
VIDEO_GENERATION_README.md
|
|
43
|
+
MULTIMODAL_README.md
|
|
44
|
+
QUICK_START_ANTHROPIC.md
|
|
45
|
+
HISTORY_MIGRATION_GUIDE.md
|
|
46
|
+
```
|
|
47
|
+
|
|
48
|
+
### 实现总结文档
|
|
49
|
+
```bash
|
|
50
|
+
examples/IMPLEMENTATION_SUMMARY.md
|
|
51
|
+
```
|
|
52
|
+
|
|
53
|
+
---
|
|
54
|
+
|
|
55
|
+
## 低优先级删除(示例和工作进程文件)
|
|
56
|
+
|
|
57
|
+
### 非核心示例文件(examples目录)
|
|
58
|
+
```bash
|
|
59
|
+
examples/anthropic_vision_example.rb
|
|
60
|
+
examples/anthropic_example.rb
|
|
61
|
+
examples/anthropic_tools_example.rb
|
|
62
|
+
examples/automatic_cleanup_example.rb
|
|
63
|
+
examples/chat_example.rb
|
|
64
|
+
examples/examples.rb
|
|
65
|
+
examples/fast_example.rb
|
|
66
|
+
examples/inner_thoughts_example.rb
|
|
67
|
+
examples/logging_example.rb
|
|
68
|
+
examples/message_example.rb
|
|
69
|
+
examples/monitoring_example.rb
|
|
70
|
+
examples/multimodal_example.rb
|
|
71
|
+
examples/structured_data_example.rb
|
|
72
|
+
```
|
|
73
|
+
|
|
74
|
+
### 非核心工作进程文件(workers目录)
|
|
75
|
+
```bash
|
|
76
|
+
workers/image_generation_workers.rb
|
|
77
|
+
workers/multimodal_workers.rb
|
|
78
|
+
workers/stt_workers.rb
|
|
79
|
+
workers/tts_workers.rb
|
|
80
|
+
workers/video_generation_workers.rb
|
|
81
|
+
```
|
|
82
|
+
|
|
83
|
+
---
|
|
84
|
+
|
|
85
|
+
## 其他可考虑删除的文档(可选)
|
|
86
|
+
|
|
87
|
+
### 实施细节文档(如果不再需要)
|
|
88
|
+
```bash
|
|
89
|
+
HISTORY_MANAGEMENT_GUIDE.md
|
|
90
|
+
MONITORING_GUIDE.md
|
|
91
|
+
RELEVANCE_BASED_STRATEGY_IMPLEMENTATION.md
|
|
92
|
+
```
|
|
93
|
+
|
|
94
|
+
---
|
|
95
|
+
|
|
96
|
+
## 总计
|
|
97
|
+
|
|
98
|
+
- **文件数量**: 41个文件/目录
|
|
99
|
+
- **预计释放空间**: 3.5MB - 4.5MB(主要为媒体文件和日志)
|
|
100
|
+
|
|
101
|
+
---
|
|
102
|
+
|
|
103
|
+
## 删除方法
|
|
104
|
+
|
|
105
|
+
可以使用以下命令批量删除:
|
|
106
|
+
|
|
107
|
+
```bash
|
|
108
|
+
# 删除生成的媒体文件和构建产物
|
|
109
|
+
rm -f smart_prompt-0.3.4.gem generated_images/sunset_1.png art_images/fantasy_forest_1.png direct_images/cartoon_cat_*.png product_images/smartphone_1.png logs/smart_prompt.log
|
|
110
|
+
|
|
111
|
+
# 删除示例文件(如果需要)
|
|
112
|
+
rm -f examples/*_example.rb examples/example.rb examples/examples.rb
|
|
113
|
+
|
|
114
|
+
# 删除工作进程文件(如果需要)
|
|
115
|
+
rm -f workers/*_workers.rb
|
|
116
|
+
|
|
117
|
+
# 删除docs文件(如果需要)
|
|
118
|
+
rm -f IMAGE_GENERATION_README.md TTS_README.md STT_README.md VIDEO_GENERATION_README.md MULTIMODAL_README.md ANTHROPIC_EXAMPLES.md QUICK_START_ANTHROPIC.md HISTORY_MIGRATION_GUIDE.md examples/IMPLEMENTATION_SUMMARY.md
|
|
119
|
+
|
|
120
|
+
# 删除开发工具配置文件(如果需要)
|
|
121
|
+
rm -rf .ruby-lsp/ .claude/ .vscode/ .kiro/
|
|
122
|
+
```
|
|
123
|
+
|
|
124
|
+
**注意**: 在删除任何文件之前,建议先进行备份或确认这些文件确实不再需要。
|