ciyidogan commited on
Commit
dced8da
·
verified ·
1 Parent(s): c1b9e28

Delete flare-tasarim.md

Browse files
Files changed (1) hide show
  1. flare-tasarim.md +0 -444
flare-tasarim.md DELETED
@@ -1,444 +0,0 @@
1
- # Flare Platform - Güncel Tasarım Dokümanı
2
-
3
- ## 🏗 Genel Mimari
4
-
5
- Flare, modüler LLM provider desteği ile çalışan çok adımlı ve akıllı bir orchestration katmanıdır. Provider-agnostic tasarımı sayesinde farklı LLM, TTS ve STT motorları ile çalışabilir.
6
-
7
- ### Temel Özellikler
8
- - ✅ Provider-based mimari (LLM, TTS, STT)
9
- - ✅ Intent detection ve parameter extraction
10
- - ✅ Akıllı parametre toplama (smart grouping)
11
- - ✅ Onay mekanizması (requiresApproval)
12
- - ✅ Multi-language destek (LocalizedExample, LocalizedCaption)
13
- - ✅ Session-based state machine
14
- - ✅ API orchestration ve response mapping
15
- - ✅ Activity logging ve audit trail
16
-
17
- ## 📋 Konfigürasyon Yapısı
18
-
19
- ### service_config.jsonc - Ana Yapı
20
- ```json
21
- {
22
- "config": {
23
- // Provider tanımları
24
- "llm_provider": {
25
- "name": "spark|gpt4o|gpt4o-mini",
26
- "api_key": "enc:...", // Şifrelenmiş
27
- "endpoint": "https://...",
28
- "settings": {
29
- "internal_prompt": "Global LLM yönergesi",
30
- "parameter_collection_config": {
31
- "max_params_per_question": 2,
32
- "smart_grouping": true,
33
- "retry_unanswered": true,
34
- "collection_prompt": "..."
35
- }
36
- }
37
- },
38
- "tts_provider": {
39
- "name": "no_tts|elevenlabs|blaze",
40
- "api_key": "enc:...",
41
- "endpoint": null,
42
- "settings": {}
43
- },
44
- "stt_provider": {
45
- "name": "no_stt|google|azure|flicker",
46
- "api_key": "/path/to/credentials.json",
47
- "endpoint": null,
48
- "settings": {
49
- "language": "tr-TR",
50
- "model": "latest_long"
51
- }
52
- },
53
- "providers": [
54
- // Kullanılabilir provider tanımları
55
- ],
56
- "users": [...]
57
- },
58
- "projects": [...],
59
- "apis": [...],
60
- "activity_log": [...],
61
- "project_id_counter": 1,
62
- "last_update_date": null,
63
- "last_update_user": null
64
- }
65
- ```
66
-
67
- ### Provider Sistemi
68
-
69
- #### Provider Config
70
- ```json
71
- {
72
- "type": "llm|tts|stt",
73
- "name": "spark",
74
- "display_name": "Spark LLM",
75
- "requires_endpoint": true,
76
- "requires_api_key": true,
77
- "requires_repo_info": false,
78
- "description": "YTU Cosmos Spark LLM"
79
- }
80
- ```
81
-
82
- #### Provider Settings
83
- ```json
84
- {
85
- "name": "provider_name",
86
- "api_key": "enc:encrypted_key",
87
- "endpoint": "https://endpoint",
88
- "settings": {
89
- // Provider-specific ayarlar
90
- }
91
- }
92
- ```
93
-
94
- ### Project Yapısı
95
- ```json
96
- {
97
- "id": 1,
98
- "name": "project_name",
99
- "caption": "Proje Başlığı",
100
- "icon": "folder",
101
- "description": "Açıklama",
102
- "enabled": true,
103
- "default_locale": "tr",
104
- "supported_locales": ["tr", "en"],
105
- "timezone": "Europe/Istanbul",
106
- "region": "tr-TR",
107
- "versions": [...],
108
- "version_id_counter": 1,
109
- "deleted": false,
110
- "created_date": "2024-01-01T00:00:00Z",
111
- "created_by": "username",
112
- "last_update_date": null,
113
- "last_update_user": null
114
- }
115
- ```
116
-
117
- ### Version Yapısı
118
- ```json
119
- {
120
- "id": 1,
121
- "no": 1,
122
- "caption": "v1",
123
- "description": "Version açıklaması",
124
- "published": true,
125
- "deleted": false,
126
- "general_prompt": "Asistan için genel yönerge",
127
- "welcome_prompt": "Hoşgeldin mesajı yönergesi",
128
- "llm": {
129
- "repo_id": "model-id",
130
- "generation_config": {},
131
- "use_fine_tune": false,
132
- "fine_tune_zip": ""
133
- },
134
- "intents": [...],
135
- "created_date": "2024-01-01T00:00:00Z",
136
- "created_by": "username",
137
- "publish_date": null,
138
- "published_by": null
139
- }
140
- ```
141
-
142
- ### Intent Yapısı
143
- ```json
144
- {
145
- "name": "intent_name",
146
- "caption": "Intent Başlığı",
147
- "requiresApproval": false,
148
- "dependencies": [],
149
- "examples": [
150
- {
151
- "locale_code": "tr",
152
- "example": "Örnek cümle"
153
- }
154
- ],
155
- "detection_prompt": "Intent algılama yönergesi",
156
- "parameters": [...],
157
- "action": "api_name",
158
- "fallback_timeout_prompt": "Zaman aşımı mesajı",
159
- "fallback_error_prompt": "Hata mesajı"
160
- }
161
- ```
162
-
163
- ### Parameter Yapısı
164
- ```json
165
- {
166
- "name": "param_name",
167
- "caption": [
168
- {
169
- "locale_code": "tr",
170
- "caption": "Parametre Başlığı"
171
- }
172
- ],
173
- "type": "str|int|float|bool|date",
174
- "required": true,
175
- "variable_name": "variable_name",
176
- "extraction_prompt": "Parametre çıkarma yönergesi",
177
- "validation_regex": "^pattern$",
178
- "invalid_prompt": "Geçersiz değer mesajı",
179
- "type_error_prompt": "Tip hatası mesajı"
180
- }
181
- ```
182
-
183
- ### API Yapısı
184
- ```json
185
- {
186
- "name": "api_name",
187
- "description": "{{variables.x}} için işlem açıklaması",
188
- "url": "https://api-endpoint",
189
- "method": "GET|POST|PUT|DELETE",
190
- "headers": "{}", // JSON string
191
- "body_template": "{}", // JSON string
192
- "timeout_seconds": 10,
193
- "retry": {
194
- "max_attempts": 3,
195
- "backoff_seconds": 2,
196
- "strategy": "static|exponential"
197
- },
198
- "auth": {
199
- "enabled": true,
200
- "token_endpoint": "https://auth-endpoint",
201
- "response_token_path": "access_token",
202
- "token_request_body": "{}",
203
- "token_refresh_endpoint": null,
204
- "token_refresh_body": "{}"
205
- },
206
- "response_mappings": [
207
- {
208
- "variable_name": "result",
209
- "caption": "Sonuç",
210
- "type": "str",
211
- "json_path": "$.data.result"
212
- }
213
- ],
214
- "response_prompt": "Response insanileştirme yönergesi",
215
- "deleted": false,
216
- "created_date": "2024-01-01T00:00:00Z",
217
- "created_by": "username"
218
- }
219
- ```
220
-
221
- ## 🔄 Session ve State Yönetimi
222
-
223
- ### Session Özellikleri
224
- ```python
225
- class Session:
226
- session_id: str
227
- project_name: str
228
- version_number: int
229
- version_config: VersionConfig
230
-
231
- # State machine
232
- state: str # idle | await_param | call_api | humanize
233
- last_intent: str | None
234
- awaiting_parameters: List[str]
235
- missing_ask_count: int
236
-
237
- # Data storage
238
- variables: Dict[str, str]
239
- auth_tokens: Dict[str, Dict]
240
- chat_history: List[Dict[str, str]]
241
-
242
- # Smart parameter tracking
243
- asked_parameters: Dict[str, int]
244
- unanswered_parameters: List[str]
245
- parameter_ask_rounds: int
246
-
247
- # Real-time support
248
- is_realtime_session: bool
249
- active_websocket: Any
250
- ```
251
-
252
- ### State Machine Flow
253
- ```
254
- start_session → welcome_prompt
255
-
256
- idle ← ← ← ← ← ← ← ← ← ← ← ← ← ← ← ← ← ← ← ← ←
257
- ↓ ↑
258
- detect_intent → collect_params → approval? → call_api → humanize
259
- ↑ ↓
260
- ← await_param ←
261
- ```
262
-
263
- ## 🔐 Onay Mekanizması
264
-
265
- Intent'te `requiresApproval: true` olduğunda:
266
-
267
- 1. **Otomatik parametre ekleme**: `is_approved` parametresi dinamik olarak eklenir
268
- 2. **Onay sorusu oluşturma**: API description'daki placeholder'lar değiştirilir
269
- 3. **Onay kontrolü**:
270
- - Onay verilirse → API çağrısı
271
- - Onay verilmezse → İşlem iptali
272
-
273
- ## 🌍 Multi-Language Destek
274
-
275
- ### Locale Yönetimi
276
- - Project seviyesinde `default_locale` ve `supported_locales`
277
- - LocalizedExample ve LocalizedCaption yapıları
278
- - Locale JSON dosyaları (`tr.json`, `en.json`, vb.)
279
-
280
- ### LocaleManager
281
- ```python
282
- # Locale bilgilerini yönetir
283
- LocaleManager.get_locale("tr")
284
- LocaleManager.format_date(date, "tr")
285
- LocaleManager.parse_date_expression("yarın", "tr")
286
- LocaleManager.format_number(1234.56, "tr")
287
- ```
288
-
289
- ## 🎤 TTS/STT Entegrasyonu
290
-
291
- ### TTS Providers
292
- - **ElevenLabs**: Yüksek kaliteli, çok dilli
293
- - **Blaze**: Alternatif TTS
294
- - **No TTS**: Devre dışı
295
-
296
- ### STT Providers
297
- - **Google**: Cloud Speech-to-Text
298
- - **Azure**: Azure Speech Services
299
- - **Flicker**: Alternatif STT
300
- - **No STT**: Devre dışı
301
-
302
- ### Real-time Features
303
- - WebSocket-based audio streaming
304
- - Voice Activity Detection (VAD)
305
- - Noise reduction
306
- - Interim results
307
-
308
- ## 🚀 LLM Provider Desteği
309
-
310
- ### Spark
311
- - YTU Cosmos modelleri
312
- - HuggingFace Cloud veya on-premise
313
- - Custom fine-tuning desteği
314
-
315
- ### GPT-4o / GPT-4o-mini
316
- - OpenAI API entegrasyonu
317
- - Temperature ve max_tokens kontrolü
318
- - Maliyet optimizasyonu
319
-
320
- ### Provider Seçimi
321
- ```python
322
- # chat_handler.py
323
- if llm_provider.name == "spark":
324
- llm = SparkLLM(endpoint, token)
325
- elif llm_provider.name.startswith("gpt4o"):
326
- llm = GPT4oLLM(api_key, model)
327
- ```
328
-
329
- ## 📡 API Yönetimi
330
-
331
- ### API Çağrı Süreci
332
- 1. **Variable substitution**: `{{variables.xxx}}` → gerçek değerler
333
- 2. **Auth token yönetimi**: Otomatik token alma ve yenileme
334
- 3. **Retry logic**: Configurable retry stratejisi
335
- 4. **Response mapping**: JSON path ile veri çıkarma
336
- 5. **Response humanization**: LLM ile insanileştirme
337
-
338
- ### Auth Mekanizması
339
- ```python
340
- # Token alma ve cache'leme
341
- if api.auth.enabled:
342
- token = get_or_refresh_token(api, session)
343
- headers["Authorization"] = f"Bearer {token}"
344
- ```
345
-
346
- ## 🔒 Güvenlik
347
-
348
- ### Encryption
349
- - API key'ler `enc:` prefix ile şifrelenmiş saklanır
350
- - Fernet encryption (symmetric)
351
- - Environment variable: `FERNET_KEY`
352
-
353
- ### Authentication
354
- - JWT-based session yönetimi
355
- - Bcrypt password hashing
356
- - Session timeout kontrolü
357
-
358
- ### Race Condition Koruması
359
- - `last_update_date` ile optimistic locking
360
- - Thread-safe session store
361
- - Concurrent update kontrolü
362
-
363
- ## 📊 Monitoring ve Logging
364
-
365
- ### Activity Log
366
- ```json
367
- {
368
- "timestamp": "2024-01-01T00:00:00Z",
369
- "username": "admin",
370
- "action": "CREATE_PROJECT",
371
- "entity_type": "project",
372
- "entity_id": 1,
373
- "entity_name": "project_name",
374
- "details": "Additional info"
375
- }
376
- ```
377
-
378
- ### Log Actions
379
- - Project CRUD: CREATE, UPDATE, DELETE, ENABLE, DISABLE
380
- - Version: CREATE, UPDATE, PUBLISH, DELETE
381
- - API: CREATE, UPDATE, DELETE
382
- - Environment: UPDATE_ENVIRONMENT
383
- - Import/Export: IMPORT_PROJECT, EXPORT_PROJECT
384
-
385
- ## 🧪 Test ve Development
386
-
387
- ### Mock Backend
388
- - Scenario-based testing
389
- - Configurable responses
390
- - Error simulation
391
-
392
- ### Debug Features
393
- - Detailed timestamped logging
394
- - Request/Response tracking
395
- - Performance metrics
396
-
397
- ## 🔄 Import/Export
398
-
399
- ### Project Export Format
400
- ```json
401
- {
402
- "name": "project_name",
403
- "caption": "Project Caption",
404
- "icon": "folder",
405
- "description": "Description",
406
- "default_locale": "tr",
407
- "supported_locales": ["tr", "en"],
408
- "versions": [
409
- {
410
- "caption": "v1",
411
- "general_prompt": "...",
412
- "llm": {...},
413
- "intents": [...]
414
- }
415
- ]
416
- }
417
- ```
418
-
419
- ## 🚦 Production Deployment
420
-
421
- ### Docker Support
422
- - HuggingFace Spaces uyumlu
423
- - Health check endpoint
424
- - Environment-based configuration
425
- - Volume mount için permission handling
426
-
427
- ### Environment Variables
428
- ```bash
429
- FERNET_KEY=... # Encryption key
430
- SPARK_TOKEN=... # Spark API token
431
- OPENAI_API_KEY=... # GPT-4o key
432
- GOOGLE_APPLICATION_CREDENTIALS=... # STT credentials
433
- HF_HOME=/app/.cache # HuggingFace cache
434
- ```
435
-
436
- ### Health Check
437
- ```python
438
- @app.get("/")
439
- def health():
440
- return {"status": "ok"}
441
-
442
- # Hugging Face için daemon thread
443
- threading.Thread(target=run_health_server, daemon=True).start()
444
- ```