Chainlit / cookbook

Chainlit's cookbook repo
https://github.com/Chainlit/chainlit
661 stars 245 forks source link

In Willy Douhard's bigquery cookbook example - missing to_openai() method #105

Open johnlabuyfoy1024 opened 2 months ago

johnlabuyfoy1024 commented 2 months ago

I have configured Google Cloud successfully however, when I ran the bigquery Python example from the Cookbook with my first text question, I get the following error: 2024-04-30 14:17:52 - 'dict' object has no attribute 'to_openai' Traceback (most recent call last): File "C:\Users\johnl\PycharmProjects\bigquery\vnew\Lib\site-packages\chainlit\utils.py", line 39, in wrapper return await user_function(params_values) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "C:\Users\johnl\PycharmProjects\bigquery\app.py", line 139, in main await chain(message.content) File "C:\Users\johnl\PycharmProjects\bigquery\vnew\Lib\site-packages\chainlit\step.py", line 84, in async_wrapper result = await func(*args, *kwargs) ^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "C:\Users\johnl\PycharmProjects\bigquery\app.py", line 131, in chain sql_query = await gen_query(human_query) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "C:\Users\johnl\PycharmProjects\bigquery\vnew\Lib\site-packages\chainlit\step.py", line 84, in async_wrapper result = await func(args, kwargs) ^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "C:\Users\johnl\PycharmProjects\bigquery\app.py", line 57, in gen_query messages=[m.to_openai() for m in current_step.generation.messages], ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "C:\Users\johnl\PycharmProjects\bigquery\app.py", line 57, in messages=[m.to_openai() for m in current_step.generation.messages], ^^^^^^^^^^^ AttributeError: 'dict' object has no attribute 'to_openai'

From this code snippet:

# Call OpenAI and stream the message
stream_resp = await openai_client.chat.completions.create(
    messages=[m.to_openai() for m in current_step.generation.messages],
    stream=True,
    **settings
)

Any help would be appreciated - I like this example very much! Please advise & thanks.