Skip to main content

The Anaconda Assistant Python client

Project description

anaconda-assistant

The Anaconda Assistant Python client

Installation

conda install -c anaconda-cloud anaconda-assistant-sdk

How to authenticate

To use the Python client or CLI you can use anaconda login CLI, Anaconda Navigator, or

from anaconda_auth import login
login()

to launch a browser to login and save your API token to disk. For cases where you cannot utilize a browser to login you can grab your API and set the ANACONDA_AUTH_API_KEY=<api-key> env var.

The Python clients and integrations provide api_key as a keyword argument.

Terms of use and data collection

In order to use the Anaconda Assistant SDK and derived integrations the user must first agree to

On Data Collection: If you opt-in you will enjoy personalized recommendations and contribute to smarter features.

We prioritize your privacy:

  • Your data is never sold
  • Always secured
  • This setting only affects the data Anaconda stores
  • It does not affect the data that is sent to Open AI

To agree to the terms of service and configure data collection edit the ~/.anaconda/config.toml file

[plugin.assistant]
accepted_terms = true
data_collection = true

You may set data_collection = false if you chose to opt-out.

If you set accepted_terms = false the Anaconda Assistant SDK and derived integrations will not function.

If either or both of these values are unset in the ~/.anaconda/config.toml file, an exception will be raised.

Chat session

The ChatSession provides a multi-turn chat interface that saves input and output messages. The response can be streamed or provided in one chunk.

from anaconda_assistant import ChatSession

chat = ChatSession()

text = chat.completions("what are the the first 5 fibonacci numbers?", stream=False)
print(text)

text = chat.completions("make that the first 10 numbers", stream=True)
for chunk in text:
    print(chunk, end="")

Chat client

The ChatClient provides a low-level completions function that accepts a list of messages in the same format as OpenAI. The completions() method returns a ChatResponse object that allows streaming of the response similar to requests Response with .iter_content(), .iter_lines(), and .message, which returns the whole message as a string. Once the who message has been access or consumed through an iterable it is retained in the .message object. Additionally, the response object stores .tokens_used and .tokens_limit integers.

from anaconda_assistant import ChatClient

client = ChatClient()

messages = [
    {"role": "user", "content": "What is pi?"}
]

response = client.completions(messages=messages)

for chunk in response.iter_content():
    print(chunk, end="")

You can only consume the message with .iter_content() once, but the result is captured to the .message attribute while streaming.

Daily quotas

Each Anaconda subscription plan enforces a limit on the number of requests (calls to .completions()). The limits are documented on the Plans and Pricing page. Once the limit is reached the .completions() function will throw a DailyQuotaExceeded exception.

Users can upgrade their plans by visiting https://anaconda.cloud/profile/subscriptions.

Integrations

A number of 3rd party integrations are provided. In each case you will need to have optional packages installed.

LLM CLI

The LLM CLI can be use to send and receive messages with the Anaconda Assistant.

Required packages: llm

To direct your messages to Anaconda Assistant use the model name anaconda-assistant

> llm -m anaconda-assistant 'what is pi?'

LlamaIndex

To use the LlamaIndex integration you will need to install at least llama-index-core

Required packages: llama-index-core

The AnacondaAssistant class supports streaming and non-streaming completions and chat methods. A system prompt can be provided to AnacondaAssistant with the system_prompt keyword argument

from anaconda_assistant.integrations.llama_index import AnacondaAssistant

llm = AnacondaAssistant()

# Completions example
for c in llm.stream_complete('who are you?'):
    print(c.delta, end='')

# Chat example
from llama_index.core.llms import ChatMessage
response = model.chat(messages=[ChatMessage(content="Who are you?")])

# custom system prompt
prompted = AnacondaAssistant(system_prompt='you are a kitty, you will response with meow!')
print(prompted.complete('what is pi?'))

LangChain

A LangChain integration is provided that supports message streaming and non-streaming responses.

Required packages: langchain-core >=0.3 and langchain >=0.3

from anaconda_assistant.integrations.langchain import AnacondaAssistant
from langchain.prompts import ChatPromptTemplate

model = AnacondaAssistant()
prompt = ChatPromptTemplate.from_template("tell me a joke about {topic}")
chain = prompt | model

message = chain.invoke({'topic': 'python'})
print(message.content)

ELL

You can use Anaconda Assistant as a model in the ell prompt engineering framework.

Required packages: ell-ai[sqlite] or ell-ai[postgres]

import ell
import anaconda_assistant.integrations.ell

ell.init(verbose=True)

@ell.simple(model="anaconda-assistant")
def who():
    return "Who are you?"

who()

PandasAI

To use Anaconda Assistant with PandasAI configure the SmartDataFrame using the AnacondaAssistant plugin

Required packages: pandasai

from anaconda_assistant.integrations.pandasai import AnacondaAssistant
from pandasai import SmartDataframe

ai = AnacondaAssistant()
sdf = SmartDataframe(df, config={'llm': ai})
sdf.chat('what is the average of this column where some condition is true?')

Panel

You can integrate the Anaconda Assistant in your Panel application using the chat features including the name and avatar for the signed in user.

Required packages: panel

import panel as pn

from anaconda_auth import BaseClient
from anaconda_assistant.integrations.panel import AnacondaAssistantCallbackHandler

callback = AnacondaAssistantCallbackHandler()
auth_client = BaseClient()

chat = pn.chat.ChatInterface(
    callback=callback,
    user=auth_client.name,
    avatar=auth_client.avatar,
    placeholder_threshold=0.05
)

Setup for development

Ensure you have conda installed. Then run:

make setup

Run the unit tests

make test

Run the unit tests across isolated environments with tox

make tox

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

anaconda_assistant_sdk-0.4.0.tar.gz (31.6 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

anaconda_assistant_sdk-0.4.0-py3-none-any.whl (31.8 kB view details)

Uploaded Python 3

File details

Details for the file anaconda_assistant_sdk-0.4.0.tar.gz.

File metadata

  • Download URL: anaconda_assistant_sdk-0.4.0.tar.gz
  • Upload date:
  • Size: 31.6 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: python-httpx/0.28.1

File hashes

Hashes for anaconda_assistant_sdk-0.4.0.tar.gz
Algorithm Hash digest
SHA256 1bf4b513bab7402faa126874e2ef0c2adb5ddd8a8484c320b239cad4a01c4ad0
MD5 00125eb7ffe356422d10a93ee65b1531
BLAKE2b-256 592c3f129c16f359b1c1617048610ba27e161ce76e9cb199899cd1dc44292bce

See more details on using hashes here.

File details

Details for the file anaconda_assistant_sdk-0.4.0-py3-none-any.whl.

File metadata

File hashes

Hashes for anaconda_assistant_sdk-0.4.0-py3-none-any.whl
Algorithm Hash digest
SHA256 74ceb408ddd4cb2b153d77bbefc98f338c8d948e99b82597bcac2ffd90493362
MD5 05b31ae141535b6551ad46042dc02127
BLAKE2b-256 7927abcbea34c3e8f3934c6acfaac6e0b92c918142b5d42acb0af5ff18188ebc

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page