主要特性 • 範例 • 入門 • 附加資訊
線上嘗試 CSML
CSML(會話標準元語言)既是一種特定領域的程式語言,也是聊天機器人引擎,旨在使開發複雜的聊天機器人變得容易。
CSML 流具有非常富有表現力的純文字語法,易於理解,從而可以輕鬆部署和維護會話代理。憑藉其強大的運行時 API,CSML 可以處理短期和長期記憶體插槽、元資料注入以及連接到任何第三方 API 或以任何程式語言注入任意程式碼。
start:
say " Hi, nice to meet you, I'm a demo bot "
if (name) {
say " I already know you "
goto known
}
else
goto name
name:
say Question (
" I'd like to know you better, what's your name? " ,
buttons=[
Button ( " I'm anonymous ? " , accepts=[ " No " , " Nope " ]) as anonBtn
],
)
hold
if (event.match(anonBtn)) {
remember name = " anon "
} else {
remember name = event
}
goto known
known:
if (name == " anon " )
say "...but I know you don't want to say too much about yourself!"
else
say "You are {{name}}! "
goto end
完整文件可在 https://docs.csml.dev/language 上找到。
開始使用 CSML 最簡單的方法是使用 CSML Studio,這是一個免費的線上開發環境,所有內容都已設定好,可以直接在瀏覽器中立即開始建立機器人。
開始使用 CSML Studio:https://studio.csml.dev
CSML Studio 為您提供了一個免費的平台來試驗該語言,以及一鍵大規模部署聊天機器人的選項。
CSML 可作為自架 Web 伺服器,您可以使用下列選項之一輕鬆安裝。
請注意,您將需要一個資料庫。預設選擇是MongoDB ,但也可以透過選擇環境變數集略有不同的mongodb
、 dynamodb
、 postgresql
或sqlite
引擎資料庫類型來使用Amazon DynamoDB 、 PostgreSQL和SQLite 。
在開始之前,請確保您已使用以下選項設定環境:
ENGINE_DB_TYPE=mongodb # must be one of mongodb|dynamodb|postgresql|sqlite
# for mongodb
MONGODB_URI=mongodb://username:password@localhost:27017
MONGODB_DATABASE=csml
# for postgresql
POSTGRESQL_URL=postgres://user:password@hostname:port/database
# for sqlite
SQLITE_URL=csml.db
# for dynamodb (requires S3 for storage of large items)
AWS_ACCESS_KEY_ID= # or use a local IAM role
AWS_SECRET_ACCESS_KEY= # or use a local IAM role
AWS_REGION=
AWS_DYNAMODB_ENDPOINT= # optional, defaults to the dynamodb endpoint for the given region.
AWS_DYNAMODB_TABLE=
AWS_S3_ENDPOINT= # optional, defaults to the S3 endpoint for the given region
AWS_S3_BUCKET=
# CSML Server configuration
ENGINE_SERVER_PORT=5000
ENGINE_SERVER_API_KEYS=someAuthKey4CsmlServer,someOtherAuthKey
# Other optional engine configuration
ENGINE_ENCRYPTION_SECRET=some-secret-string # if not set, data will not be stored encrypted
TTL_DURATION=30 # auto-remove chatbot user data after X days
LOW_DATA_MODE=true # do not store contents of sent/received messages
DISABLE_SSL_VERIFY=false # reach trusted endpoints with known invalid certificates
DEBUG=true # print debug output in console
CSML_LOG_LEVEL=error # print log output in stderr. Possible values are error, warn, info, debug, trace.
MODULES_URL= # default module repository base url
MODULES_AUTH= # default module auth token
在您自己的電腦上啟動 CSML 引擎的最簡單方法是使用我們預先建立的最佳化二進位檔案之一(適用於 MongoDB 和 Amazon DynamoDB)。自 v1.3.0 以來,這些二進位檔案在每個 CSML 版本上都可以作為可執行檔使用。
請按照此部落格文章中的安裝指南(適用於ubuntu,但該過程在其他作業系統上類似)進行操作:https://blog.csml.dev/how-to-install-a-self-hosted-csml- engine -在-ubuntu-18-04/
若要下載最新的 CSML Server 二進位文件,請前往最新版本並確保下載適合您的架構的版本。
Mac 使用者:首次執行此二進位檔案時,Mac 可能會開啟一條有關應用程式未簽署的警告(來自 Apple 的更多資訊)。由於這並不打算作為廣泛分發的應用程序,因此我們決定暫時不進行公證過程,但您可以安全地忽略該警告!但是,如果您願意,您始終可以從原始程式碼建立此套件。
我們提供了一個 docker 映像,方便自架使用。
docker pull clevy/csml-engine
要開始在 Docker 上使用 CSML 引擎:https://github.com/CSML-by-Clevy/csml-engine-docker
CSML 是用 Rust 建構的。不過,您不需要了解任何 Rust 即可運行它!確保您運行的是 Rust v1.46+ 並且您的電腦上安裝了 openssl(或 Linux 發行版的等效版本,例如 libssl),然後運行:
cd csml_server
# for use with MongoDB
cargo build --release --features csml_engine/mongo
# for use with Amazon DynamoDB
cargo build --release --features csml_engine/dynamo
之後,執行您的建置(預設在 ./targets/release/csml_server 下)並造訪 http://localhost:5000 以取得一些請求範例。
此儲存庫提供了此 rust 函式庫的 Node.js 綁定。要在 Node.js 專案中使用此程式庫,您需要從原始程式碼建置它。有幾個要求:
若要將 CSML Engine 編譯為本機節點模組,請執行:
git clone https://github.com/CSML-by-Clevy/csml-engine csml
cd csml/bindings/node/native
npm run build -- --release
注意:您可以使用 package.json 中的專用腳本之一(即
npm run build:mongodb
)專門針對 MongoDB、DynamoDB、SQLite 或 PostgreSQL 進行建置。
此方法將輸出此本機檔案: csml/bindings/node/native/index.node
,您可以在專案中簡單地require()
(或import
)。有關如何在自己的專案中使用此模組的更多詳細信息,您可以查看我們的 Docker 版本實作。
請注意,如果您打算在不同的架構上部署項目,則需要在該架構上重新編譯項目。如果您需要將 CSML Engine 整合到您自己的 Node.js 專案中,我們建議您使用 git 子模組。
CSML Server 的 HTTP REST API 文件以 OpenAPIv3 格式提供:swagger.yaml。要輕鬆閱讀此文件,您可以在 Swagger Editor 中開啟它。