wcgw 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.
Potentially problematic release.
This version of wcgw might be problematic. Click here for more details.
- wcgw-0.1.0/.github/workflows/python-publish.yml +40 -0
- wcgw-0.1.0/.gitignore +166 -0
- wcgw-0.1.0/.vscode/settings.json +16 -0
- wcgw-0.1.0/PKG-INFO +23 -0
- wcgw-0.1.0/README.md +1 -0
- wcgw-0.1.0/config.toml +11 -0
- wcgw-0.1.0/pyproject.toml +39 -0
- wcgw-0.1.0/src/relay/serve.py +101 -0
- wcgw-0.1.0/src/wcgw/__init__.py +2 -0
- wcgw-0.1.0/src/wcgw/__main__.py +3 -0
- wcgw-0.1.0/src/wcgw/basic.py +341 -0
- wcgw-0.1.0/src/wcgw/common.py +47 -0
- wcgw-0.1.0/src/wcgw/openai_adapters.py +0 -0
- wcgw-0.1.0/src/wcgw/openai_utils.py +68 -0
- wcgw-0.1.0/src/wcgw/tools.py +465 -0
- wcgw-0.1.0/uv.lock +808 -0
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
# This workflow will upload a Python Package using Twine when a release is created
|
|
2
|
+
# For more information see: https://docs.github.com/en/actions/automating-builds-and-tests/building-and-testing-python#publishing-to-package-registries
|
|
3
|
+
|
|
4
|
+
# This workflow uses actions that are not certified by GitHub.
|
|
5
|
+
# They are provided by a third-party and are governed by
|
|
6
|
+
# separate terms of service, privacy policy, and support
|
|
7
|
+
# documentation.
|
|
8
|
+
|
|
9
|
+
name: Upload Python Package
|
|
10
|
+
|
|
11
|
+
on:
|
|
12
|
+
release:
|
|
13
|
+
types: [published]
|
|
14
|
+
|
|
15
|
+
permissions:
|
|
16
|
+
contents: read
|
|
17
|
+
|
|
18
|
+
jobs:
|
|
19
|
+
deploy:
|
|
20
|
+
|
|
21
|
+
runs-on: ubuntu-latest
|
|
22
|
+
|
|
23
|
+
steps:
|
|
24
|
+
- uses: actions/checkout@v4
|
|
25
|
+
- name: Set up Python
|
|
26
|
+
uses: actions/setup-python@v3
|
|
27
|
+
with:
|
|
28
|
+
python-version: '3.x'
|
|
29
|
+
|
|
30
|
+
- name: Install dependencies
|
|
31
|
+
run: |
|
|
32
|
+
python -m pip install --upgrade pip
|
|
33
|
+
pip install build
|
|
34
|
+
- name: Build package
|
|
35
|
+
run: python -m build
|
|
36
|
+
- name: Publish package
|
|
37
|
+
uses: pypa/gh-action-pypi-publish@27b31702a0e7fc50959f5ad993c78deac1bdfc29
|
|
38
|
+
with:
|
|
39
|
+
user: __token__
|
|
40
|
+
password: ${{ secrets.PYPI_API_TOKEN }}
|
wcgw-0.1.0/.gitignore
ADDED
|
@@ -0,0 +1,166 @@
|
|
|
1
|
+
.venv
|
|
2
|
+
.env
|
|
3
|
+
.wcgw
|
|
4
|
+
|
|
5
|
+
# Byte-compiled / optimized / DLL files
|
|
6
|
+
__pycache__/
|
|
7
|
+
*.py[cod]
|
|
8
|
+
*$py.class
|
|
9
|
+
|
|
10
|
+
# C extensions
|
|
11
|
+
*.so
|
|
12
|
+
|
|
13
|
+
# Distribution / packaging
|
|
14
|
+
.Python
|
|
15
|
+
build/
|
|
16
|
+
develop-eggs/
|
|
17
|
+
dist/
|
|
18
|
+
downloads/
|
|
19
|
+
eggs/
|
|
20
|
+
.eggs/
|
|
21
|
+
lib/
|
|
22
|
+
lib64/
|
|
23
|
+
parts/
|
|
24
|
+
sdist/
|
|
25
|
+
var/
|
|
26
|
+
wheels/
|
|
27
|
+
share/python-wheels/
|
|
28
|
+
*.egg-info/
|
|
29
|
+
.installed.cfg
|
|
30
|
+
*.egg
|
|
31
|
+
MANIFEST
|
|
32
|
+
|
|
33
|
+
# PyInstaller
|
|
34
|
+
# Usually these files are written by a python script from a template
|
|
35
|
+
# before PyInstaller builds the exe, so as to inject date/other infos into it.
|
|
36
|
+
*.manifest
|
|
37
|
+
*.spec
|
|
38
|
+
|
|
39
|
+
# Installer logs
|
|
40
|
+
pip-log.txt
|
|
41
|
+
pip-delete-this-directory.txt
|
|
42
|
+
|
|
43
|
+
# Unit test / coverage reports
|
|
44
|
+
htmlcov/
|
|
45
|
+
.tox/
|
|
46
|
+
.nox/
|
|
47
|
+
.coverage
|
|
48
|
+
.coverage.*
|
|
49
|
+
.cache
|
|
50
|
+
nosetests.xml
|
|
51
|
+
coverage.xml
|
|
52
|
+
*.cover
|
|
53
|
+
*.py,cover
|
|
54
|
+
.hypothesis/
|
|
55
|
+
.pytest_cache/
|
|
56
|
+
cover/
|
|
57
|
+
|
|
58
|
+
# Translations
|
|
59
|
+
*.mo
|
|
60
|
+
*.pot
|
|
61
|
+
|
|
62
|
+
# Django stuff:
|
|
63
|
+
*.log
|
|
64
|
+
local_settings.py
|
|
65
|
+
db.sqlite3
|
|
66
|
+
db.sqlite3-journal
|
|
67
|
+
|
|
68
|
+
# Flask stuff:
|
|
69
|
+
instance/
|
|
70
|
+
.webassets-cache
|
|
71
|
+
|
|
72
|
+
# Scrapy stuff:
|
|
73
|
+
.scrapy
|
|
74
|
+
|
|
75
|
+
# Sphinx documentation
|
|
76
|
+
docs/_build/
|
|
77
|
+
|
|
78
|
+
# PyBuilder
|
|
79
|
+
.pybuilder/
|
|
80
|
+
target/
|
|
81
|
+
|
|
82
|
+
# Jupyter Notebook
|
|
83
|
+
.ipynb_checkpoints
|
|
84
|
+
|
|
85
|
+
# IPython
|
|
86
|
+
profile_default/
|
|
87
|
+
ipython_config.py
|
|
88
|
+
|
|
89
|
+
# pyenv
|
|
90
|
+
# For a library or package, you might want to ignore these files since the code is
|
|
91
|
+
# intended to run in multiple environments; otherwise, check them in:
|
|
92
|
+
# .python-version
|
|
93
|
+
|
|
94
|
+
# pipenv
|
|
95
|
+
# According to pypa/pipenv#598, it is recommended to include Pipfile.lock in version control.
|
|
96
|
+
# However, in case of collaboration, if having platform-specific dependencies or dependencies
|
|
97
|
+
# having no cross-platform support, pipenv may install dependencies that don't work, or not
|
|
98
|
+
# install all needed dependencies.
|
|
99
|
+
#Pipfile.lock
|
|
100
|
+
|
|
101
|
+
# poetry
|
|
102
|
+
# Similar to Pipfile.lock, it is generally recommended to include poetry.lock in version control.
|
|
103
|
+
# This is especially recommended for binary packages to ensure reproducibility, and is more
|
|
104
|
+
# commonly ignored for libraries.
|
|
105
|
+
# https://python-poetry.org/docs/basic-usage/#commit-your-poetrylock-file-to-version-control
|
|
106
|
+
#poetry.lock
|
|
107
|
+
|
|
108
|
+
# pdm
|
|
109
|
+
# Similar to Pipfile.lock, it is generally recommended to include pdm.lock in version control.
|
|
110
|
+
#pdm.lock
|
|
111
|
+
# pdm stores project-wide configurations in .pdm.toml, but it is recommended to not include it
|
|
112
|
+
# in version control.
|
|
113
|
+
# https://pdm.fming.dev/latest/usage/project/#working-with-version-control
|
|
114
|
+
.pdm.toml
|
|
115
|
+
.pdm-python
|
|
116
|
+
.pdm-build/
|
|
117
|
+
|
|
118
|
+
# PEP 582; used by e.g. github.com/David-OConnor/pyflow and github.com/pdm-project/pdm
|
|
119
|
+
__pypackages__/
|
|
120
|
+
|
|
121
|
+
# Celery stuff
|
|
122
|
+
celerybeat-schedule
|
|
123
|
+
celerybeat.pid
|
|
124
|
+
|
|
125
|
+
# SageMath parsed files
|
|
126
|
+
*.sage.py
|
|
127
|
+
|
|
128
|
+
# Environments
|
|
129
|
+
.env
|
|
130
|
+
.venv
|
|
131
|
+
env/
|
|
132
|
+
venv/
|
|
133
|
+
ENV/
|
|
134
|
+
env.bak/
|
|
135
|
+
venv.bak/
|
|
136
|
+
|
|
137
|
+
# Spyder project settings
|
|
138
|
+
.spyderproject
|
|
139
|
+
.spyproject
|
|
140
|
+
|
|
141
|
+
# Rope project settings
|
|
142
|
+
.ropeproject
|
|
143
|
+
|
|
144
|
+
# mkdocs documentation
|
|
145
|
+
/site
|
|
146
|
+
|
|
147
|
+
# mypy
|
|
148
|
+
.mypy_cache/
|
|
149
|
+
.dmypy.json
|
|
150
|
+
dmypy.json
|
|
151
|
+
|
|
152
|
+
# Pyre type checker
|
|
153
|
+
.pyre/
|
|
154
|
+
|
|
155
|
+
# pytype static type analyzer
|
|
156
|
+
.pytype/
|
|
157
|
+
|
|
158
|
+
# Cython debug symbols
|
|
159
|
+
cython_debug/
|
|
160
|
+
|
|
161
|
+
# PyCharm
|
|
162
|
+
# JetBrains specific template is maintained in a separate JetBrains.gitignore that can
|
|
163
|
+
# be found at https://github.com/github/gitignore/blob/main/Global/JetBrains.gitignore
|
|
164
|
+
# and can be added to the global gitignore or merged into this file. For a more nuclear
|
|
165
|
+
# option (not recommended) you can uncomment the following to ignore the entire idea folder.
|
|
166
|
+
#.idea/
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
{
|
|
2
|
+
"python.defaultInterpreterPath": ".venv/bin/python",
|
|
3
|
+
"mypy-type-checker.interpreter": [
|
|
4
|
+
".venv/bin/python"
|
|
5
|
+
],
|
|
6
|
+
"mypy.extraArguments": [
|
|
7
|
+
"--enable-incomplete-feature=NewGenericSyntax",
|
|
8
|
+
"--strict"
|
|
9
|
+
],
|
|
10
|
+
"mypy-type-checker.args": [
|
|
11
|
+
"--enable-incomplete-feature=NewGenericSyntax",
|
|
12
|
+
"--strict"
|
|
13
|
+
],
|
|
14
|
+
"editor.formatOnSave": true,
|
|
15
|
+
"editor.renderWhitespace": "selection",
|
|
16
|
+
}
|
wcgw-0.1.0/PKG-INFO
ADDED
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
Metadata-Version: 2.3
|
|
2
|
+
Name: wcgw
|
|
3
|
+
Version: 0.1.0
|
|
4
|
+
Summary: What could go wrong giving full shell access to chatgpt?
|
|
5
|
+
Requires-Python: >=3.12
|
|
6
|
+
Requires-Dist: fastapi>=0.115.0
|
|
7
|
+
Requires-Dist: mypy>=1.11.2
|
|
8
|
+
Requires-Dist: openai>=1.46.0
|
|
9
|
+
Requires-Dist: petname>=2.6
|
|
10
|
+
Requires-Dist: pexpect>=4.9.0
|
|
11
|
+
Requires-Dist: pyte>=0.8.2
|
|
12
|
+
Requires-Dist: python-dotenv>=1.0.1
|
|
13
|
+
Requires-Dist: rich>=13.8.1
|
|
14
|
+
Requires-Dist: shell>=1.0.1
|
|
15
|
+
Requires-Dist: tiktoken==0.7.0
|
|
16
|
+
Requires-Dist: toml>=0.10.2
|
|
17
|
+
Requires-Dist: typer>=0.12.5
|
|
18
|
+
Requires-Dist: types-pexpect>=4.9.0.20240806
|
|
19
|
+
Requires-Dist: uvicorn>=0.31.0
|
|
20
|
+
Requires-Dist: websockets>=13.1
|
|
21
|
+
Description-Content-Type: text/markdown
|
|
22
|
+
|
|
23
|
+
# What could go wrong giving full shell access to Chatgpt?
|
wcgw-0.1.0/README.md
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
# What could go wrong giving full shell access to Chatgpt?
|
wcgw-0.1.0/config.toml
ADDED
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
model = "gpt-4o-2024-08-06"
|
|
2
|
+
secondary_model = 'gpt-4o-2024-08-06'
|
|
3
|
+
cost_limit = 0.1
|
|
4
|
+
|
|
5
|
+
[cost_file.gpt-4o-2024-08-06]
|
|
6
|
+
cost_per_1m_input_tokens = 5
|
|
7
|
+
cost_per_1m_output_tokens = 15
|
|
8
|
+
|
|
9
|
+
[cost_file.gpt-4o-mini]
|
|
10
|
+
cost_per_1m_input_tokens = 0.15
|
|
11
|
+
cost_per_1m_output_tokens = 0.6
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
[project]
|
|
2
|
+
name = "wcgw"
|
|
3
|
+
version = "0.1.0"
|
|
4
|
+
description = "What could go wrong giving full shell access to chatgpt?"
|
|
5
|
+
readme = "README.md"
|
|
6
|
+
requires-python = ">=3.12"
|
|
7
|
+
dependencies = [
|
|
8
|
+
"openai>=1.46.0",
|
|
9
|
+
"mypy>=1.11.2",
|
|
10
|
+
"typer>=0.12.5",
|
|
11
|
+
"rich>=13.8.1",
|
|
12
|
+
"python-dotenv>=1.0.1",
|
|
13
|
+
"tiktoken==0.7.0",
|
|
14
|
+
"pexpect>=4.9.0",
|
|
15
|
+
"shell>=1.0.1",
|
|
16
|
+
"types-pexpect>=4.9.0.20240806",
|
|
17
|
+
"toml>=0.10.2",
|
|
18
|
+
"petname>=2.6",
|
|
19
|
+
"pyte>=0.8.2",
|
|
20
|
+
"fastapi>=0.115.0",
|
|
21
|
+
"uvicorn>=0.31.0",
|
|
22
|
+
"websockets>=13.1",
|
|
23
|
+
]
|
|
24
|
+
|
|
25
|
+
[build-system]
|
|
26
|
+
requires = ["hatchling"]
|
|
27
|
+
build-backend = "hatchling.build"
|
|
28
|
+
|
|
29
|
+
[project.scripts]
|
|
30
|
+
wcgw_local = "wcgw:app"
|
|
31
|
+
wcgw = "wcgw:listen"
|
|
32
|
+
|
|
33
|
+
[tool.uv]
|
|
34
|
+
dev-dependencies = [
|
|
35
|
+
"ipython>=8.27.0",
|
|
36
|
+
"mypy>=1.11.2",
|
|
37
|
+
"types-toml>=0.10.8.20240310",
|
|
38
|
+
"autoflake",
|
|
39
|
+
]
|
|
@@ -0,0 +1,101 @@
|
|
|
1
|
+
import asyncio
|
|
2
|
+
import threading
|
|
3
|
+
import time
|
|
4
|
+
from typing import Callable, Coroutine, Literal, Optional, Sequence
|
|
5
|
+
from uuid import UUID
|
|
6
|
+
import fastapi
|
|
7
|
+
from fastapi import WebSocket, WebSocketDisconnect
|
|
8
|
+
from pydantic import BaseModel
|
|
9
|
+
import uvicorn
|
|
10
|
+
|
|
11
|
+
from dotenv import load_dotenv
|
|
12
|
+
|
|
13
|
+
|
|
14
|
+
class Writefile(BaseModel):
|
|
15
|
+
file_path: str
|
|
16
|
+
file_content: str
|
|
17
|
+
|
|
18
|
+
|
|
19
|
+
Specials = Literal["Key-up", "Key-down", "Key-left", "Key-right", "Enter", "Ctrl-c"]
|
|
20
|
+
|
|
21
|
+
|
|
22
|
+
class ExecuteBash(BaseModel):
|
|
23
|
+
execute_command: Optional[str] = None
|
|
24
|
+
send_ascii: Optional[Sequence[int | Specials]] = None
|
|
25
|
+
|
|
26
|
+
|
|
27
|
+
class Mdata(BaseModel):
|
|
28
|
+
data: ExecuteBash | Writefile
|
|
29
|
+
user_id: UUID
|
|
30
|
+
|
|
31
|
+
|
|
32
|
+
app = fastapi.FastAPI()
|
|
33
|
+
|
|
34
|
+
clients: dict[UUID, Callable[[Mdata], Coroutine[None, None, None]]] = {}
|
|
35
|
+
websockets: dict[UUID, WebSocket] = {}
|
|
36
|
+
gpts: dict[UUID, Callable[[str], None]] = {}
|
|
37
|
+
|
|
38
|
+
|
|
39
|
+
@app.websocket("/register/{uuid}")
|
|
40
|
+
async def register_websocket(websocket: WebSocket, uuid: UUID) -> None:
|
|
41
|
+
await websocket.accept()
|
|
42
|
+
|
|
43
|
+
# Register the callback for this client UUID
|
|
44
|
+
async def send_data_callback(data: Mdata) -> None:
|
|
45
|
+
await websocket.send_text(data.model_dump_json())
|
|
46
|
+
|
|
47
|
+
clients[uuid] = send_data_callback
|
|
48
|
+
websockets[uuid] = websocket
|
|
49
|
+
|
|
50
|
+
try:
|
|
51
|
+
while True:
|
|
52
|
+
received_data = await websocket.receive_text()
|
|
53
|
+
if uuid not in gpts:
|
|
54
|
+
raise fastapi.HTTPException(status_code=400, detail="No call made")
|
|
55
|
+
gpts[uuid](received_data)
|
|
56
|
+
except WebSocketDisconnect:
|
|
57
|
+
# Remove the client if the WebSocket is disconnected
|
|
58
|
+
del clients[uuid]
|
|
59
|
+
del websockets[uuid]
|
|
60
|
+
print(f"Client {uuid} disconnected")
|
|
61
|
+
|
|
62
|
+
|
|
63
|
+
@app.post("/action")
|
|
64
|
+
async def chatgpt_server(json_data: Mdata) -> str:
|
|
65
|
+
user_id = json_data.user_id
|
|
66
|
+
if user_id not in clients:
|
|
67
|
+
raise fastapi.HTTPException(
|
|
68
|
+
status_code=404, detail="User with the provided id not found"
|
|
69
|
+
)
|
|
70
|
+
|
|
71
|
+
results: Optional[str] = None
|
|
72
|
+
|
|
73
|
+
def put_results(result: str) -> None:
|
|
74
|
+
nonlocal results
|
|
75
|
+
results = result
|
|
76
|
+
|
|
77
|
+
gpts[user_id] = put_results
|
|
78
|
+
|
|
79
|
+
await clients[user_id](json_data)
|
|
80
|
+
|
|
81
|
+
start_time = time.time()
|
|
82
|
+
while time.time() - start_time < 30:
|
|
83
|
+
if results is not None:
|
|
84
|
+
return results
|
|
85
|
+
await asyncio.sleep(0.1)
|
|
86
|
+
|
|
87
|
+
raise fastapi.HTTPException(status_code=500, detail="Timeout error")
|
|
88
|
+
|
|
89
|
+
|
|
90
|
+
def run() -> None:
|
|
91
|
+
load_dotenv()
|
|
92
|
+
|
|
93
|
+
uvicorn_thread = threading.Thread(
|
|
94
|
+
target=uvicorn.run, args=(app,), kwargs={"host": "0.0.0.0", "port": 8000}
|
|
95
|
+
)
|
|
96
|
+
uvicorn_thread.start()
|
|
97
|
+
uvicorn_thread.join()
|
|
98
|
+
|
|
99
|
+
|
|
100
|
+
if __name__ == "__main__":
|
|
101
|
+
run()
|