An ergonomic way to use Metaphor in python.
Install metaphor-python
via pip:
pip install metaphor-python
Import the package and initialize the Metaphor client with your API key:
from metaphor_python import Metaphor
client = Metaphor(api_key="your-api-key")
You can perform a search by creating a SearchRequest object and passing it to the search method:
from metaphor_python import SearchRequest
request = SearchRequest(query="Here is a reaully interesting AI company:", num_results=5)
response = client.search(request)
for result in response.results:
print(result.title, result.url)
To find documents similar to a given URL, you can use the FindSimilarRequest object:
from metaphor_python import FindSimilarRequest
request = FindSimilarRequest(url="https://example.com/article", num_results=5)
response = client.find_similar(request)
for result in response.results:
print(result.title, result.url)
To retrieve the contents of documents, use the GetContentsRequest object:
from metaphor_python import GetContentsRequest
request = GetContentsRequest(ids=["doc1", "doc2"])
response = client.get_contents(request)
for content in response.contents:
print(content.title, content.url)
Contributions to metaphor-python are very welcome! Feel free to submit pull requests or raise issues.