You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Many projects require real, authentic images. Currently, LangChain doesn’t offer a way to retrieve real images on demand. By integrating Unsplash, which has a huge collection of real photos, this toolkit would make it easier for developers to add royalty-free images to their applications.
Proposal (If applicable)
We plan to create a tool that enables LangChain agents to access the Unsplash API. The additions would be unobtrusive and follow a format similar to existing files.
New Files
libs/community/langchain_community/utilities/unsplash.py : API wrapper
classUnsplashQueryRun(BaseTool):
"""Tool that searches the Unsplash API."""name: str="Unsplash"description: str= (
"Query run for UnsplashAPI"
)
api_wrapper: UnsplashAPIWrapperargs_schema: Type[BaseModel] =UnsplashQuerydef_run(
self,
query: str,
run_manager: Optional[CallbackManagerForToolRun] =None,
) ->str:
"""Uses the UnsplashAPIWrapper to perform the actual search."""returnself.api_wrapper.run(query)
classUnsplashAPIWrapper(BaseModel):
top_k_results: int=3load_all_available_meta: bool=False@model_validator(mode="before")@classmethoddefvalidate_environment(cls, values: Dict) ->Any:
"""Validate that the python package exists in environment and also validates if the Unsplash API key exists"""try:
#import unsplash-python in your environmentexceptImportError:
raiseImportError(
#unable to install the package
)
unsplash_api_key=#retrieved through environment variablesreturnunsplash_api_keydefrun(self, query: str) ->str:
"""Search for the image and return it's url."""#we must see if the input is appropriate for searching Unsplashif !query.validate_input:
returnFalse#create url using api and queries in the form https://api.unsplash.com/photos/?client_id=API_KEY...#retrieves the results from the Unsplash APIimage_urls=requests.get(#request_url + params)final_results= []
forurlinimage_urls[: self.top_k_results]:
#we should check if it's a valid image url, if so we add it to final resultsifnotfinal_results:
return"No results were found"returnfinal_results
About Us
We're a group of four students from the University of Toronto, and we're excited to contribute to LangChain. We like our idea because of its straightforward and practical use cases. We aim to have the first version ready by November, and we'd greatly appreciate any feedback or ideas!
reacted with thumbs up emoji reacted with thumbs down emoji reacted with laugh emoji reacted with hooray emoji reacted with confused emoji reacted with heart emoji reacted with rocket emoji reacted with eyes emoji
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
-
Checked
Feature request
We'd like to add a toolkit to integrate the Unsplash API into LangChain. This would allow users to:
Sample Usage
Sample Output
Motivation
Many projects require real, authentic images. Currently, LangChain doesn’t offer a way to retrieve real images on demand. By integrating Unsplash, which has a huge collection of real photos, this toolkit would make it easier for developers to add royalty-free images to their applications.
Proposal (If applicable)
We plan to create a tool that enables LangChain agents to access the Unsplash API. The additions would be unobtrusive and follow a format similar to existing files.
New Files
libs/community/langchain_community/utilities/unsplash.py
: API wrapperlibs/community/langchain_community/tools/unsplash.py
: Tool/libs/community/tests/unit_tests/tools/unsplash/
/libs/community/tests/integration_tests/utilities/
Files to Modify
libs/community/langchain_community/agent_toolkits/load_tools.py
libs/community/langchain_community/tools/__init__.py
libs/langchain/langchain/tools/__init__.py
Sample Code
About Us
We're a group of four students from the University of Toronto, and we're excited to contribute to LangChain. We like our idea because of its straightforward and practical use cases. We aim to have the first version ready by November, and we'd greatly appreciate any feedback or ideas!
Beta Was this translation helpful? Give feedback.
All reactions