|
|
import os |
|
|
from dotenv import load_dotenv |
|
|
load_dotenv() |
|
|
|
|
|
import chainlit as cl |
|
|
from phi.assistant import Assistant |
|
|
from phi.tools.duckduckgo import DuckDuckGo |
|
|
from phi.llm.openai import OpenAIChat |
|
|
from phi.tools.yfinance import YFinanceTools |
|
|
from src.tools.coin_data_toolkit import CryptoDataTools |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@cl.set_starters |
|
|
async def set_starters(): |
|
|
return [ |
|
|
cl.Starter( |
|
|
label="Create a crypto wallet for me", |
|
|
message="create a crypto wallet for me", |
|
|
icon="/public/wallet-svgrepo-com.svg", |
|
|
), |
|
|
|
|
|
cl.Starter( |
|
|
label="Latest News on defi, crypto and solana", |
|
|
message="What news are currentlly trending on defi.", |
|
|
icon="/public/news-svgrepo-com.svg", |
|
|
), |
|
|
cl.Starter( |
|
|
label="Get price of BTC, ETH and PEPE", |
|
|
message="Get me the Price of BTC, ETH and PEPE", |
|
|
icon="/public/coins-electronics-svgrepo-com.svg", |
|
|
), |
|
|
cl.Starter( |
|
|
label="Get trending stocks", |
|
|
message="Get latest stock", |
|
|
icon="/public/stockchart-svgrepo-com.svg", |
|
|
) |
|
|
] |
|
|
|
|
|
|
|
|
@cl.on_chat_start |
|
|
def start(): |
|
|
is_dev_mode = True if os.getenv("DEV_MODE") else False |
|
|
|
|
|
|
|
|
cxbt_assistant = Assistant( |
|
|
llm=OpenAIChat(model="gpt-4o"), |
|
|
tools=[CryptoDataTools(), DuckDuckGo(), YFinanceTools(stock_price=True)], |
|
|
show_tool_calls= is_dev_mode, |
|
|
markdown=True, |
|
|
) |
|
|
|
|
|
|
|
|
cl.user_session.set("agent", cxbt_assistant) |
|
|
|
|
|
@cl.on_message |
|
|
async def main(message: cl.Message): |
|
|
|
|
|
agent = cl.user_session.get("agent") |
|
|
|
|
|
|
|
|
|
|
|
response = "" |
|
|
for delta in agent.run(message.content, stream=True): |
|
|
response += delta |
|
|
|
|
|
|
|
|
await cl.Message(content=response).send() |
|
|
|
|
|
|
|
|
if __name__ == "__main__": |
|
|
cl.run() |
|
|
|