Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
Create Llama
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Iterations
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Locked files
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package registry
Container Registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Service Desk
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Code review analytics
Issue analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Terms and privacy
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
mirrored_repos
MachineLearning
run-llama
Create Llama
Commits
d8bc271a
Commit
d8bc271a
authored
9 months ago
by
leehuwuj
Browse files
Options
Downloads
Patches
Plain Diff
add local tool that combine openapi and request tool
parent
f29561cd
No related branches found
No related tags found
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
helpers/tools.ts
+9
-23
9 additions, 23 deletions
helpers/tools.ts
templates/components/engines/python/agent/tools/openapi_action.py
+59
-0
59 additions, 0 deletions
...s/components/engines/python/agent/tools/openapi_action.py
with
68 additions
and
23 deletions
helpers/tools.ts
+
9
−
23
View file @
d8bc271a
...
@@ -118,8 +118,8 @@ export const supportedTools: Tool[] = [
...
@@ -118,8 +118,8 @@ export const supportedTools: Tool[] = [
],
],
},
},
{
{
display
:
"
OpenAPI
"
,
display
:
"
OpenAPI
action
"
,
name
:
"
openapi.OpenAPIToolSpec
"
,
name
:
"
openapi
_action
.OpenAPI
Action
ToolSpec
"
,
dependencies
:
[
dependencies
:
[
{
{
name
:
"
llama-index-tools-openapi
"
,
name
:
"
llama-index-tools-openapi
"
,
...
@@ -129,35 +129,21 @@ export const supportedTools: Tool[] = [
...
@@ -129,35 +129,21 @@ export const supportedTools: Tool[] = [
name
:
"
jsonschema
"
,
name
:
"
jsonschema
"
,
version
:
"
^4.22.0
"
,
version
:
"
^4.22.0
"
,
},
},
],
config
:
{
url
:
"
The URL of the OpenAPI schema
"
,
},
supportedFrameworks
:
[
"
fastapi
"
],
type
:
ToolType
.
LLAMAHUB
,
envVars
:
[
{
{
name
:
TOOL_SYSTEM_PROMPT_ENV_VAR
,
name
:
"
llama-index-tools-requests
"
,
description
:
"
System prompt for openapi tool.
"
,
version
:
"
0.1.3
"
,
value
:
`You can use the provided OpenAPI schema to see the available endpoints to make requests with the HTTP Request tool.`
,
},
},
],
],
},
{
display
:
"
HTTP Request
"
,
name
:
"
requests.RequestsToolSpec
"
,
dependencies
:
[],
supportedFrameworks
:
[
"
fastapi
"
],
type
:
ToolType
.
LLAMAHUB
,
config
:
{
config
:
{
domain_headers
:
openapi_uri
:
"
The URL or file path of the OpenAPI schema
"
,
"
A mapping of domain to its headers. Example: example.com: {}
"
,
},
},
supportedFrameworks
:
[
"
fastapi
"
],
type
:
ToolType
.
LOCAL
,
envVars
:
[
envVars
:
[
{
{
name
:
TOOL_SYSTEM_PROMPT_ENV_VAR
,
name
:
TOOL_SYSTEM_PROMPT_ENV_VAR
,
description
:
"
System prompt for openapi tool.
"
,
description
:
"
System prompt for openapi
action
tool.
"
,
value
:
`You
can make HTTP
requests to the provided
domain
.`
,
value
:
`You
are an OpenAPI action agent. You help users to make
requests to the provided
OpenAPI schema
.`
,
},
},
],
],
},
},
...
...
This diff is collapsed.
Click to expand it.
templates/components/engines/python/agent/tools/openapi_action.py
0 → 100644
+
59
−
0
View file @
d8bc271a
import
inspect
from
typing
import
Dict
,
List
,
Tuple
from
llama_index.tools.openapi
import
OpenAPIToolSpec
from
llama_index.tools.requests
import
RequestsToolSpec
class
OpenAPIActionToolSpec
(
OpenAPIToolSpec
,
RequestsToolSpec
):
"""
A combination of OpenAPI and Requests tool specs that can parse OpenAPI specs and make requests.
openapi_uri: str: The file path or URL to the OpenAPI spec.
domain_headers: dict: Whitelist domains and the headers to use.
"""
spec_functions
=
OpenAPIToolSpec
.
spec_functions
+
RequestsToolSpec
.
spec_functions
def
__init__
(
self
,
openapi_uri
:
str
,
domain_headers
:
dict
=
{},
**
kwargs
):
# Load the OpenAPI spec
openapi_spec
,
servers
=
self
.
load_openapi_spec
(
openapi_uri
)
# Add the servers to the domain headers if they are not already present
for
server
in
servers
:
if
server
not
in
domain_headers
:
domain_headers
[
server
]
=
{}
OpenAPIToolSpec
.
__init__
(
self
,
spec
=
openapi_spec
)
RequestsToolSpec
.
__init__
(
self
,
domain_headers
)
@staticmethod
def
load_openapi_spec
(
uri
:
str
)
->
Tuple
[
Dict
,
List
[
str
]]:
"""
Load an OpenAPI spec from a URI.
Args:
uri (str): A file path or URL to the OpenAPI spec.
Returns:
List[Document]: A list of Document objects.
"""
import
yaml
from
urllib.parse
import
urlparse
if
uri
.
startswith
(
"
http
"
):
import
requests
response
=
requests
.
get
(
uri
).
text
spec
=
yaml
.
safe_load
(
response
)
elif
uri
.
startswith
(
"
file
"
):
filepath
=
uri
[
7
:]
# Remove the 'file://' scheme
with
open
(
filepath
,
"
r
"
)
as
file
:
spec
=
yaml
.
safe_load
(
file
)
else
:
raise
ValueError
(
"
Could not initialize OpenAPIActionToolSpec because invalid OpenAPI URI provided.
"
"
Only HTTP and file path are supported.
"
)
# Add the servers to the whitelist
servers
=
[
urlparse
(
server
[
"
url
"
]).
netloc
for
server
in
spec
.
get
(
"
servers
"
,
[])]
return
spec
,
servers
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment