diff --git a/gptscript/tool.py b/gptscript/tool.py index 1b8efd4..285fadf 100644 --- a/gptscript/tool.py +++ b/gptscript/tool.py @@ -59,6 +59,7 @@ def __init__(self, agents: list[str] = None, credentials: list[str] = None, instructions: str = "", + type: str = "", ): self.name = name self.description = description @@ -83,6 +84,7 @@ def __init__(self, self.agents = agents self.credentials = credentials self.instructions = instructions + self.type = type def to_json(self) -> dict[str, Any]: out = self.__dict__ @@ -161,14 +163,16 @@ def __init__(self, agents: list[str] = None, credentials: list[str] = None, instructions: str = "", + type: str = "", toolMapping: dict[str, list[ToolReference]] = None, + metaData: dict[str, str] = None, localTools: dict[str, str] = None, source: SourceRef = None, workingDir: str = "", ): super().__init__(name, description, maxTokens, modelName, modelProvider, jsonResponse, temperature, cache, chat, internalPrompt, arguments, tools, globalTools, globalModelName, context, exportContext, export, - agents, credentials, instructions) + agents, credentials, instructions, type) self.id = id self.toolMapping = toolMapping @@ -179,6 +183,7 @@ def __init__(self, if isinstance(self.toolMapping[tool][i], dict): self.toolMapping[tool][i] = ToolReference(**self.toolMapping[tool][i]) self.localTools = localTools + self.metaData = metaData self.source = source if self.source is not None and isinstance(self.source, dict): self.source = SourceRef(**self.source) diff --git a/tests/fixtures/parse-with-metadata.gpt b/tests/fixtures/parse-with-metadata.gpt new file mode 100644 index 0000000..cfcb965 --- /dev/null +++ b/tests/fixtures/parse-with-metadata.gpt @@ -0,0 +1,12 @@ +Name: foo + +#!/usr/bin/env python3 +import requests + + +resp = requests.get("https://google.com") +print(resp.status_code, end="") + +--- +!metadata:foo:requirements.txt +requests \ No newline at end of file diff --git a/tests/test_gptscript.py b/tests/test_gptscript.py index 30584f9..2e27ae1 100644 --- a/tests/test_gptscript.py +++ b/tests/test_gptscript.py @@ -8,6 +8,7 @@ import pytest from gptscript.confirm import AuthResponse +from gptscript.exec_utils import get_env from gptscript.frame import RunEventType, CallFrame, RunFrame, RunState, PromptFrame from gptscript.gptscript import GPTScript from gptscript.install import install, gptscript_binary_name, python_bin_dir @@ -16,7 +17,6 @@ from gptscript.run import Run from gptscript.text import Text from gptscript.tool import ToolDef, ArgumentSchema, Property, Tool -from gptscript.exec_utils import get_env # Ensure the OPENAI_API_KEY is set for testing @@ -226,6 +226,18 @@ async def test_parse_simple_file(gptscript): "Unexpected output from parsing simple file" +@pytest.mark.asyncio +async def test_parse_tool_with_metadata(gptscript): + wd = os.getcwd() + tools = await gptscript.parse(wd + "/tests/fixtures/parse-with-metadata.gpt") + assert len(tools) == 2, "Unexpected number of tools for parsing simple file" + assert isinstance(tools[0], Tool), "Unexpected node type from parsing file with metadata" + assert "requests.get(" in tools[0].instructions, "Unexpected output from parsing file with metadata" + assert isinstance(tools[1], Text), "Unexpected node type from parsing file with metadata" + assert tools[1].text == "requests", "Unexpected output from parsing file with metadata" + assert tools[1].format == "metadata:foo:requirements.txt", "Unexpected output from parsing file with metadata" + + @pytest.mark.asyncio async def test_parse_tool(gptscript): tools = await gptscript.parse_tool("echo hello") @@ -525,3 +537,9 @@ def test_get_env(): '_gz': base64.b64encode(gzip.compress(b'test value')).decode('utf-8'), }).replace(' ', '') assert 'test value' == get_env('TEST_ENV') + + +@pytest.mark.asyncio +async def test_stream_run_file(gptscript): + run = gptscript.run("./tests/fixtures/parse-with-metadata.gpt") + assert "200" == await run.text(), "Expect file to have correct output"