Skip to content

Commit dd030c8

Browse files
committed
feat: add metadata and type fields to tools
Signed-off-by: Donnie Adams <[email protected]>
1 parent 498ccd9 commit dd030c8

File tree

3 files changed

+37
-2
lines changed

3 files changed

+37
-2
lines changed

gptscript/tool.py

+6-1
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,7 @@ def __init__(self,
5959
agents: list[str] = None,
6060
credentials: list[str] = None,
6161
instructions: str = "",
62+
type: str = "",
6263
):
6364
self.name = name
6465
self.description = description
@@ -83,6 +84,7 @@ def __init__(self,
8384
self.agents = agents
8485
self.credentials = credentials
8586
self.instructions = instructions
87+
self.type = type
8688

8789
def to_json(self) -> dict[str, Any]:
8890
out = self.__dict__
@@ -161,14 +163,16 @@ def __init__(self,
161163
agents: list[str] = None,
162164
credentials: list[str] = None,
163165
instructions: str = "",
166+
type: str = "",
164167
toolMapping: dict[str, list[ToolReference]] = None,
168+
metaData: dict[str, str] = None,
165169
localTools: dict[str, str] = None,
166170
source: SourceRef = None,
167171
workingDir: str = "",
168172
):
169173
super().__init__(name, description, maxTokens, modelName, modelProvider, jsonResponse, temperature, cache, chat,
170174
internalPrompt, arguments, tools, globalTools, globalModelName, context, exportContext, export,
171-
agents, credentials, instructions)
175+
agents, credentials, instructions, type)
172176

173177
self.id = id
174178
self.toolMapping = toolMapping
@@ -179,6 +183,7 @@ def __init__(self,
179183
if isinstance(self.toolMapping[tool][i], dict):
180184
self.toolMapping[tool][i] = ToolReference(**self.toolMapping[tool][i])
181185
self.localTools = localTools
186+
self.metaData = metaData
182187
self.source = source
183188
if self.source is not None and isinstance(self.source, dict):
184189
self.source = SourceRef(**self.source)
+12
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
Name: foo
2+
3+
#!/usr/bin/env python3
4+
import requests
5+
6+
7+
resp = requests.get("https://google.com")
8+
print(resp.status_code, end="")
9+
10+
---
11+
!metadata:foo:requirements.txt
12+
requests

tests/test_gptscript.py

+19-1
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
import pytest
99

1010
from gptscript.confirm import AuthResponse
11+
from gptscript.exec_utils import get_env
1112
from gptscript.frame import RunEventType, CallFrame, RunFrame, RunState, PromptFrame
1213
from gptscript.gptscript import GPTScript
1314
from gptscript.install import install, gptscript_binary_name, python_bin_dir
@@ -16,7 +17,6 @@
1617
from gptscript.run import Run
1718
from gptscript.text import Text
1819
from gptscript.tool import ToolDef, ArgumentSchema, Property, Tool
19-
from gptscript.exec_utils import get_env
2020

2121

2222
# Ensure the OPENAI_API_KEY is set for testing
@@ -226,6 +226,18 @@ async def test_parse_simple_file(gptscript):
226226
"Unexpected output from parsing simple file"
227227

228228

229+
@pytest.mark.asyncio
230+
async def test_parse_tool_with_metadata(gptscript):
231+
wd = os.getcwd()
232+
tools = await gptscript.parse(wd + "/tests/fixtures/parse-with-metadata.gpt")
233+
assert len(tools) == 2, "Unexpected number of tools for parsing simple file"
234+
assert isinstance(tools[0], Tool), "Unexpected node type from parsing file with metadata"
235+
assert "requests.get(" in tools[0].instructions, "Unexpected output from parsing file with metadata"
236+
assert isinstance(tools[1], Text), "Unexpected node type from parsing file with metadata"
237+
assert tools[1].text == "requests", "Unexpected output from parsing file with metadata"
238+
assert tools[1].format == "metadata:foo:requirements.txt", "Unexpected output from parsing file with metadata"
239+
240+
229241
@pytest.mark.asyncio
230242
async def test_parse_tool(gptscript):
231243
tools = await gptscript.parse_tool("echo hello")
@@ -525,3 +537,9 @@ def test_get_env():
525537
'_gz': base64.b64encode(gzip.compress(b'test value')).decode('utf-8'),
526538
}).replace(' ', '')
527539
assert 'test value' == get_env('TEST_ENV')
540+
541+
542+
@pytest.mark.asyncio
543+
async def test_stream_run_file(gptscript):
544+
run = gptscript.run("./tests/fixtures/parse-with-metadata.gpt")
545+
assert "200" == await run.text(), "Expect file to have correct output"

0 commit comments

Comments
 (0)