mirror of
https://github.com/hwchase17/langchain.git
synced 2025-09-18 16:16:33 +00:00
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:
@@ -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. "
|
||||
|
Reference in New Issue
Block a user