Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add load method #45

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion gptscript/__init__.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
from gptscript.gptscript import GPTScript
from gptscript.confirm import AuthResponse
from gptscript.frame import RunFrame, CallFrame, PromptFrame
from gptscript.frame import RunFrame, CallFrame, PromptFrame, Program
from gptscript.opts import GlobalOptions
from gptscript.prompt import PromptResponse
from gptscript.run import Run, RunBasicCommand, Options
Expand Down
9 changes: 6 additions & 3 deletions gptscript/frame.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,9 +47,12 @@ def __init__(self,
self.name = name
self.entryToolId = entryToolId
self.toolSet = toolSet
for tool in toolSet:
if isinstance(self.toolSet[tool], dict):
self.toolSet[tool] = Tool(**self.toolSet[tool])
if self.toolSet is None:
self.toolSet = {}
else:
for tool in toolSet:
if isinstance(self.toolSet[tool], dict):
self.toolSet[tool] = Tool(**self.toolSet[tool])


class RunFrame:
Expand Down
7 changes: 6 additions & 1 deletion gptscript/gptscript.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
import requests

from gptscript.confirm import AuthResponse
from gptscript.frame import RunFrame, CallFrame, PromptFrame
from gptscript.frame import RunFrame, CallFrame, PromptFrame, Program
from gptscript.opts import GlobalOptions
from gptscript.prompt import PromptResponse
from gptscript.run import Run, RunBasicCommand, Options
Expand Down Expand Up @@ -94,6 +94,11 @@ def run(
"" if opts is None else opts.input
)

async def load(self, file_path: str) -> Program:
out = await self._run_basic_command("load", {"file": file_path})
parsed_nodes = json.loads(out)
return Program(**parsed_nodes.get("program", {}))

async def parse(self, file_path: str, disable_cache: bool = False) -> list[Text | Tool]:
out = await self._run_basic_command("parse", {"file": file_path, "disableCache": disable_cache})
parsed_nodes = json.loads(out)
Expand Down
7 changes: 7 additions & 0 deletions tests/test_gptscript.py
Original file line number Diff line number Diff line change
Expand Up @@ -248,6 +248,13 @@ async def test_eval_with_context(gptscript):

assert "Acorn Labs" == await run.text(), "Unexpected output from eval using context"

@pytest.mark.asyncio
async def test_load_simple_file(gptscript):
wd = os.getcwd()
prg = await gptscript.load(wd + "/tests/fixtures/test.gpt")
assert prg.toolSet[prg.entryToolId].instructions == "Who was the president of the United States in 1986?", \
"Unexpected output from parsing simple file"


@pytest.mark.asyncio
async def test_parse_simple_file(gptscript):
Expand Down