Beispiel #1
0
import coffeehouse

api_key = "1082159"
api_client = coffeehouse.API(api_key)

session = api_client.create_session()
print("Session ID: {0}".format(session.id))
print("Session Available: {0}".format(str(session.available)))
print("Session Language: {0}".format(str(session.language)))
print("Session Expires: {0}".format(str(session.expires)))

while(True):
    output = session.think_thought(input("Input: "))
    print("Output: {0}".format(output))


# In the case you want to save the Session ID to reuse the session
# Use api_client to invoke think_thought instead, for example;
#
# while(True):
#     output = api_client.think_thought(session.id, input("Input: "))
#     print("Output: {0}".format(output))
#
# This is the same effect as above but uses the client directly.
@Hackintosh5 (for inspiring me to write this module)
@Zero_cool7870 (For Writing The Original Module)
Zi Xing (For CoffeeHouse API)"""

import coffeehouse as cf

import asyncio
import io
from sql_helpers.lydia_ai_sql import get_s, get_all_s, add_s, remove_s
from time import time
from uniborg.util import admin_cmd

if Config.LYDIA_API is not None:
    api_key = Config.LYDIA_API
    # Initialise client
    api_client = cf.API(api_key)


@borg.on(admin_cmd(pattern="(ena|del|lst)cf", allow_sudo=True))
async def lydia_disable_enable(event):
    if event.fwd_from:
        return
    if Config.LYDIA_API is None:
        await event.edit("please add required `LYDIA_API` env var")
        return
    if event.reply_to_msg_id is not None:
        input_str = event.pattern_match.group(1)
        reply_msg = await event.get_reply_message()
        user_id = reply_msg.from_id
        chat_id = event.chat_id
        await event.edit("Processing...")
Beispiel #3
0
# AI module using Intellivoid's Coffeehouse API by @TheRealPhoenix

from time import time, sleep
import coffeehouse as cf
from coffeehouse.exception import CoffeeHouseError as CFError

from telegram import Message, Chat, User, Update, Bot
from telegram.ext import CommandHandler, MessageHandler, Filters, run_async

from tg_bot import dispatcher, AI_API_KEY, OWNER_ID
import tg_bot.modules.sql.chatbot_sql as sql
from tg_bot.modules.helper_funcs.filters import CustomFilters

api_client = cf.API(AI_API_KEY)


@run_async
def add_chat(bot: Bot, update: Update):
    chat_id = update.effective_chat.id
    msg = update.effective_message
    is_chat = sql.is_chat(chat_id)
    if not is_chat:
        ses = api_client.create_session()
        ses_id = str(ses.id)
        expires = str(ses.expires)
        sql.set_ses(chat_id, ses_id, expires)
        msg.reply_text("AI successfully enabled for this chat!")
    else:
        msg.reply_text("AI is already enabled for this chat!")

Beispiel #4
0
 async def client_ready(self, client, db):
     self._db = db
     self._lydia = coffeehouse.API(self.config["CLIENT_KEY"])
     self._me = await client.get_me()
     # Schedule cleanups
     self._cleanup = asyncio.ensure_future(self.schedule_cleanups())
Beispiel #5
0
import coffeehouse

api_key = "<API KEY>"
api = coffeehouse.API(api_key)

session = api.create_session()
print("Session ID: {0}".format(session.id))
print("Session Available: {0}".format(str(session.available)))
print("Session Language: {0}".format(str(session.language)))
print("Session Expires: {0}".format(str(session.expires)))

while (True):
    output = api.think_thought(session.id, input("Input: "))
    print("Output: {0}".format(output))