LLM plugin for interacting with Jina AI APIs
Install this plugin in the same environment as LLM.
llm install llm-jina
You need to set the JINA_API_KEY
environment variable with your Jina AI API key. You can get a free API key from https://jina.ai/?sui=apikey.
export JINA_API_KEY=your_api_key_here
This plugin adds several commands to interact with Jina AI APIs:
Generate embeddings for given texts:
llm jina embed "The quick brown fox jumps over the lazy dog."
You can specify a different model using the --model
option:
llm jina embed "To be, or not to be, that is the question." --model jina-embeddings-v2-base-en
Rerank documents based on a query:
llm jina rerank "Best sci-fi movies" "Star Wars: A New Hope" "The Matrix" "Blade Runner" "Interstellar" "2001: A Space Odyssey"
You can specify a different model using the --model
option:
llm jina rerank "Healthy eating tips" "Eat more fruits and vegetables" "Limit processed foods" "Stay hydrated" --model jina-reranker-v2-base-en
Read and parse content from a URL:
llm jina read https://en.wikipedia.org/wiki/Artificial_intelligence
You can include link and image summaries:
llm jina read https://www.nasa.gov/topics/moon-to-mars --with-links --with-images
Search the web for information:
llm jina search "History of the internet"
You can limit the search to a specific domain:
llm jina search "Python programming tutorials" --site docs.python.org
Example with multiple options:
llm jina search "Climate change impacts" --site nasa.gov --with-links --with-images
Verify the factual accuracy of a statement:
llm jina ground "The Mona Lisa was painted by Leonardo da Vinci."
You can provide specific sites for grounding:
llm jina ground "Jina AI offers state-of-the-art AI models." --sites https://jina.ai,https://docs.jina.ai
Segment text into tokens or chunks:
llm jina segment --content "Space: the final frontier. These are the voyages of the starship Enterprise. Its five-year mission: to explore strange new worlds. To seek out new life and new civilizations. To boldly go where no man has gone before
In the beginning God created the heaven and the earth. And the earth was without form, and void; and darkness was upon the face of the deep." --tokenizer cl100k_base --return-chunks
Example response:
{
"chunks": [
"Space: the final frontier. These are the voyages of the starship Enterprise. Its five-year mission: to explore strange new worlds. To seek out new life and new civilizations. To boldly go where no man has gone before\n",
"In the beginning God created the heaven and the earth. And the earth was without form, and void; and darkness was upon the face of the deep."
]
}
Classify inputs into given labels:
llm jina classify "The movie was amazing! I loved every minute of it." "The acting was terrible and the plot made no sense." --labels positive negative neutral
For image classification:
llm jina classify path/to/cat.jpg path/to/dog.jpg path/to/bird.jpg --labels feline canine avian --image
Generate Jina API code based on a prompt:
llm jina generate-code "Create a function that searches Wikipedia for information about famous scientists and reranks the results based on relevance to the query."
llm jina generate-code "Create a function that searches for information about AI and reranks the results based on relevance"
Display the Jina metaprompt used for generating code:
llm jina metaprompt
To set up this plugin locally, first checkout the code. Then create a new virtual environment:
cd llm-jina
python3 -m venv venv
source venv/bin/activate
Now install the dependencies and test dependencies:
pip install -e '.[test]'
To run the tests:
pytest
Contributions to this plugin are welcome! Please refer to the LLM plugin development documentation for more information on how to get started.