Skip to content

Commit

Permalink
fix: JSON not serializable fix in using_chainlit.py (#1204)
Browse files Browse the repository at this point in the history
* Update using_chainlit.py

> JSON not serializable fix

* lint: fix lint

* chore: fix typo

---------

Co-authored-by: Gabriele Venturi <[email protected]>
  • Loading branch information
getmykhan and gventuri authored Jun 5, 2024
1 parent ecbea99 commit bdd5ce4
Showing 1 changed file with 23 additions and 16 deletions.
39 changes: 23 additions & 16 deletions examples/using_chainlit.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,17 +9,29 @@

import os

import chainlit as cl
import pandas as pd

from pandasai import SmartDataframe

import chainlit as cl

# Sample DataFrame
sales_by_country = pd.DataFrame({
"country": ["United States", "United Kingdom", "France", "Germany", "Italy", "Spain", "Canada", "Australia", "Japan", "China"],
"sales": [5000, 3200, 2900, 4100, 2300, 2100, 2500, 2600, 4500, 7000]
})
sales_by_country = pd.DataFrame(
{
"country": [
"United States",
"United Kingdom",
"France",
"Germany",
"Italy",
"Spain",
"Canada",
"Australia",
"Japan",
"China",
],
"sales": [5000, 3200, 2900, 4100, 2300, 2100, 2500, 2600, 4500, 7000],
}
)


# By default, unless you choose a different LLM, it will use BambooLLM.
Expand All @@ -29,31 +41,26 @@
# Create a PandasAI SmartDataframe from pandas DataFrame
df = SmartDataframe(sales_by_country)

# This function is called for each chat/reponse cycle

# This function is called for each chat/response cycle
@cl.on_message
async def on_message(message: cl.Message):

# send empty content response to display a loader animation
msg = cl.Message(content="")
await msg.send()


# Example:
# Example:
# User Question: Which are the top 5 countries by sales?
# LLM Response: China, United States, Japan, Germany, Australia


# what did the user type for a question?
user_question = message.content

# feed the llm the question and get the response
llm_response = df.chat(user_question)


# load the response into chainlit
msg.content=llm_response
msg.content = str(llm_response)

# send the response
await msg.update()


0 comments on commit bdd5ce4

Please sign in to comment.