File size: 2,149 Bytes
9f99fe2
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
"""Scaffolding to host your LangChain Chatbot on Steamship and connect it to Telegram."""
from typing import List, Optional, Type

from pydantic import Field


from agent.base import LangChainAgentBot 
from telegram.ext import Updater, CommandHandler, CallbackContext, Application, ContextTypes
from telegram import Update


VERBOSE = True


class GirlFriendAIConfig():
    elevenlabs_api_key: str = Field(
        default="", description="Optional API KEY for ElevenLabs Voice Bot"
    )
    elevenlabs_voice_id: str = Field(
        default="", description="Optional voice_id for ElevenLabs Voice Bot"
    )


class GirlfriendGPT(LangChainAgentBot):
    """Deploy LangChain chatbots and connect them to Telegram."""

    token: str
    application: Application

    def __init__(self, token, application):
        super().__init__()
        self.application = application
        # application.add_handler(CommandHandler('start', hello))
        # Run the bot until the user presses Ctrl-C
        # self.application.run_polling()
        self.token = token

    # async def echo(self, update: Update, context: CallbackContext) -> None:
    #     """Echo the user message."""
    #     await update.message.reply_text(update.message.text)

    # def voice_tool(self) -> Optional[Tool]:
    #     """Return tool to generate spoken version of output text."""
    #     # return None
    #     return GenerateSpeechTool(
    #         client=self.client,
    #         voice_id=self.config.elevenlabs_voice_id,
    #         elevenlabs_api_key=self.config.elevenlabs_api_key,
    #     )

    # def get_memory(self, chat_id):
    #     if self.context and self.context.invocable_instance_handle:
    #         my_instance_handle = self.context.invocable_instance_handle
    #     else:
    #         my_instance_handle = "local-instance-handle"
    #     memory = ConversationBufferMemory(
    #         memory_key="chat_history",
    #         chat_memory=ChatMessageHistory(
    #             client=self.client, key=f"history-{chat_id}-{my_instance_handle}"
    #         ),
    #         return_messages=True,
    #     )
    #     return memory