astra-repl 0.1__py3-none-any.whl
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.
- ai/__init__.py +0 -0
- ai/client.py +87 -0
- ai/commands.py +1666 -0
- ai/models.py +32 -0
- astra_repl-0.1.dist-info/METADATA +827 -0
- astra_repl-0.1.dist-info/RECORD +26 -0
- astra_repl-0.1.dist-info/WHEEL +5 -0
- astra_repl-0.1.dist-info/entry_points.txt +2 -0
- astra_repl-0.1.dist-info/licenses/LICENSE.txt +21 -0
- astra_repl-0.1.dist-info/top_level.txt +5 -0
- config.py +87 -0
- core/__init__.py +1 -0
- core/banner.py +88 -0
- core/command_router.py +310 -0
- core/config.py +55 -0
- core/repl.py +1707 -0
- core/shell.py +260 -0
- core/themes.py +5 -0
- main.py +16 -0
- plugins/__init__.py +18 -0
- plugins/api.py +8 -0
- plugins/calc.py +11 -0
- plugins/chat.py +15 -0
- plugins/hello.py +11 -0
- plugins/time.py +10 -0
- plugins/weather.py +1 -0
ai/__init__.py
ADDED
|
File without changes
|
ai/client.py
ADDED
|
@@ -0,0 +1,87 @@
|
|
|
1
|
+
#ai/client.py
|
|
2
|
+
|
|
3
|
+
import os
|
|
4
|
+
import requests
|
|
5
|
+
|
|
6
|
+
from dotenv import load_dotenv
|
|
7
|
+
from ai.models import get_model
|
|
8
|
+
|
|
9
|
+
load_dotenv()
|
|
10
|
+
|
|
11
|
+
API_KEY = os.getenv("OPENROUTER_API_KEY")
|
|
12
|
+
|
|
13
|
+
API_URL = "https://openrouter.ai/api/v1/chat/completions"
|
|
14
|
+
|
|
15
|
+
LAST_RESPONSE = ""
|
|
16
|
+
|
|
17
|
+
def ask(prompt):
|
|
18
|
+
|
|
19
|
+
global LAST_RESPONSE
|
|
20
|
+
|
|
21
|
+
if not API_KEY:
|
|
22
|
+
return "OPENROUTER_API_KEY topilmadi."
|
|
23
|
+
|
|
24
|
+
try:
|
|
25
|
+
|
|
26
|
+
response = requests.post(
|
|
27
|
+
API_URL,
|
|
28
|
+
headers={
|
|
29
|
+
"Authorization": f"Bearer {API_KEY}",
|
|
30
|
+
"Content-Type": "application/json"
|
|
31
|
+
},
|
|
32
|
+
json={
|
|
33
|
+
"model": get_model(),
|
|
34
|
+
"messages": [
|
|
35
|
+
{
|
|
36
|
+
"role": "system",
|
|
37
|
+
"content": (
|
|
38
|
+
"You are Astra AI, a helpful programming assistant."
|
|
39
|
+
)
|
|
40
|
+
},
|
|
41
|
+
{
|
|
42
|
+
"role": "user",
|
|
43
|
+
"content": prompt
|
|
44
|
+
}
|
|
45
|
+
]
|
|
46
|
+
},
|
|
47
|
+
timeout=60
|
|
48
|
+
)
|
|
49
|
+
|
|
50
|
+
if response.status_code == 429:
|
|
51
|
+
return (
|
|
52
|
+
"OpenRouter limit reached.\n"
|
|
53
|
+
"Try again later or change model."
|
|
54
|
+
)
|
|
55
|
+
|
|
56
|
+
if response.status_code == 401:
|
|
57
|
+
return "Invalid API key."
|
|
58
|
+
|
|
59
|
+
response.raise_for_status()
|
|
60
|
+
|
|
61
|
+
data = response.json()
|
|
62
|
+
|
|
63
|
+
LAST_RESPONSE = ( data["choices"][0]["message"]["content"]
|
|
64
|
+
)
|
|
65
|
+
|
|
66
|
+
return LAST_RESPONSE
|
|
67
|
+
|
|
68
|
+
except requests.exceptions.Timeout:
|
|
69
|
+
return "Request timeout."
|
|
70
|
+
|
|
71
|
+
except requests.exceptions.ConnectionError:
|
|
72
|
+
return "Connection error."
|
|
73
|
+
|
|
74
|
+
except Exception as e:
|
|
75
|
+
return f"Error: {e}"
|
|
76
|
+
|
|
77
|
+
def get_last_response():
|
|
78
|
+
|
|
79
|
+
return LAST_RESPONSE
|
|
80
|
+
|
|
81
|
+
def get_ai_status():
|
|
82
|
+
|
|
83
|
+
return {
|
|
84
|
+
"provider": "OpenRouter",
|
|
85
|
+
"model": get_model(),
|
|
86
|
+
"api_key_loaded": bool(API_KEY)
|
|
87
|
+
}
|