diff --git a/docs/examples/kickstart_snippets/mistralai_.py b/docs/examples/kickstart_snippets/mistralai_.py index 02d5399..6451a4a 100644 --- a/docs/examples/kickstart_snippets/mistralai_.py +++ b/docs/examples/kickstart_snippets/mistralai_.py @@ -9,18 +9,23 @@ - Uses `yield` to continuously concatenate the parts of the response. """ +import os + import panel as pn from mistralai import Mistral, UserMessage -import os pn.extension() + def update_api_key(api_key): # Use the provided api_key or default to the environment variable pn.state.cache["aclient"] = ( - Mistral(api_key=api_key) if api_key else Mistral(api_key=os.getenv("MISTRAL_API_KEY", "")) + Mistral(api_key=api_key) + if api_key + else Mistral(api_key=os.getenv("MISTRAL_API_KEY", "")) ) + async def callback(contents: str, user: str, instance: pn.chat.ChatInterface): # memory is a list of serialized messages messages = instance.serialize() @@ -40,6 +45,7 @@ async def callback(contents: str, user: str, instance: pn.chat.ChatInterface): message += part yield message + # Input widget for the API key api_key_input = pn.widgets.PasswordInput( placeholder="Uses $MISTRAL_API_KEY if not set",