airgptx 0.1.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.
- airgptx-0.1.0/PKG-INFO +58 -0
- airgptx-0.1.0/README.md +46 -0
- airgptx-0.1.0/airgptx/__init__.py +8 -0
- airgptx-0.1.0/airgptx/agent.py +80 -0
- airgptx-0.1.0/airgptx/airsim/__init__.py +5 -0
- airgptx-0.1.0/airgptx/airsim/client.py +1658 -0
- airgptx-0.1.0/airgptx/airsim/pfm.py +85 -0
- airgptx-0.1.0/airgptx/airsim/types.py +592 -0
- airgptx-0.1.0/airgptx/airsim/utils.py +208 -0
- airgptx-0.1.0/airgptx/llm.py +90 -0
- airgptx-0.1.0/airgptx/prompts/airsim_basic_cn.txt +63 -0
- airgptx-0.1.0/airgptx/system_prompts/airsim_basic_cn.txt +5 -0
- airgptx-0.1.0/airgptx.egg-info/PKG-INFO +58 -0
- airgptx-0.1.0/airgptx.egg-info/SOURCES.txt +17 -0
- airgptx-0.1.0/airgptx.egg-info/dependency_links.txt +1 -0
- airgptx-0.1.0/airgptx.egg-info/requires.txt +5 -0
- airgptx-0.1.0/airgptx.egg-info/top_level.txt +1 -0
- airgptx-0.1.0/pyproject.toml +23 -0
- airgptx-0.1.0/setup.cfg +4 -0
airgptx-0.1.0/PKG-INFO
ADDED
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: airgptx
|
|
3
|
+
Version: 0.1.0
|
|
4
|
+
Summary: AirGPTX Python package with the bundled AirSim client APIs.
|
|
5
|
+
Requires-Python: >=3.8
|
|
6
|
+
Description-Content-Type: text/markdown
|
|
7
|
+
Requires-Dist: backports.ssl-match-hostname
|
|
8
|
+
Requires-Dist: msgpack-rpc-python
|
|
9
|
+
Requires-Dist: numpy
|
|
10
|
+
Requires-Dist: openai
|
|
11
|
+
Requires-Dist: opencv-contrib-python
|
|
12
|
+
|
|
13
|
+
# AirGPTX
|
|
14
|
+
|
|
15
|
+
AirGPTX packages the AirSim Python client and an OpenAI-compatible SDK for calling online LLMs through the AirGPTX relay service.
|
|
16
|
+
|
|
17
|
+
## Install
|
|
18
|
+
|
|
19
|
+
```bash
|
|
20
|
+
pip install airgptx
|
|
21
|
+
```
|
|
22
|
+
|
|
23
|
+
## AirSim API
|
|
24
|
+
|
|
25
|
+
```python
|
|
26
|
+
import airgptx.airsim as airsim
|
|
27
|
+
|
|
28
|
+
client = airsim.MultirotorClient()
|
|
29
|
+
client.confirmConnection()
|
|
30
|
+
```
|
|
31
|
+
|
|
32
|
+
## LLM relay SDK
|
|
33
|
+
|
|
34
|
+
```python
|
|
35
|
+
from airgptx import AirGPTX
|
|
36
|
+
|
|
37
|
+
sdk = AirGPTX(api_key="YOUR_AIRGPTX_API_KEY")
|
|
38
|
+
answer = sdk.ask("Say hello")
|
|
39
|
+
print(answer)
|
|
40
|
+
```
|
|
41
|
+
|
|
42
|
+
You can also configure the SDK with environment variables:
|
|
43
|
+
|
|
44
|
+
```bash
|
|
45
|
+
export AIRGPTX_API_KEY="YOUR_AIRGPTX_API_KEY"
|
|
46
|
+
export AIRGPTX_BASE_URL="https://api.airgptx.com/v1"
|
|
47
|
+
export AIRGPTX_MODEL="airgptx-default"
|
|
48
|
+
```
|
|
49
|
+
|
|
50
|
+
## AirSim agent
|
|
51
|
+
|
|
52
|
+
```python
|
|
53
|
+
from airgptx import AirSimAgent
|
|
54
|
+
|
|
55
|
+
agent = AirSimAgent(api_key="YOUR_AIRGPTX_API_KEY")
|
|
56
|
+
python_code = agent.process("起飞")
|
|
57
|
+
print(python_code)
|
|
58
|
+
```
|
airgptx-0.1.0/README.md
ADDED
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
# AirGPTX
|
|
2
|
+
|
|
3
|
+
AirGPTX packages the AirSim Python client and an OpenAI-compatible SDK for calling online LLMs through the AirGPTX relay service.
|
|
4
|
+
|
|
5
|
+
## Install
|
|
6
|
+
|
|
7
|
+
```bash
|
|
8
|
+
pip install airgptx
|
|
9
|
+
```
|
|
10
|
+
|
|
11
|
+
## AirSim API
|
|
12
|
+
|
|
13
|
+
```python
|
|
14
|
+
import airgptx.airsim as airsim
|
|
15
|
+
|
|
16
|
+
client = airsim.MultirotorClient()
|
|
17
|
+
client.confirmConnection()
|
|
18
|
+
```
|
|
19
|
+
|
|
20
|
+
## LLM relay SDK
|
|
21
|
+
|
|
22
|
+
```python
|
|
23
|
+
from airgptx import AirGPTX
|
|
24
|
+
|
|
25
|
+
sdk = AirGPTX(api_key="YOUR_AIRGPTX_API_KEY")
|
|
26
|
+
answer = sdk.ask("Say hello")
|
|
27
|
+
print(answer)
|
|
28
|
+
```
|
|
29
|
+
|
|
30
|
+
You can also configure the SDK with environment variables:
|
|
31
|
+
|
|
32
|
+
```bash
|
|
33
|
+
export AIRGPTX_API_KEY="YOUR_AIRGPTX_API_KEY"
|
|
34
|
+
export AIRGPTX_BASE_URL="https://api.airgptx.com/v1"
|
|
35
|
+
export AIRGPTX_MODEL="airgptx-default"
|
|
36
|
+
```
|
|
37
|
+
|
|
38
|
+
## AirSim agent
|
|
39
|
+
|
|
40
|
+
```python
|
|
41
|
+
from airgptx import AirSimAgent
|
|
42
|
+
|
|
43
|
+
agent = AirSimAgent(api_key="YOUR_AIRGPTX_API_KEY")
|
|
44
|
+
python_code = agent.process("起飞")
|
|
45
|
+
print(python_code)
|
|
46
|
+
```
|
|
@@ -0,0 +1,80 @@
|
|
|
1
|
+
"""LLM-powered AirSim agent built on the AirGPTX relay client."""
|
|
2
|
+
|
|
3
|
+
from __future__ import annotations
|
|
4
|
+
|
|
5
|
+
import re
|
|
6
|
+
from importlib import resources
|
|
7
|
+
from pathlib import Path
|
|
8
|
+
from typing import Any, Iterable, Mapping
|
|
9
|
+
|
|
10
|
+
from .llm import AirGPTX
|
|
11
|
+
|
|
12
|
+
|
|
13
|
+
def _read_text(path_or_resource: str | Path, resource_dir: str) -> str:
|
|
14
|
+
path = Path(path_or_resource)
|
|
15
|
+
if path.exists():
|
|
16
|
+
return path.read_text(encoding="utf8")
|
|
17
|
+
|
|
18
|
+
return (
|
|
19
|
+
resources.files("airgptx")
|
|
20
|
+
.joinpath(resource_dir, str(path_or_resource))
|
|
21
|
+
.read_text(encoding="utf8")
|
|
22
|
+
)
|
|
23
|
+
|
|
24
|
+
|
|
25
|
+
class AirSimAgent:
|
|
26
|
+
"""Generate AirSim Python code from natural-language commands."""
|
|
27
|
+
|
|
28
|
+
def __init__(
|
|
29
|
+
self,
|
|
30
|
+
sdk: AirGPTX | None = None,
|
|
31
|
+
api_key: str | None = None,
|
|
32
|
+
base_url: str | None = None,
|
|
33
|
+
model: str | None = None,
|
|
34
|
+
system_prompt: str | Path = "airsim_basic_cn.txt",
|
|
35
|
+
knowledge_prompt: str | Path = "airsim_basic_cn.txt",
|
|
36
|
+
chat_history: Iterable[Mapping[str, Any]] | None = None,
|
|
37
|
+
temperature: float = 0.1,
|
|
38
|
+
) -> None:
|
|
39
|
+
self.sdk = sdk or AirGPTX(api_key=api_key, base_url=base_url, model=model)
|
|
40
|
+
self.temperature = temperature
|
|
41
|
+
self.chat_history: list[dict[str, Any]] = []
|
|
42
|
+
|
|
43
|
+
system_text = _read_text(system_prompt, "system_prompts")
|
|
44
|
+
self.chat_history.append({"role": "system", "content": system_text})
|
|
45
|
+
|
|
46
|
+
if chat_history:
|
|
47
|
+
self.chat_history.extend(dict(message) for message in chat_history)
|
|
48
|
+
|
|
49
|
+
knowledge_text = _read_text(knowledge_prompt, "prompts")
|
|
50
|
+
self.ask(knowledge_text)
|
|
51
|
+
|
|
52
|
+
def ask(self, prompt: str, **kwargs: Any) -> str:
|
|
53
|
+
"""Ask the relay model while preserving conversation history."""
|
|
54
|
+
|
|
55
|
+
self.chat_history.append({"role": "user", "content": prompt})
|
|
56
|
+
completion = self.sdk.chat(
|
|
57
|
+
messages=self.chat_history,
|
|
58
|
+
temperature=self.temperature,
|
|
59
|
+
**kwargs,
|
|
60
|
+
)
|
|
61
|
+
content = completion.choices[0].message.content
|
|
62
|
+
self.chat_history.append({"role": "assistant", "content": content})
|
|
63
|
+
return content
|
|
64
|
+
|
|
65
|
+
def extract_python_code(self, content: str) -> str | None:
|
|
66
|
+
"""Extract fenced Python code from a model response."""
|
|
67
|
+
|
|
68
|
+
code_blocks = re.findall(r"```(?:python)?\s*(.*?)```", content, re.DOTALL | re.IGNORECASE)
|
|
69
|
+
if not code_blocks:
|
|
70
|
+
return None
|
|
71
|
+
return "\n".join(block.strip() for block in code_blocks if block.strip()) or None
|
|
72
|
+
|
|
73
|
+
def process(self, command: str, run_python_code: bool = False, exec_globals: dict[str, Any] | None = None) -> str | None:
|
|
74
|
+
"""Generate code for an AirSim command, optionally executing it."""
|
|
75
|
+
|
|
76
|
+
response = self.ask(command)
|
|
77
|
+
python_code = self.extract_python_code(response)
|
|
78
|
+
if run_python_code and python_code:
|
|
79
|
+
exec(python_code, exec_globals if exec_globals is not None else {})
|
|
80
|
+
return python_code
|