Getting started
Cycls is a lightweight python framework for publishing and sharing AI chat-apps. It comes with everything you need to get started, with support for local development. All in pure python. No front-end work required.
1. Install
You can install Cycls via pip as follows:
pip install cycls
If you use poetry, you can also install Cycls as:
poetry add cycls
2. Obtain Your Secret Key
First Step
Visit the registration page at platform.cycls.com
Second Step
Complete the sign-up process
Third Step
Navigate to the dashboard, and get your secret key
Important Notes About Your Secret Key:
sk-
3. Define Your App Object
Create a new Python file for e.g. main.py in your project directory, and pick a handler
for the app’s URL:
from cycls import App
app = App(secret="sk-secret",
handler="@handler-name", # app url: handler-name.cycls.app
)
Cycle provides additional optional fields
from cycls import App
app = App(
secret="sk-secret",
handler="@handler-name", # handler-name.cycls.app
name="Application Name", # optional
image="Image URL" # optional
)
4. Define the Entry Point for the App
After creating the app object, you’ll need to define your app entry point, which is decorated with @app
@app
def entry_point(context):
...
The context
object contains important information:
id
: A session id, which can be thought of as a conversation idmessage
: An object containing the user’s messagesend.text
: An action to reply to a message with text without streamingstream.text
: An action to reply to a message with text streaming
5. Full Working Example
Here’s how you might have a complete working app that just resends whatever the user types:
from cycls import App
app = App(secret="sk-secret",
handler="@handler-name")
@app
def entry_point(context):
# Capture the received message
received_message = context.message.content.text
# Reply back with a simple message
context.send.text(f"Received message: {received_message}")
app.publish()
Run your app in the directory containing main.py
:
python main.py
6. Async Support for Streaming (WIP)
Cycls also supports asynchronous (async
) application connections. Async connections are used for streaming responses like how chat-gpt streams the text back to the user in real time.
Import AsyncApp
instead of App
from cycls import AsyncApp
app = AsyncApp(secret="sk-secret"
handler="@handler-name")
[WIP] This example demonstrates the implementation of asynchronous streaming. Follow these steps to modify the synchronous behavior:
- Replace
context.send.text
withcontext.stream.text
to enable streaming responses - Utilize yield to send the response incrementally
from cycls import AsyncApp
app = AsyncApp(secret="sk-secret",
handler="@handler-name")
async def stream_response(received_message: str):
# Stream each word in the received message, one at a time
for word in f"Received message: {received_message}".split():
yield word
@app
async def entry_point(context):
# Capture the received message
received_message = context.message.content.text
# Initiate streaming of the received message
await context.stream.text(stream_response(received_message))
app.publish()
Run your app in the directory containing main.py
:
python main.py