app.py 815 B

1234567891011121314151617181920212223242526272829303132333435
  1. import chainlit as cl
  2. from embedchain import Pipeline as App
  3. import os
  4. os.environ["OPENAI_API_KEY"] = "sk-xxx"
  5. @cl.on_chat_start
  6. async def on_chat_start():
  7. app = App.from_config(config={
  8. 'app': {
  9. 'config': {
  10. 'name': 'chainlit-app'
  11. }
  12. },
  13. 'llm': {
  14. 'config': {
  15. 'stream': True,
  16. }
  17. }
  18. })
  19. # import your data here
  20. app.add("https://www.forbes.com/profile/elon-musk/")
  21. app.collect_metrics = False
  22. cl.user_session.set("app", app)
  23. @cl.on_message
  24. async def on_message(message: cl.Message):
  25. app = cl.user_session.get("app")
  26. msg = cl.Message(content="")
  27. for chunk in await cl.make_async(app.chat)(message.content):
  28. await msg.stream_token(chunk)
  29. await msg.send()