cleverbotfree
1.0.0
Cleverbot.com은 챗봇 애플리케이션을 위한 무료 API를 보유하고 있었습니다. 그들은 가지고 있다
계층화된 구독 API 서비스 대신 무료 API를 제거했습니다.
Cleverbotfree는 헤드리스 Firefox를 사용하는 API의 무료 대안입니다.
챗봇 애플리케이션과 통신하기 위한 브라우저입니다. 이 모듈을 사용할 수 있습니다
Cleverbot과 메시지를 주고받는 애플리케이션/봇 생성
챗봇 애플리케이션.
요구 사항이 충족되면 pip를 통해 이 라이브러리를 설치할 수 있습니다.
pip install cleverbotfree
이 라이브러리는 Playwright 라이브러리를 사용하여 Cleverbot 웹사이트와 인터페이스합니다.
헤드리스 Firefox 브라우저를 사용합니다.
Playwright Firefox 브라우저 바이너리를 다운로드하려면 간단히 다음 명령을 실행하세요.
Cleverbotfree 설치:
playwright install firefox
예
종료될 때까지 영구 채팅 세션을 생성하는 간단한 CLI 스크립트의 예입니다.
import asyncio
import cleverbotfree
def chat ():
"""Example code using cleverbotfree sync api."""
with cleverbotfree . sync_playwright () as p_w :
c_b = cleverbotfree . Cleverbot ( p_w )
while True :
user_input = input ( "User: " )
if user_input == 'quit' :
break
bot = c_b . single_exchange ( user_input )
print ( 'Cleverbot:' , bot )
c_b . close ()
chat ()
async def async_chat ():
"""Example code using cleverbotfree async api."""
async with cleverbotfree . async_playwright () as p_w :
c_b = await cleverbotfree . CleverbotAsync ( p_w )
while True :
user_input = input ( "User: " )
if user_input == 'quit' :
break
bot = await c_b . single_exchange ( user_input )
print ( 'Cleverbot:' , bot )
await c_b . close ()
asyncio . run ( async_chat ())
클래스 데코레이터를 사용하는 간단한 CLI 스크립트의 예입니다.
import asyncio
from cleverbotfree import CleverbotAsync
from cleverbotfree import Cleverbot
@ Cleverbot . connect
def chat ( bot , user_prompt , bot_prompt ):
"""Example code using cleverbotfree sync api with decorator."""
while True :
user_input = input ( user_prompt )
if user_input == "quit" :
break
reply = bot . single_exchange ( user_input )
print ( bot_prompt , reply )
bot . close ()
chat ( "User: " , "Cleverbot:" )
@ CleverbotAsync . connect
async def async_chat ( bot , user_prompt , bot_prompt ):
"""Example code using cleverbotfree async api with decorator."""
while True :
user_input = input ( user_prompt )
if user_input == "quit" :
break
reply = await bot . single_exchange ( user_input )
print ( bot_prompt , reply )
await bot . close ()
asyncio . run ( async_chat ( "User: " , "Cleverbot:" ))