Skip to content

Commit 5c616aa

Browse files
committed
chore: rewrite SDK to have parity with other SDKs
The Python SDK has been neglected in favor of the other SDKs. This change brings it up to date wih the others.
1 parent d9cf94d commit 5c616aa

20 files changed

+1333
-369
lines changed

.github/workflows/dispatch.yaml

+44
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
name: Update GPTScript Version
2+
on:
3+
repository_dispatch:
4+
types: release
5+
6+
jobs:
7+
update-gptscript-dep:
8+
runs-on: ubuntu-latest
9+
steps:
10+
- uses: actions/checkout@v4
11+
- name: Update GPTScript Version
12+
run: |
13+
TAG=${{ github.event.client_payload.tag }}
14+
echo "${TAG#v}" >> $VERSION
15+
sed -i 's/version = "[0-9.]*"/version = "'${VERSION}'"/' pyproject.toml
16+
sed -i 's/version: "v[0-9.]*"/version: ""/' gptscript/install.py
17+
- uses: actions/setup-python@v5
18+
with:
19+
python-version: "3.12"
20+
- name: Install deps
21+
run: |
22+
pip install -r requirements.txt
23+
- uses: stefanzweifel/git-auto-commit-action@v5
24+
with:
25+
commit_message: Automated GPTScript Version Update
26+
file_pattern: 'pyproject.toml gptscript/install.py'
27+
tag-release:
28+
needs: update-gptscript-dep
29+
runs-on: ubuntu-latest
30+
steps:
31+
- uses: actions/checkout@v4
32+
- name: Bump version and push tag
33+
id: tag_version
34+
uses: mathieudutour/[email protected]
35+
with:
36+
github_token: ${{ secrets.GITHUB_TOKEN }}
37+
custom_tag: ${{ github.event.client_payload.tag }}
38+
tag_prefix: ""
39+
- name: Create a GitHub release
40+
uses: ncipollo/release-action@v1
41+
with:
42+
tag: ${{ steps.tag_version.outputs.new_tag }}
43+
name: Release ${{ steps.tag_version.outputs.new_tag }}
44+
body: ${{ steps.tag_version.outputs.changelog }}

examples/run.py

+18
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
import asyncio
2+
3+
from gptscript.gptscript import GPTScript
4+
from gptscript.text import Text
5+
from gptscript.tool import Tool
6+
7+
8+
async def main():
9+
g = GPTScript()
10+
nodes = [
11+
Text(fmt="nodeGraph", text='{"main":{"x":-692.5543409432609,"y":-114.63783459299711}}'),
12+
Tool(chat=True, tools=["sys.prompt"], context=["github.com/gptscript-ai/context/workspace"],
13+
instructions="Ask the user for their 'first name'. Then reply hello to the user."),
14+
]
15+
print(await g.fmt(nodes))
16+
17+
18+
asyncio.run(main())

gptscript/command.py

-163
This file was deleted.

gptscript/confirm.py

+9
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
class AuthResponse:
2+
def __init__(self,
3+
id: str = "",
4+
accept: bool = "",
5+
message: str = "",
6+
):
7+
self.id = id
8+
self.accept = accept
9+
self.message = message

gptscript/exec_utils.py

+7-10
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
import subprocess
21
import os
2+
import subprocess
33
import sys
44

55
if sys.platform == "win32":
@@ -19,10 +19,7 @@ def exec_cmd(cmd, args=[], input=None):
1919
encoding="utf-8",
2020
)
2121

22-
if input is None:
23-
return process.communicate()
24-
else:
25-
return process.communicate(input=input)
22+
return process.communicate(input=input)
2623
except Exception as e:
2724
raise e
2825

@@ -48,11 +45,11 @@ def stream_exec_cmd_with_events(cmd, args=[], input=None):
4845
# Duplicate the handle to make it inheritable
4946
proc_handle = win32api.GetCurrentProcess()
5047
dup_handle = win32api.DuplicateHandle(
51-
proc_handle, # Source process handle
52-
w_handle, # Source handle
53-
proc_handle, # Target process handle
54-
0, # Desired access (0 defaults to same as source)
55-
1, # Inherit handle
48+
proc_handle, # Source process handle
49+
w_handle, # Source handle
50+
proc_handle, # Target process handle
51+
0, # Desired access (0 defaults to same as source)
52+
1, # Inherit handle
5653
win32con.DUPLICATE_SAME_ACCESS # Options
5754
)
5855
args = ["--events-stream-to=fd://" + str(int(dup_handle))] + args

0 commit comments

Comments
 (0)