Chainlitとは
ChainlitはPythonで簡単にChat形式のアプリケーションを開発できるフレームワーク。
https://github.com/Chainlit/chainlit?tab=readme-ov-file
Chat-GPTやそのたLLMのモデルをアプリに組み込むことも簡単にできるみたい。
動かしてみた
チュートリアルに従ってとりあえず動かしてみました。
まずはインストール
pip install chainlit
ドキュメント通りサンプルコード(app.py)を書く
import chainlit as cl
@cl.step
def tool():
    return "Response from the tool!"
@cl.on_message  # this function will be called every time a user inputs a message in the UI
async def main(message: cl.Message):
    """
    This function is called every time a user inputs a message in the UI.
    It sends back an intermediate response from the tool, followed by the final answer.
    Args:
        message: The user's message.
    Returns:
        None.
    """
    # Call the tool
    tool()
    # Send the final answer.
    await cl.Message(content="This is the final answer").send()
ちなみにこのコードはひたらすらThis is the final answerと返すだけのアプリ。
本来ならtool関数などに処理を書く。
このアプリを起動する。
chainlit run app.py -w
-wはウォッチオプション。ソースコードが変更されるたびに自動的にアプリケーションが再起動される。
以下のようなアプリが起動する。

  
  
  
  

コメント