API para desenvolver clientes Python para interagir com o Cheshire Cat.
O pacote permite instantar um cliente da WebSocket e fornece a API para interagir com todos os pontos de extremidade.
Uma parte deste pacote Python é gerada automaticamente pelo projeto OpenAPI Generator.
Para uma documentação mais profunda sobre os terminais disponíveis, consulte a API Redoc. A documentação oficial do Cheshire Cat está disponível aqui.
Python 3.10
Você pode instalar a API com pip :
pip install cheshire-cat-apiEm seguida, importe o pacote:
import cheshire_cat_api as ccat O CatClient tem os seguintes atributos para interface facilmente as APIs relacionadas:
import cheshire_cat_api as ccat
# A config is necessary to set up base parameters like
# URL, port, user_id, etc.
config = ccat . Config ( user_id = "my_user_42" )
# Connect to the API
cat_client = ccat . CatClient (
config = config
) # Now retrieve a list of the available plugins
plugins = cat_client . plugins . get_available_plugins () from cheshire_cat_api . models . body_upload_url import BodyUploadUrl
# Please note that interacting with the RabbitHole to upload
# a URL requires structuring the body like this
body_upload_url = BodyUploadUrl (
url = "https://cheshire-cat-ai.github.io/docs/conceptual/cheshire_cat/rabbit_hole/"
)
# then you can make the request as follows
response = cat_client . rabbit_hole . upload_url ( body_upload_url ) import time
import cheshire_cat_api as ccat
# A config is necessary to set up base parameters like
# URL, port, user_id, etc.
config = ccat . Config ( user_id = "my_user_42" )
cat_client = ccat . CatClient ( config = config )
# Connect to the WebSocket API
cat_client . connect_ws ()
while not cat_client . is_ws_connected :
# A better handling is strongly advised to avoid an infinite loop
time . sleep ( 1 )
# Send the message
cat_client . send ( message = "Hello Cat!" )
# Close connection
cat_client . close ()Ambas as aulas estão disponíveis com:
from cheshire_cat_api import Config| Aula | Nome | Padrão | Descrição |
|---|---|---|---|
| Config | base_url | "Localhost" | URL base onde o gato está hospedado |
| Config | port | 1865 | porta para a conexão |
| Config | user_id | "usuário" | ID do cliente |
| Config | auth_key | "" | Chave de autenticação para os terminais HTTP |
| Config | secure_connection | Falso | Se para usar o Protocolo Seguro |
Para um uso mais avançado, você pode interagir diretamente com o cliente gerado automaticamente. Para documentação, veja aqui