Add Retrieval Example for AI Plugins (#2737)

This PR proposes
- An NLAToolkit method to instantiate from an AI Plugin URL
- A notebook that shows how to use that alongside an example of using a
Retriever object to lookup specs and route queries to them on the fly

---------

Co-authored-by: Harrison Chase <hw.chase.17@gmail.com>
This commit is contained in:
vowelparrot
2023-04-11 23:22:14 -07:00
committed by GitHub
parent b5bbe601fb
commit 94a92abf24
3 changed files with 609 additions and 14 deletions

View File

@@ -17,6 +17,8 @@ class ApiConfig(BaseModel):
class AIPlugin(BaseModel):
"""AI Plugin Definition."""
schema_version: str
name_for_model: str
name_for_human: str
@@ -28,6 +30,12 @@ class AIPlugin(BaseModel):
contact_email: Optional[str]
legal_info_url: Optional[str]
@classmethod
def from_url(cls, url: str) -> AIPlugin:
"""Instantiate AIPlugin from a URL."""
response = requests.get(url).json()
return cls(**response)
def marshal_spec(txt: str) -> dict:
"""Convert the yaml or json serialized spec to a dict."""
@@ -43,8 +51,7 @@ class AIPluginTool(BaseTool):
@classmethod
def from_plugin_url(cls, url: str) -> AIPluginTool:
response = requests.get(url).json()
plugin = AIPlugin(**response)
plugin = AIPlugin.from_url(url)
description = (
f"Call this tool to get the OpenAPI spec (and usage guide) "
f"for interacting with the {plugin.name_for_human} API. "