Skip to content

Commit

Permalink
lint
Browse files Browse the repository at this point in the history
  • Loading branch information
ahuang11 committed Oct 4, 2024
1 parent 74e27e2 commit 6a48450
Showing 1 changed file with 8 additions and 2 deletions.
10 changes: 8 additions & 2 deletions docs/examples/kickstart_snippets/mistralai_.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand All @@ -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",
Expand Down

0 comments on commit 6a48450

Please sign in to comment.