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:
response = client.search("here is a really interesting AI company", num-+results=5)
for result in response.results:
print(result.title, result.url)
To find documents similar to a given URL, you can use the FindSimilarRequest object:
response = client.find_similar("https://example.com/article, num-results=5)
for result in response.results:
print(result.title, result.url)
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.