-
Notifications
You must be signed in to change notification settings - Fork 62
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
9b9c21d
commit 85d09e3
Showing
6 changed files
with
162 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
{ | ||
"api_key": "" | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
from .linkup_api import LinkupApi |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
{ | ||
"text": { | ||
"search": { | ||
"version": "v1.0", | ||
"constraints": { | ||
"depth": ["standard", "deep"], | ||
"outputType": ["searchResults", "sourcedAnswer"] | ||
} | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,80 @@ | ||
from edenai_apis.features.provider.provider_interface import ProviderInterface | ||
from edenai_apis.loaders.loaders import load_provider, ProviderDataEnum | ||
from edenai_apis.utils.exception import ProviderException | ||
from linkup import LinkupClient | ||
from typing import Dict, List, Optional | ||
from pydantic import BaseModel | ||
|
||
|
||
class SearchResult(BaseModel): | ||
type: str | ||
name: Optional[str] | ||
url: Optional[str] | ||
content: Optional[str] | ||
|
||
|
||
class StandardizedResponse(BaseModel): | ||
results: List[SearchResult] | ||
|
||
|
||
class ApiResponse(BaseModel): | ||
original_response: Dict | ||
standardized_response: StandardizedResponse | ||
|
||
|
||
class LinkupApi(ProviderInterface): | ||
provider_name = "linkup" | ||
|
||
def __init__(self, api_keys: Dict = {}): | ||
self.api_settings = load_provider( | ||
ProviderDataEnum.KEY, self.provider_name, api_keys=api_keys | ||
) | ||
self.client = LinkupClient(api_key=self.api_settings["api_key"]) | ||
|
||
def text__search( | ||
self, query: str, texts: list = None, similarity_metric: str = "cosine", model: str = None | ||
): | ||
try: | ||
output_type = "sourcedAnswer" | ||
depth = "standard" | ||
|
||
if model and ":" in model: | ||
params = model.split(":") | ||
if len(params) >= 1: | ||
output_type = params[0] | ||
if len(params) >= 2: | ||
depth = params[1] | ||
|
||
payload = { | ||
"query": query, | ||
"depth": depth, | ||
"output_type": output_type | ||
} | ||
|
||
response = self.client.search(**payload) | ||
|
||
if not hasattr(response, "sources") or not isinstance(response.sources, list): | ||
raise ProviderException("Invalid format for response.sources; expected a list.") | ||
|
||
standardized_response = StandardizedResponse( | ||
results=[ | ||
SearchResult( | ||
type="text", | ||
name=getattr(source, "name", None), | ||
url=getattr(source, "url", None), | ||
content=getattr(source, "snippet", None), | ||
) | ||
for source in response.sources | ||
] | ||
) | ||
|
||
return ApiResponse( | ||
original_response={ | ||
"answer": response.answer, | ||
"sources": response.sources, | ||
}, | ||
standardized_response=standardized_response | ||
) | ||
|
||
except Exception as e: | ||
raise ProviderException(f"Error during Linkup API call: {str(e)}") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,66 @@ | ||
{ | ||
"original_response": { | ||
"answer": "Rome, founded in 753 B.C. by Romulus, is a city rich in history and culture. It boasts various transport options, including two airports: Fiumicino (FCO) and Ciampino (CIA). For travelers, public transport is advised due to the city\u2019s hilly terrain and heavy tourist traffic. Rome offers a multitude of attractions such as the Colosseum and Vatican, with numerous resources available for insights and travel tips.", | ||
"sources": [ | ||
{ | ||
"name": "Rome guide - Rome travel guide", | ||
"url": "https://www.travelplan.it/pdf/rome_guide.pdf", | ||
"snippet": "The founding of Rome is enveloped in myth: the story goes that the first city center sprang up in 753 B.C. on the Palatine hill, built by Romulus after he had killed his twin brother Remus." | ||
}, | ||
{ | ||
"name": "TRAVEL GUIDE MAGAZINE - mrdanielrowland.com", | ||
"url": "https://mrdanielrowland.com/Travel_Guides_mrdanielrowland/ROME_Travel_Guide_free_with_maps.pdf", | ||
"snippet": "Rome has two airports - Fiumicino (FCO) and Ciampino (CIA), but the main one is Leonardo da Vinci International Airport in Fiumicino." | ||
}, | ||
{ | ||
"name": "ROME - Tripadvisor", | ||
"url": "https://cdn.tripadvisor.com/pdfs/Guides/TA_Rome_Guide.pdf", | ||
"snippet": "In addition to the best hotels, restaurants and attractions for every type of traveler, you\u2019ll get great advice about what to pack, how to get around and where to find the best views." | ||
}, | ||
{ | ||
"name": "Rome - Monocle", | ||
"url": "https://monocle.com/workspace/uploads/file/travel/v2_19_rome_web-pdf-58ada7aacf00a.pdf", | ||
"snippet": "Seven Hills, Rome\u2019s pavements can be steep, slippery and choked with tourists so it\u2019s often best to get to grips with public transport." | ||
}, | ||
{ | ||
"name": "Rome Travel Guide", | ||
"url": "http://li.ijcaonline.org/About/browse/Documents/Rome%20Travel%20Guide.pdf", | ||
"snippet": "Immerse yourself in the rich tapestry of Rome's enduring heritage as you follow insightful itineraries." | ||
} | ||
] | ||
}, | ||
"standardized_response": { | ||
"results": [ | ||
{ | ||
"type": "text", | ||
"name": "Rome guide - Rome travel guide", | ||
"url": "https://www.travelplan.it/pdf/rome_guide.pdf", | ||
"content": "The founding of Rome is enveloped in myth: the story goes that the first city center sprang up in 753 B.C. on the Palatine hill, built by Romulus after he had killed his twin brother Remus." | ||
}, | ||
{ | ||
"type": "text", | ||
"name": "TRAVEL GUIDE MAGAZINE - mrdanielrowland.com", | ||
"url": "https://mrdanielrowland.com/Travel_Guides_mrdanielrowland/ROME_Travel_Guide_free_with_maps.pdf", | ||
"content": "Rome has two airports - Fiumicino (FCO) and Ciampino (CIA), but the main one is Leonardo da Vinci International Airport in Fiumicino." | ||
}, | ||
{ | ||
"type": "text", | ||
"name": "ROME - Tripadvisor", | ||
"url": "https://cdn.tripadvisor.com/pdfs/Guides/TA_Rome_Guide.pdf", | ||
"content": "In addition to the best hotels, restaurants and attractions for every type of traveler, you\u2019ll get great advice about what to pack, how to get around and where to find the best views." | ||
}, | ||
{ | ||
"type": "text", | ||
"name": "Rome - Monocle", | ||
"url": "https://monocle.com/workspace/uploads/file/travel/v2_19_rome_web-pdf-58ada7aacf00a.pdf", | ||
"content": "Seven Hills, Rome\u2019s pavements can be steep, slippery and choked with tourists so it\u2019s often best to get to grips with public transport." | ||
}, | ||
{ | ||
"type": "text", | ||
"name": "Rome Travel Guide", | ||
"url": "http://li.ijcaonline.org/About/browse/Documents/Rome%20Travel%20Guide.pdf", | ||
"content": "Immerse yourself in the rich tapestry of Rome's enduring heritage as you follow insightful itineraries." | ||
} | ||
] | ||
} | ||
} |