The AI Navigator SDK provides a Python interface for managing models and inference servers. Use it to list and download quantized models, configure and launch API servers, and integrate directly into your application’s workflows.
The .create method creates a new server configuration. By default, creating a server configuration downloads the model file (if it is not already downloaded) and selects a random, unused port for the server. For example:
Report incorrect code
Copy
Ask AI
from anaconda_ai import get_default_clientclient = get_default_client()server = client.servers.create( 'OpenHermes-2.5-Mistral-7B/Q4_K_M',)
If a server with the specified configuration is already running, the existing configuration is returned, and no new server is created.
class InferParams(BaseModel, extra="forbid"): threads: int | None = None n_predict: int | None = None top_k: int | None = None top_p: float | None = None min_p: float | None = None repeat_last: int | None = None repeat_penalty: float | None = None temp: float | None = None parallel: int | None = None
For example, to create a server configuration that uses a specific port; customizes the context size, number of GPU layers, and temperature; and avoids downloading the model file, your code might look like this:
When you invoke a model, llm first ensures that the model has been downloaded, then starts the server using AI Navigator. Standard OpenAI and the SDK’s server parameters are supported. For example:
Report incorrect code
Copy
Ask AI
llm -m 'anaconda:meta-llama/llama-2-7b-chat-hf_Q4_K_M.gguf' -o temperature 0.1 'what is pi?'
The LangChain integration provides Chat and Embedding classes that automatically manage downloading models and starting servers.Install langchain-openai in your environment:
Report incorrect code
Copy
Ask AI
pip install langchain-openai
Only pip install packages in your conda environment once all other packages and their dependencies have been installed. For more information on installing pip packages in your conda environment, see Installing pip packages.
Here is a minimal setup example for using LangChain with Anaconda’s models:
Report incorrect code
Copy
Ask AI
from langchain.prompts import ChatPromptTemplatefrom anaconda_ai.integrations.langchain import AnacondaQuantizedModelChat, AnacondaQuantizedModelEmbeddingsprompt = ChatPromptTemplate.from_template("tell me a joke about {topic}")model = AnacondaQuantizedModelChat(model_name='meta-llama/llama-2-7b-chat-hf_Q4_K_M.gguf')chain = prompt | modelmessage = chain.invoke({'topic': 'python'})
The following keyword arguments are supported:
api_params: Dict or APIParams class above
load_params: Dict or LoadParams class above
infer_params: Dict or InferParams class above (excluding AnacondaQuantizedEmbedding)
The SDK’s server parameter classes are supported for working with LangChain with the exception of AnacondaQuantizedEmbedding.For more information on using the langchain-openai package, see the official documentation.
Only pip install packages in your conda environment once all other packages and their dependencies have been installed. For more information on installing pip packages in your conda environment, see Installing pip packages.
Here is a minimal setup example for using LlamaIndex with Anaconda AI Navigator:
Report incorrect code
Copy
Ask AI
from anaconda_ai.integrations.llama_index import AnacondaModelllm = AnacondaModel( model='OpenHermes-2.5-Mistral-7B_q4_k_m')
The AnacondaModel class supports the following arguments
Parameter
Type
Description
Default
model
str
Model name
Required
system_prompt
str
System prompt
None
temperature
float
Sampling temperature
0.1
max_tokens
int
Max tokens to predict
Model default
api_params
dict or APIParams
Server configuration
None
load_params
dict or LoadParams
Model loading
None
infer_params
dict or InferParams
Inference config
None
For more information on using the llama-index-llms-openai package, see the official documentation.
This provides a CustomLLM provider for use with litellm. But, since litellm does not currently support entrypoints to register the provider, the user must import the module first.
This integration supports litellm.completion() for both standard and streamed completions (stream=True). Most OpenAI-compatible inference parameters are available and behave as expected, with the exception of the n parameter (for multiple completions), which is not currently supported.You can also configure server behavior using the optional_params argument. This accepts a dictionary with api_params, load_params, and infer_params keys, matching the parameter schemas defined in the SDK:
The SDK integrates with DSPy using litellm, allowing you to use quantized local models with any DSPy module that relies on the LM interface.Install the dspy package:
Report incorrect code
Copy
Ask AI
pip install -U dspy
Only pip install packages in your conda environment once all other packages and their dependencies have been installed. For more information on installing pip packages in your conda environment, see Installing pip packages.
Here is an example of how to use DSPy with Anaconda’s models:
Use Panel’s ChatInterface callback to build a chatbot that uses one of Anaconda’s models by serving it through the SDK.
The ChatInterface callback requires panel, httpx, and numpy to be installed in your environment:
Report incorrect code
Copy
Ask AI
conda install panel httpx numpy
Here’s an example Panel chatbot application:
Report incorrect code
Copy
Ask AI
import panel as pnfrom anaconda_ai.integrations.panel import AnacondaModelHandlerpn.extension('echarts', 'tabulator', 'terminal')llm = AnacondaModelHandler('TinyLlama/TinyLlama-1.1B-Chat-v1.0_Q4_K_M.gguf', display_throughput=True)chat = pn.chat.ChatInterface( callback=llm.callback, show_button_name=False)chat.send( "I am your assistant. How can I help you?", user=llm.model_id, avatar=llm.avatar, respond=False)chat.servable()
AnacondaModelHandler supports the following keyword arguments:
Parameter
Description
display_throughput
Show a speed dial next to the response. Default is False
system_message
Default system message applied to all responses
client_options
Optional dict passed as keyword arguments to chat.completions.create