🖥️
carter-py V1
  • carter-py
  • Conversation
    • Interactions
    • Say
    • Opener
  • Other Features
    • Personalise
  • More
    • Changelog
    • Further Reading
    • carter-js
Powered by GitBook
On this page
  • Prerequisites
  • Installation
  • The Carter Object
  • Async
  • Speak

carter-py

NextInteractions

Last updated 1 year ago

Prerequisites

In order to use carter-py you'll need to sign up to sign up to and create an agent. CarterAPI has excellent documentation.

Installation

pip install carter-py

The Carter Object

The main component of carter-py is the Carter class. This class provides a set of methods to interact with your carter agent.

from carterpy import Carter


# Replace YOUR_API_KEY with your actual API key

carter = Carter("YOUR_API_KEY")

# Send a message to the API

response = carter.say("Hello, world!", "player123")

# Print the response text

print(response.output_text)

Pass in the apiKey of your specific agent - remember to keep this secret while developing and in production as this will allow anyone access to your agent.

Async

carter-py is compatible with asynchronous code through importing the async version of the class.

import asyncio
from carterpy import AsyncCarter

async def main():
    async_carter = AsyncCarter("YOUR_API_KEY)

    # with carter object already created
    interaction = await async_carter.say("hello", "player123")
    personalise = await async_carter.personalise("Hello, world!", "player_id")
    opener = await async_carter.opener("player123")
    print(interaction.output_text)

asyncio.run(main())

Speak

When using any of the following methods, the output audio will not be returned by default as this currently introduces significant latency on the API end. If you want to receive the audio you have two options. You can set the speak parameter to Truewhen creating the Carter object, or you can set it to Truewhen calling the method. When calling a function carter-py will first check if the speak parameter has been overridden in the function call, if it hasn't, it will use the class default.

    carter = Carter('your-api-key') 
    # False by default

    interaction = carter.say("Hello, world!", "player123") 
    # No audio will be returned, because you have not overridden the default on the class

    interaction = carter.say("Hello, world!", "player123", speak=True) 
    # Audio will be returned, because you have overridden the default on the class

Documentation on say() is included in further sections.

CarterAPI