mirror of
https://github.com/hwchase17/langchain.git
synced 2025-07-05 20:58:25 +00:00
…/17690 Thank you for contributing to LangChain! - [x] **Fix Google Lens knowledge graph issue**: "langchain: community" - Fix for [No "knowledge_graph" property in Google Lens API call from SerpAPI](https://github.com/langchain-ai/langchain/issues/17690) - [x] **PR message**: ***Delete this entire checklist*** and replace with - **Description:** handled the existence of keys in the json response of Google Lens - **Issue:** [No "knowledge_graph" property in Google Lens API call from SerpAPI](https://github.com/langchain-ai/langchain/issues/17690) - [x] **Lint and test**: Run `make format`, `make lint` and `make test` from the root of the package(s) you've modified. See contribution guidelines for more: https://python.langchain.com/docs/contributing/ If no one reviews your PR within a few days, please @-mention one of baskaryan, efriis, eyurtsev, hwchase17. Co-authored-by: Bagatur <22008038+baskaryan@users.noreply.github.com>
This commit is contained in:
parent
a7a4630bf4
commit
28b0b0d863
@ -65,7 +65,10 @@ class GoogleLensAPIWrapper(BaseModel):
|
||||
return "Google Lens search failed"
|
||||
|
||||
xs = ""
|
||||
if len(responseValue["knowledge_graph"]) > 0:
|
||||
if (
|
||||
"knowledge_graph" in responseValue
|
||||
and len(responseValue["knowledge_graph"]) > 0
|
||||
):
|
||||
subject = responseValue["knowledge_graph"][0]
|
||||
xs += f"Subject:{subject['title']}({subject['subtitle']})\n"
|
||||
xs += f"Link to subject:{subject['link']}\n\n"
|
||||
@ -74,10 +77,11 @@ class GoogleLensAPIWrapper(BaseModel):
|
||||
xs += f"Title: {image['title']}\n"
|
||||
xs += f"Source({image['source']}): {image['link']}\n"
|
||||
xs += f"Image: {image['thumbnail']}\n\n"
|
||||
xs += (
|
||||
"Reverse Image Search"
|
||||
+ f"Link: {responseValue['reverse_image_search']['link']}\n"
|
||||
)
|
||||
if "reverse_image_search" in responseValue:
|
||||
xs += (
|
||||
"Reverse Image Search"
|
||||
+ f"Link: {responseValue['reverse_image_search']['link']}\n"
|
||||
)
|
||||
print(xs) # noqa: T201
|
||||
|
||||
docs = [xs]
|
||||
|
Loading…
Reference in New Issue
Block a user