Skip to content

Commit 7a98e80

Browse files
author
Aman Rusia
committed
Pinned python version. Bumped up version. Minor print change
1 parent 041e100 commit 7a98e80

File tree

7 files changed

+254
-39
lines changed

7 files changed

+254
-39
lines changed

.python-version

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
3.12

pyproject.toml

+2-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
[project]
22
authors = [{ name = "Aman Rusia", email = "[email protected]" }]
33
name = "wcgw"
4-
version = "0.0.6"
4+
version = "0.0.7"
55
description = "What could go wrong giving full shell access to chatgpt?"
66
readme = "README.md"
77
requires-python = ">=3.8"
@@ -21,6 +21,7 @@ dependencies = [
2121
"fastapi>=0.115.0",
2222
"uvicorn>=0.31.0",
2323
"websockets>=13.1",
24+
"anthropic>=0.36.2",
2425
]
2526

2627
[project.urls]

src/wcgw/basic.py

+4-29
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,9 @@
2020
from typer import Typer
2121
import uuid
2222

23-
from .common import Models, discard_input
24-
from .common import CostData, History
23+
from wcgw.common import Config, text_from_editor
24+
25+
from .common import Models
2526
from .openai_utils import get_input_cost, get_output_cost
2627
from .tools import ExecuteBash, ReadImage, ImageData
2728

@@ -39,40 +40,14 @@
3940
import tiktoken
4041

4142
from urllib import parse
42-
import subprocess
4343
import os
44-
import tempfile
4544

4645
import toml
47-
from pydantic import BaseModel
4846

4947

5048
from dotenv import load_dotenv
5149

52-
53-
class Config(BaseModel):
54-
model: Models
55-
secondary_model: Models
56-
cost_limit: float
57-
cost_file: dict[Models, CostData]
58-
cost_unit: str = "$"
59-
60-
61-
def text_from_editor(console: rich.console.Console) -> str:
62-
# First consume all the input till now
63-
discard_input()
64-
console.print("\n---------------------------------------\n# User message")
65-
data = input()
66-
if data:
67-
return data
68-
editor = os.environ.get("EDITOR", "vim")
69-
with tempfile.NamedTemporaryFile(suffix=".tmp") as tf:
70-
subprocess.run([editor, tf.name], check=True)
71-
with open(tf.name, "r") as f:
72-
data = f.read()
73-
console.print(data)
74-
return data
75-
50+
History = list[ChatCompletionMessageParam]
7651

7752
def save_history(history: History, session_id: str) -> None:
7853
myid = str(history[1]["content"]).replace("/", "_").replace(" ", "_").lower()[:60]

src/wcgw/common.py

+28-8
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,20 @@
1+
import os
12
import select
3+
import subprocess
24
import sys
5+
import tempfile
36
import termios
47
import tty
58
from typing import Literal
69
from pydantic import BaseModel
10+
import rich
711

812

913
class CostData(BaseModel):
1014
cost_per_1m_input_tokens: float
1115
cost_per_1m_output_tokens: float
1216

1317

14-
from openai.types.chat import (
15-
ChatCompletionMessageParam,
16-
ChatCompletionAssistantMessageParam,
17-
ChatCompletionMessage,
18-
ParsedChatCompletionMessage,
19-
)
20-
21-
History = list[ChatCompletionMessageParam]
2218
Models = Literal["gpt-4o-2024-08-06", "gpt-4o-mini"]
2319

2420

@@ -45,3 +41,27 @@ def discard_input() -> None:
4541
finally:
4642
# Restore old terminal settings
4743
termios.tcsetattr(fd, termios.TCSADRAIN, old_settings)
44+
45+
46+
class Config(BaseModel):
47+
model: Models
48+
secondary_model: Models
49+
cost_limit: float
50+
cost_file: dict[Models, CostData]
51+
cost_unit: str = "$"
52+
53+
54+
def text_from_editor(console: rich.console.Console) -> str:
55+
# First consume all the input till now
56+
discard_input()
57+
console.print("\n---------------------------------------\n# User message")
58+
data = input()
59+
if data:
60+
return data
61+
editor = os.environ.get("EDITOR", "vim")
62+
with tempfile.NamedTemporaryFile(suffix=".tmp") as tf:
63+
subprocess.run([editor, tf.name], check=True)
64+
with open(tf.name, "r") as f:
65+
data = f.read()
66+
console.print(data)
67+
return data

src/wcgw/openai_adapters.py

Whitespace-only changes.

src/wcgw/tools.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -467,7 +467,7 @@ async def register_client(server_url: str, client_uuid: str = "") -> None:
467467

468468
# Create the WebSocket connection
469469
async with websockets.connect(f"{server_url}/{client_uuid}") as websocket:
470-
print(f"Connected. Share this user id with the chatbot: {client_uuid}")
470+
print(f"Connected. Share this user id with the chatbot: {client_uuid} \nLink: https://chatgpt.com/g/g-Us0AAXkRh-wcgw-giving-shell-access")
471471
try:
472472
while True:
473473
# Wait to receive data from the server

0 commit comments

Comments
 (0)