lazarus-cms 1.0.0__tar.gz
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.
- lazarus_cms-1.0.0/LICENSE +21 -0
- lazarus_cms-1.0.0/PKG-INFO +96 -0
- lazarus_cms-1.0.0/README.md +84 -0
- lazarus_cms-1.0.0/pyproject.toml +21 -0
- lazarus_cms-1.0.0/setup.cfg +4 -0
- lazarus_cms-1.0.0/src/lazarus/__init__.py +8 -0
- lazarus_cms-1.0.0/src/lazarus/__main__.py +10 -0
- lazarus_cms-1.0.0/src/lazarus/api_manager.py +365 -0
- lazarus_cms-1.0.0/src/lazarus/chat_mode.py +239 -0
- lazarus_cms-1.0.0/src/lazarus/code_mode.py +323 -0
- lazarus_cms-1.0.0/src/lazarus/compiler.py +242 -0
- lazarus_cms-1.0.0/src/lazarus/cron.py +214 -0
- lazarus_cms-1.0.0/src/lazarus/engine.py +169 -0
- lazarus_cms-1.0.0/src/lazarus/md_reader.py +206 -0
- lazarus_cms-1.0.0/src/lazarus/md_writer.py +267 -0
- lazarus_cms-1.0.0/src/lazarus/media.py +0 -0
- lazarus_cms-1.0.0/src/lazarus/security.py +189 -0
- lazarus_cms-1.0.0/src/lazarus/seo.py +131 -0
- lazarus_cms-1.0.0/src/lazarus/site_structure.py +202 -0
- lazarus_cms-1.0.0/src/lazarus/test_api.py +91 -0
- lazarus_cms-1.0.0/src/lazarus/theme.py +330 -0
- lazarus_cms-1.0.0/src/lazarus_cms.egg-info/PKG-INFO +96 -0
- lazarus_cms-1.0.0/src/lazarus_cms.egg-info/SOURCES.txt +24 -0
- lazarus_cms-1.0.0/src/lazarus_cms.egg-info/dependency_links.txt +1 -0
- lazarus_cms-1.0.0/src/lazarus_cms.egg-info/entry_points.txt +2 -0
- lazarus_cms-1.0.0/src/lazarus_cms.egg-info/top_level.txt +1 -0
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 Ali Azimi
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
|
@@ -0,0 +1,96 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: lazarus-cms
|
|
3
|
+
Version: 1.0.0
|
|
4
|
+
Summary: AI-Powered Content Management System with Markdown
|
|
5
|
+
Author: Ali Azimi
|
|
6
|
+
License-Expression: MIT
|
|
7
|
+
Keywords: cms,ai,markdown,website-builder
|
|
8
|
+
Requires-Python: >=3.8
|
|
9
|
+
Description-Content-Type: text/markdown
|
|
10
|
+
License-File: LICENSE
|
|
11
|
+
Dynamic: license-file
|
|
12
|
+
|
|
13
|
+
# 🔧 Lazarus
|
|
14
|
+
## AI-Driven Content Management System with Markdown
|
|
15
|
+
|
|
16
|
+
Lazarus یک CMS هوشمند است که با استفاده از API هوش مصنوعی و فایلهای Markdown، ساخت وبسایت را آسان میکند.
|
|
17
|
+
|
|
18
|
+
## ✨ ویژگیها
|
|
19
|
+
|
|
20
|
+
- 🔑 **اتصال API شخصی** - مثل Hermes، API Key خود را وارد کنید
|
|
21
|
+
- 💬 **Chat Mode** - چت با AI برای ساخت سایت
|
|
22
|
+
- 📝 **Code Mode** - ویرایش مستقیم فایلهای MD
|
|
23
|
+
- 🔨 **Compile Mode** - کامپایل MD به HTML
|
|
24
|
+
- 🎨 **سیستم تم** - تمهای آماده و قابل تنظیم
|
|
25
|
+
- 🔒 **امنیت** - رمزنگاری API Key
|
|
26
|
+
- 📈 **SEO** - بهینهسازی خودکار
|
|
27
|
+
- ⏰ **Cron Job** - زمانبندی وظایف
|
|
28
|
+
|
|
29
|
+
## 🚀 شروع سریع
|
|
30
|
+
|
|
31
|
+
```bash
|
|
32
|
+
# کلون کردن
|
|
33
|
+
git clone https://github.com/areniti/lazarus.git
|
|
34
|
+
cd lazarus
|
|
35
|
+
|
|
36
|
+
# نصب وابستگیها
|
|
37
|
+
pip install requests pyyaml
|
|
38
|
+
|
|
39
|
+
# اجرا
|
|
40
|
+
python3 src/engine.py
|
|
41
|
+
```
|
|
42
|
+
|
|
43
|
+
## 📁 ساختار پروژه
|
|
44
|
+
|
|
45
|
+
```
|
|
46
|
+
lazarus/
|
|
47
|
+
├── lazarus-config.yaml # تنظیمات API
|
|
48
|
+
├── src/
|
|
49
|
+
│ ├── engine.py # موتور اصلی
|
|
50
|
+
│ ├── api_manager.py # مدیریت API
|
|
51
|
+
│ ├── chat_mode.py # حالت چت
|
|
52
|
+
│ ├── code_mode.py # حالت کد
|
|
53
|
+
│ ├── compiler.py # کامپایلر
|
|
54
|
+
│ ├── theme.py # سیستم تم
|
|
55
|
+
│ ├── security.py # امنیت
|
|
56
|
+
│ ├── seo.py # SEO
|
|
57
|
+
│ ├── media.py # رسانه
|
|
58
|
+
│ └── cron.py # زمانبندی
|
|
59
|
+
├── site/ # فایلهای MD
|
|
60
|
+
├── output/ # خروجی HTML
|
|
61
|
+
└── docs/ # مستندات
|
|
62
|
+
```
|
|
63
|
+
|
|
64
|
+
## 📋 دستورات
|
|
65
|
+
|
|
66
|
+
| دستور | توضیح |
|
|
67
|
+
|-------|-------|
|
|
68
|
+
| `/start` | شروع - تنظیم API |
|
|
69
|
+
| `/chat` | Chat Mode - چت با AI |
|
|
70
|
+
| `/code` | Code Mode - ویرایش MD |
|
|
71
|
+
| `/compile` | Compile Mode - کامپایل |
|
|
72
|
+
| `/preview` | پیشنمایش سایت |
|
|
73
|
+
| `/help` | راهنما |
|
|
74
|
+
| `/quit` | خروج |
|
|
75
|
+
|
|
76
|
+
## 🔌 API Providers
|
|
77
|
+
|
|
78
|
+
| Provider | مدلها | قیمت |
|
|
79
|
+
|----------|--------|------|
|
|
80
|
+
| OpenCode Zen | mimo-v2.5-free | رایگان |
|
|
81
|
+
| OpenAI | GPT-4, GPT-3.5 | پولی |
|
|
82
|
+
| Anthropic | Claude 3.5 | پولی |
|
|
83
|
+
|
|
84
|
+
## 📄 مستندات
|
|
85
|
+
|
|
86
|
+
- [تحلیل پروژه](docs/01-analysis.md)
|
|
87
|
+
- [مینی پروپوزال](docs/02-proposal.md)
|
|
88
|
+
|
|
89
|
+
## 📝 لایسنس
|
|
90
|
+
|
|
91
|
+
MIT License
|
|
92
|
+
|
|
93
|
+
---
|
|
94
|
+
|
|
95
|
+
*ساخته شده توسط Ali Azimi*
|
|
96
|
+
*بر اساس کتاب Systems Analysis and Design - Dennis*
|
|
@@ -0,0 +1,84 @@
|
|
|
1
|
+
# 🔧 Lazarus
|
|
2
|
+
## AI-Driven Content Management System with Markdown
|
|
3
|
+
|
|
4
|
+
Lazarus یک CMS هوشمند است که با استفاده از API هوش مصنوعی و فایلهای Markdown، ساخت وبسایت را آسان میکند.
|
|
5
|
+
|
|
6
|
+
## ✨ ویژگیها
|
|
7
|
+
|
|
8
|
+
- 🔑 **اتصال API شخصی** - مثل Hermes، API Key خود را وارد کنید
|
|
9
|
+
- 💬 **Chat Mode** - چت با AI برای ساخت سایت
|
|
10
|
+
- 📝 **Code Mode** - ویرایش مستقیم فایلهای MD
|
|
11
|
+
- 🔨 **Compile Mode** - کامپایل MD به HTML
|
|
12
|
+
- 🎨 **سیستم تم** - تمهای آماده و قابل تنظیم
|
|
13
|
+
- 🔒 **امنیت** - رمزنگاری API Key
|
|
14
|
+
- 📈 **SEO** - بهینهسازی خودکار
|
|
15
|
+
- ⏰ **Cron Job** - زمانبندی وظایف
|
|
16
|
+
|
|
17
|
+
## 🚀 شروع سریع
|
|
18
|
+
|
|
19
|
+
```bash
|
|
20
|
+
# کلون کردن
|
|
21
|
+
git clone https://github.com/areniti/lazarus.git
|
|
22
|
+
cd lazarus
|
|
23
|
+
|
|
24
|
+
# نصب وابستگیها
|
|
25
|
+
pip install requests pyyaml
|
|
26
|
+
|
|
27
|
+
# اجرا
|
|
28
|
+
python3 src/engine.py
|
|
29
|
+
```
|
|
30
|
+
|
|
31
|
+
## 📁 ساختار پروژه
|
|
32
|
+
|
|
33
|
+
```
|
|
34
|
+
lazarus/
|
|
35
|
+
├── lazarus-config.yaml # تنظیمات API
|
|
36
|
+
├── src/
|
|
37
|
+
│ ├── engine.py # موتور اصلی
|
|
38
|
+
│ ├── api_manager.py # مدیریت API
|
|
39
|
+
│ ├── chat_mode.py # حالت چت
|
|
40
|
+
│ ├── code_mode.py # حالت کد
|
|
41
|
+
│ ├── compiler.py # کامپایلر
|
|
42
|
+
│ ├── theme.py # سیستم تم
|
|
43
|
+
│ ├── security.py # امنیت
|
|
44
|
+
│ ├── seo.py # SEO
|
|
45
|
+
│ ├── media.py # رسانه
|
|
46
|
+
│ └── cron.py # زمانبندی
|
|
47
|
+
├── site/ # فایلهای MD
|
|
48
|
+
├── output/ # خروجی HTML
|
|
49
|
+
└── docs/ # مستندات
|
|
50
|
+
```
|
|
51
|
+
|
|
52
|
+
## 📋 دستورات
|
|
53
|
+
|
|
54
|
+
| دستور | توضیح |
|
|
55
|
+
|-------|-------|
|
|
56
|
+
| `/start` | شروع - تنظیم API |
|
|
57
|
+
| `/chat` | Chat Mode - چت با AI |
|
|
58
|
+
| `/code` | Code Mode - ویرایش MD |
|
|
59
|
+
| `/compile` | Compile Mode - کامپایل |
|
|
60
|
+
| `/preview` | پیشنمایش سایت |
|
|
61
|
+
| `/help` | راهنما |
|
|
62
|
+
| `/quit` | خروج |
|
|
63
|
+
|
|
64
|
+
## 🔌 API Providers
|
|
65
|
+
|
|
66
|
+
| Provider | مدلها | قیمت |
|
|
67
|
+
|----------|--------|------|
|
|
68
|
+
| OpenCode Zen | mimo-v2.5-free | رایگان |
|
|
69
|
+
| OpenAI | GPT-4, GPT-3.5 | پولی |
|
|
70
|
+
| Anthropic | Claude 3.5 | پولی |
|
|
71
|
+
|
|
72
|
+
## 📄 مستندات
|
|
73
|
+
|
|
74
|
+
- [تحلیل پروژه](docs/01-analysis.md)
|
|
75
|
+
- [مینی پروپوزال](docs/02-proposal.md)
|
|
76
|
+
|
|
77
|
+
## 📝 لایسنس
|
|
78
|
+
|
|
79
|
+
MIT License
|
|
80
|
+
|
|
81
|
+
---
|
|
82
|
+
|
|
83
|
+
*ساخته شده توسط Ali Azimi*
|
|
84
|
+
*بر اساس کتاب Systems Analysis and Design - Dennis*
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
[build-system]
|
|
2
|
+
requires = ["setuptools>=61.0", "wheel"]
|
|
3
|
+
build-backend = "setuptools.build_meta"
|
|
4
|
+
|
|
5
|
+
[project]
|
|
6
|
+
name = "lazarus-cms"
|
|
7
|
+
version = "1.0.0"
|
|
8
|
+
description = "AI-Powered Content Management System with Markdown"
|
|
9
|
+
readme = "README.md"
|
|
10
|
+
license = "MIT"
|
|
11
|
+
authors = [
|
|
12
|
+
{name = "Ali Azimi"}
|
|
13
|
+
]
|
|
14
|
+
requires-python = ">=3.8"
|
|
15
|
+
keywords = ["cms", "ai", "markdown", "website-builder"]
|
|
16
|
+
|
|
17
|
+
[project.scripts]
|
|
18
|
+
lazarus = "lazarus.engine:main"
|
|
19
|
+
|
|
20
|
+
[tool.setuptools.packages.find]
|
|
21
|
+
where = ["src"]
|
|
@@ -0,0 +1,365 @@
|
|
|
1
|
+
#!/usr/bin/env python3
|
|
2
|
+
"""
|
|
3
|
+
Lazarus API Manager
|
|
4
|
+
Handles API provider selection, key management, and connections.
|
|
5
|
+
Like Hermes - user must provide their own API key.
|
|
6
|
+
"""
|
|
7
|
+
|
|
8
|
+
import os
|
|
9
|
+
import json
|
|
10
|
+
import hashlib
|
|
11
|
+
import base64
|
|
12
|
+
from pathlib import Path
|
|
13
|
+
|
|
14
|
+
# ─── Supported Providers ────────────────────────────────────────────
|
|
15
|
+
PROVIDERS = {
|
|
16
|
+
"openai": {
|
|
17
|
+
"name": "OpenAI",
|
|
18
|
+
"models": ["gpt-4", "gpt-4o", "gpt-4o-mini", "gpt-3.5-turbo"],
|
|
19
|
+
"base_url": "https://api.openai.com/v1",
|
|
20
|
+
"description": "محبوبترین ارائهدهنده AI"
|
|
21
|
+
},
|
|
22
|
+
"anthropic": {
|
|
23
|
+
"name": "Anthropic (Claude)",
|
|
24
|
+
"models": ["claude-3-5-sonnet-20241022", "claude-3-haiku-20240307", "claude-3-opus-20240229"],
|
|
25
|
+
"base_url": "https://api.anthropic.com/v1",
|
|
26
|
+
"description": "Claude - هوش مصنوعی پیشرفته"
|
|
27
|
+
},
|
|
28
|
+
"openrouter": {
|
|
29
|
+
"name": "OpenRouter",
|
|
30
|
+
"models": ["openai/gpt-4", "anthropic/claude-3.5-sonnet", "meta-llama/llama-3-70b"],
|
|
31
|
+
"base_url": "https://openrouter.ai/api/v1",
|
|
32
|
+
"description": "دسترسی به مدلهای مختلف"
|
|
33
|
+
},
|
|
34
|
+
"groq": {
|
|
35
|
+
"name": "Groq",
|
|
36
|
+
"models": ["llama3-70b-8192", "mixtral-8x7b-32768", "gemma-7b-it"],
|
|
37
|
+
"base_url": "https://api.groq.com/openai/v1",
|
|
38
|
+
"description": "سریعترین اجرای AI"
|
|
39
|
+
},
|
|
40
|
+
"custom": {
|
|
41
|
+
"name": "سفارشی (Custom)",
|
|
42
|
+
"models": [],
|
|
43
|
+
"base_url": "",
|
|
44
|
+
"description": "هر API سازگار با OpenAI"
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
|
|
49
|
+
class APIManager:
|
|
50
|
+
"""Manages API connections like Hermes does."""
|
|
51
|
+
|
|
52
|
+
def __init__(self, config_path="lazarus-config.yaml"):
|
|
53
|
+
self.config_path = Path(config_path)
|
|
54
|
+
self.config = self._load_config()
|
|
55
|
+
|
|
56
|
+
def _load_config(self):
|
|
57
|
+
"""Load configuration from YAML file."""
|
|
58
|
+
if self.config_path.exists():
|
|
59
|
+
try:
|
|
60
|
+
import yaml
|
|
61
|
+
with open(self.config_path, 'r') as f:
|
|
62
|
+
return yaml.safe_load(f) or {}
|
|
63
|
+
except ImportError:
|
|
64
|
+
# Fallback: read as simple text
|
|
65
|
+
return self._load_config_simple()
|
|
66
|
+
return {"api": {}}
|
|
67
|
+
|
|
68
|
+
def _load_config_simple(self):
|
|
69
|
+
"""Simple config loader without YAML dependency."""
|
|
70
|
+
config = {"api": {}}
|
|
71
|
+
if self.config_path.exists():
|
|
72
|
+
with open(self.config_path, 'r') as f:
|
|
73
|
+
for line in f:
|
|
74
|
+
line = line.strip()
|
|
75
|
+
if ':' in line and not line.startswith('#'):
|
|
76
|
+
key, value = line.split(':', 1)
|
|
77
|
+
key = key.strip()
|
|
78
|
+
value = value.strip().strip('"').strip("'")
|
|
79
|
+
if key in ['provider', 'model', 'api_key', 'base_url']:
|
|
80
|
+
config["api"][key] = value
|
|
81
|
+
return config
|
|
82
|
+
|
|
83
|
+
def list_providers(self):
|
|
84
|
+
"""List all available API providers."""
|
|
85
|
+
print("\n🔌 ارائهدهندگان API موجود:\n")
|
|
86
|
+
print("─" * 50)
|
|
87
|
+
|
|
88
|
+
providers_list = list(PROVIDERS.keys())
|
|
89
|
+
for i, provider_id in enumerate(providers_list, 1):
|
|
90
|
+
provider = PROVIDERS[provider_id]
|
|
91
|
+
print(f" {i}. {provider['name']}")
|
|
92
|
+
print(f" {provider['description']}")
|
|
93
|
+
if provider['models']:
|
|
94
|
+
print(f" مدلها: {', '.join(provider['models'][:3])}...")
|
|
95
|
+
print()
|
|
96
|
+
|
|
97
|
+
print("─" * 50)
|
|
98
|
+
return providers_list
|
|
99
|
+
|
|
100
|
+
def select_provider(self, choice=None):
|
|
101
|
+
"""Select an API provider."""
|
|
102
|
+
providers_list = self.list_providers()
|
|
103
|
+
|
|
104
|
+
if choice is None:
|
|
105
|
+
while True:
|
|
106
|
+
try:
|
|
107
|
+
choice = int(input("🔢 شماره ارائهدهنده را وارد کنید: "))
|
|
108
|
+
if 1 <= choice <= len(providers_list):
|
|
109
|
+
break
|
|
110
|
+
print("❌ شماره نامعتبر!")
|
|
111
|
+
except ValueError:
|
|
112
|
+
print("❌ لطفاً یک عدد وارد کنید!")
|
|
113
|
+
|
|
114
|
+
provider_id = providers_list[choice - 1]
|
|
115
|
+
provider = PROVIDERS[provider_id]
|
|
116
|
+
|
|
117
|
+
print(f"\n✅ ارائهدهنده انتخاب شد: {provider['name']}")
|
|
118
|
+
|
|
119
|
+
# Update config
|
|
120
|
+
if "api" not in self.config:
|
|
121
|
+
self.config["api"] = {}
|
|
122
|
+
self.config["api"]["provider"] = provider_id
|
|
123
|
+
self.config["api"]["base_url"] = provider["base_url"]
|
|
124
|
+
|
|
125
|
+
return provider_id, provider
|
|
126
|
+
|
|
127
|
+
def select_model(self, provider_id, model=None):
|
|
128
|
+
"""Select a model from the provider."""
|
|
129
|
+
provider = PROVIDERS.get(provider_id, {})
|
|
130
|
+
models = provider.get("models", [])
|
|
131
|
+
|
|
132
|
+
if not models:
|
|
133
|
+
print("\n📝 مدل را وارد کنید:")
|
|
134
|
+
model = input(" مدل: ")
|
|
135
|
+
self.config["api"]["model"] = model
|
|
136
|
+
return model
|
|
137
|
+
|
|
138
|
+
print(f"\n📋 مدلهای موجود ({provider['name']}):\n")
|
|
139
|
+
for i, m in enumerate(models, 1):
|
|
140
|
+
print(f" {i}. {m}")
|
|
141
|
+
|
|
142
|
+
if model is None:
|
|
143
|
+
while True:
|
|
144
|
+
try:
|
|
145
|
+
choice = int(input("\n🔢 شماره مدل را وارد کنید: "))
|
|
146
|
+
if 1 <= choice <= len(models):
|
|
147
|
+
model = models[choice - 1]
|
|
148
|
+
break
|
|
149
|
+
print("❌ شماره نامعتبر!")
|
|
150
|
+
except ValueError:
|
|
151
|
+
print("❌ لطفاً یک عدد وارد کنید!")
|
|
152
|
+
|
|
153
|
+
print(f"\n✅ مدل انتخاب شد: {model}")
|
|
154
|
+
self.config["api"]["model"] = model
|
|
155
|
+
return model
|
|
156
|
+
|
|
157
|
+
def enter_api_key(self, api_key=None):
|
|
158
|
+
"""Enter and encrypt API key."""
|
|
159
|
+
if api_key is None:
|
|
160
|
+
print("\n🔑 API Key خود را وارد کنید:")
|
|
161
|
+
print(" (از سایت ارائهدهنده دریافت کنید)")
|
|
162
|
+
api_key = input(" API Key: ").strip()
|
|
163
|
+
|
|
164
|
+
if not api_key:
|
|
165
|
+
print("❌ API Key نمیتواند خالی باشد!")
|
|
166
|
+
return None
|
|
167
|
+
|
|
168
|
+
# Encrypt the key
|
|
169
|
+
encrypted = self._encrypt_key(api_key)
|
|
170
|
+
|
|
171
|
+
# Save to config
|
|
172
|
+
self.config["api"]["api_key"] = encrypted
|
|
173
|
+
self.config["api"]["api_key_plain"] = api_key # For testing
|
|
174
|
+
|
|
175
|
+
print(f"\n✅ API Key ذخیره و رمزنگاری شد!")
|
|
176
|
+
print(f" طول: {len(api_key)} کاراکتر")
|
|
177
|
+
|
|
178
|
+
return api_key
|
|
179
|
+
|
|
180
|
+
def _encrypt_key(self, key):
|
|
181
|
+
"""Simple encryption for API key."""
|
|
182
|
+
# In production, use proper encryption (AES-256)
|
|
183
|
+
# This is a simple obfuscation for demo
|
|
184
|
+
encoded = base64.b64encode(key.encode()).decode()
|
|
185
|
+
return f"enc:{encoded}"
|
|
186
|
+
|
|
187
|
+
def _decrypt_key(self, encrypted_key):
|
|
188
|
+
"""Decrypt API key."""
|
|
189
|
+
if encrypted_key.startswith("enc:"):
|
|
190
|
+
encoded = encrypted_key[4:]
|
|
191
|
+
return base64.b64decode(encoded.encode()).decode()
|
|
192
|
+
return encrypted_key
|
|
193
|
+
|
|
194
|
+
def test_connection(self, provider_id=None, api_key=None):
|
|
195
|
+
"""Test API connection."""
|
|
196
|
+
if provider_id is None:
|
|
197
|
+
provider_id = self.config.get("api", {}).get("provider", "")
|
|
198
|
+
|
|
199
|
+
if api_key is None:
|
|
200
|
+
encrypted_key = self.config.get("api", {}).get("api_key", "")
|
|
201
|
+
api_key = self._decrypt_key(encrypted_key)
|
|
202
|
+
|
|
203
|
+
if not provider_id or not api_key:
|
|
204
|
+
print("❌ ابتدا ارائهدهنده و API Key را تنظیم کنید!")
|
|
205
|
+
return False
|
|
206
|
+
|
|
207
|
+
provider = PROVIDERS.get(provider_id, {})
|
|
208
|
+
base_url = provider.get("base_url", "")
|
|
209
|
+
|
|
210
|
+
if not base_url:
|
|
211
|
+
print("❌ URL ارائهدهنده نامعتبر است!")
|
|
212
|
+
return False
|
|
213
|
+
|
|
214
|
+
print(f"\n🔄 در حال تست اتصال به {provider['name']}...")
|
|
215
|
+
|
|
216
|
+
try:
|
|
217
|
+
import requests
|
|
218
|
+
|
|
219
|
+
# Different test for each provider
|
|
220
|
+
if provider_id == "anthropic":
|
|
221
|
+
headers = {
|
|
222
|
+
"x-api-key": api_key,
|
|
223
|
+
"anthropic-version": "2023-06-01",
|
|
224
|
+
"content-type": "application/json"
|
|
225
|
+
}
|
|
226
|
+
response = requests.post(
|
|
227
|
+
f"{base_url}/messages",
|
|
228
|
+
headers=headers,
|
|
229
|
+
json={
|
|
230
|
+
"model": "claude-3-haiku-20240307",
|
|
231
|
+
"max_tokens": 10,
|
|
232
|
+
"messages": [{"role": "user", "content": "Hi"}]
|
|
233
|
+
},
|
|
234
|
+
timeout=10
|
|
235
|
+
)
|
|
236
|
+
else:
|
|
237
|
+
# OpenAI-compatible API
|
|
238
|
+
headers = {
|
|
239
|
+
"Authorization": f"Bearer {api_key}",
|
|
240
|
+
"Content-Type": "application/json"
|
|
241
|
+
}
|
|
242
|
+
response = requests.get(
|
|
243
|
+
f"{base_url}/models",
|
|
244
|
+
headers=headers,
|
|
245
|
+
timeout=10
|
|
246
|
+
)
|
|
247
|
+
|
|
248
|
+
if response.status_code == 200:
|
|
249
|
+
print(f"✅ اتصال موفق! (Status: {response.status_code})")
|
|
250
|
+
return True
|
|
251
|
+
else:
|
|
252
|
+
print(f"❌ خطا در اتصال! (Status: {response.status_code})")
|
|
253
|
+
print(f" پیام: {response.text[:200]}")
|
|
254
|
+
return False
|
|
255
|
+
|
|
256
|
+
except ImportError:
|
|
257
|
+
print("⚠️ کتابخانه requests نصب نیست!")
|
|
258
|
+
print(" اجرا کنید: pip install requests")
|
|
259
|
+
return False
|
|
260
|
+
except Exception as e:
|
|
261
|
+
print(f"❌ خطا: {e}")
|
|
262
|
+
return False
|
|
263
|
+
|
|
264
|
+
def save_config(self):
|
|
265
|
+
"""Save configuration to file."""
|
|
266
|
+
try:
|
|
267
|
+
import yaml
|
|
268
|
+
with open(self.config_path, 'w') as f:
|
|
269
|
+
yaml.dump(self.config, f, default_flow_style=False)
|
|
270
|
+
except ImportError:
|
|
271
|
+
# Simple save without YAML
|
|
272
|
+
with open(self.config_path, 'w') as f:
|
|
273
|
+
f.write("# Lazarus Configuration\n\n")
|
|
274
|
+
for section, values in self.config.items():
|
|
275
|
+
f.write(f"{section}:\n")
|
|
276
|
+
if isinstance(values, dict):
|
|
277
|
+
for key, value in values.items():
|
|
278
|
+
f.write(f" {key}: {value}\n")
|
|
279
|
+
f.write("\n")
|
|
280
|
+
|
|
281
|
+
print(f"\n💾 تنظیمات ذخیره شد: {self.config_path}")
|
|
282
|
+
|
|
283
|
+
def show_current_config(self):
|
|
284
|
+
"""Show current API configuration."""
|
|
285
|
+
api_config = self.config.get("api", {})
|
|
286
|
+
provider_id = api_config.get("provider", "")
|
|
287
|
+
model = api_config.get("model", "")
|
|
288
|
+
has_key = bool(api_config.get("api_key", ""))
|
|
289
|
+
|
|
290
|
+
provider = PROVIDERS.get(provider_id, {})
|
|
291
|
+
|
|
292
|
+
print("\n📋 تنظیمات فعلی API:")
|
|
293
|
+
print("─" * 40)
|
|
294
|
+
print(f" ارائهدهنده: {provider.get('name', 'تنظیم نشده')}")
|
|
295
|
+
print(f" مدل: {model or 'تنظیم نشده'}")
|
|
296
|
+
print(f" API Key: {'✅ تنظیم شده' if has_key else '❌ تنظیم نشده'}")
|
|
297
|
+
print("─" * 40)
|
|
298
|
+
|
|
299
|
+
def full_setup(self):
|
|
300
|
+
"""Complete API setup wizard."""
|
|
301
|
+
print("\n" + "=" * 50)
|
|
302
|
+
print("🔧 راهاندازی API - Lazarus")
|
|
303
|
+
print("=" * 50)
|
|
304
|
+
|
|
305
|
+
# Step 1: Select provider
|
|
306
|
+
provider_id, provider = self.select_provider()
|
|
307
|
+
|
|
308
|
+
# Step 2: Select model
|
|
309
|
+
model = self.select_model(provider_id)
|
|
310
|
+
|
|
311
|
+
# Step 3: Enter API key
|
|
312
|
+
api_key = self.enter_api_key()
|
|
313
|
+
|
|
314
|
+
if not api_key:
|
|
315
|
+
print("❌ راهاندازی ناموفق!")
|
|
316
|
+
return False
|
|
317
|
+
|
|
318
|
+
# Step 4: Test connection
|
|
319
|
+
print("\n🔄 تست اتصال...")
|
|
320
|
+
if self.test_connection(provider_id, api_key):
|
|
321
|
+
# Step 5: Save config
|
|
322
|
+
self.save_config()
|
|
323
|
+
|
|
324
|
+
print("\n" + "=" * 50)
|
|
325
|
+
print("✅ راهاندازی API با موفقیت انجام شد!")
|
|
326
|
+
print("=" * 50)
|
|
327
|
+
self.show_current_config()
|
|
328
|
+
return True
|
|
329
|
+
else:
|
|
330
|
+
print("\n❌ اتصال برقرار نشد!")
|
|
331
|
+
print(" لطفاً API Key را بررسی کنید.")
|
|
332
|
+
return False
|
|
333
|
+
|
|
334
|
+
|
|
335
|
+
def main():
|
|
336
|
+
"""Main function for testing."""
|
|
337
|
+
manager = APIManager()
|
|
338
|
+
|
|
339
|
+
print("\n🔧 Lazarus API Manager")
|
|
340
|
+
print("=" * 50)
|
|
341
|
+
|
|
342
|
+
while True:
|
|
343
|
+
print("\n📋 منو:")
|
|
344
|
+
print(" ۱. راهاندازی کامل API")
|
|
345
|
+
print(" ۲. نمایش تنظیمات فعلی")
|
|
346
|
+
print(" ۳. تست اتصال")
|
|
347
|
+
print(" ۰. خروج")
|
|
348
|
+
|
|
349
|
+
choice = input("\n🔢 انتخاب: ").strip()
|
|
350
|
+
|
|
351
|
+
if choice == "1":
|
|
352
|
+
manager.full_setup()
|
|
353
|
+
elif choice == "2":
|
|
354
|
+
manager.show_current_config()
|
|
355
|
+
elif choice == "3":
|
|
356
|
+
manager.test_connection()
|
|
357
|
+
elif choice == "0":
|
|
358
|
+
print("\n👋 خداحافظ!")
|
|
359
|
+
break
|
|
360
|
+
else:
|
|
361
|
+
print("❌ انتخاب نامعتبر!")
|
|
362
|
+
|
|
363
|
+
|
|
364
|
+
if __name__ == "__main__":
|
|
365
|
+
main()
|