Research
Security News
Malicious npm Package Targets Solana Developers and Hijacks Funds
A malicious npm package targets Solana developers, rerouting funds in 2% of transactions to a hardcoded address.
Simple, type-safe access to the ChatNoir search API.
Working with PyTerrier? Check out the chatnoir-pyterrier
package.
Install the package from PyPI:
pip install chatnoir-api
The ChatNoir API offers two main features: search with BM25F and retrieving document contents.
You can use our Python client to search for documents.
The results
object is an iterable wrapper of the search results which handles pagination for you.
List-style indexing is supported to access individual results or sub-lists of results:
from chatnoir_api.v1 import search
results = search("python library")
top10_results = results[:10]
print(top10_results)
result_1234 = results[1234]
print(result_1234)
To limit your search requests to a single index (e.g., ClueWeb22 category B), set the index
parameter like this:
from chatnoir_api import Index
from chatnoir_api.v1 import search
api_key: str = "<API_KEY>"
results = search("python library", index="clueweb22/b")
To search for phrases, use the search_phrases
method in the same way as normal search
:
from chatnoir_api.v1 import search_phrases
results = search_phrases("python library")
The public, shared, default API key comes with a limited request budget. To use the ChatNoir API more extensively, please request a dedicated API key.
Then, use the api_key
parameter to add it to your requests like this:
results = search("python library", api_key="<YOUR_API_KEY>")
To generate text with the ChatNoir Chat API you need to request an API key from the admins. With your API key, you can chat with the cat, like this:
from chatnoir_api.chat import ChatNoirChatClient
chat_client = ChatNoirChatClient(api_key="<API_KEY>")
response = chat_client.chat("how are you?")
Often the title and ID of a document is not enough to effectively re-rank a list of search results.
To retrieve the full content or plain text for a given document you can use the html_contents
helper function.
The html_contents
function expects a ChatNoir-internal UUID, shorthand UUID, or a TREC ID and the index from which to retrieve the document.
You can retrieve a document by its TREC ID like this:
from chatnoir_api import cache_contents, Index
contents = cache_contents(
"clueweb09-en0051-90-00849",
index="clueweb09",
)
print(contents)
plain_contents = cache_contents(
"clueweb09-en0051-90-00849",
index="clueweb09",
plain=True,
)
print(plain_contents)
For newer ChatNoir versions, you can also retrieve a document by its ChatNoir-internal short UUID like this:
from chatnoir_api import cache_contents, Index, ShortUUID
contents = cache_contents(
ShortUUID("MzOlTIayX9ub7c13GLPr_g"),
index="clueweb22/b",
)
print(contents)
plain_contents = cache_contents(
ShortUUID("MzOlTIayX9ub7c13GLPr_g"),
index="clueweb22/b",
plain=True,
)
print(plain_contents)
To build this package and contribute to its development you need to install the build
, and setuptools
and wheel
packages:
pip install build setuptools wheel
(On most systems, these packages are already pre-installed.)
Install package and test dependencies:
pip install -e .[tests]
Configure the API keys for testing:
export CHATNOIR_API_KEY="<API_KEY>"
export CHATNOIR_API_KEY_CHAT="<API_KEY>"
Verify your changes against the test suite to verify.
ruff check . # Code format and LINT
mypy . # Static typing
bandit -c pyproject.toml -r . # Security
pytest . # Unit tests
Please also add tests for your newly developed code.
Wheels for this package can be built with:
python -m build
If you hit any problems using this package, please file an issue. We're happy to help!
This repository is released under the MIT license.
FAQs
Simple, type-safe access to the ChatNoir search API.
We found that chatnoir-api demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 3 open source maintainers collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Research
Security News
A malicious npm package targets Solana developers, rerouting funds in 2% of transactions to a hardcoded address.
Security News
Research
Socket researchers have discovered malicious npm packages targeting crypto developers, stealing credentials and wallet data using spyware delivered through typosquats of popular cryptographic libraries.
Security News
Socket's package search now displays weekly downloads for npm packages, helping developers quickly assess popularity and make more informed decisions.