Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
@@ -25,10 +25,6 @@ VOTING_LABELS = [
|
|
25 |
]
|
26 |
|
27 |
|
28 |
-
def set_api_key(api_key):
|
29 |
-
os.environ["MISTRAL_API_KEY"] = api_key
|
30 |
-
|
31 |
-
|
32 |
async def respond(content, user, instance):
|
33 |
"""
|
34 |
Respond to the user in the chat interface.
|
@@ -48,8 +44,13 @@ async def respond(content, user, instance):
|
|
48 |
messages = instance.serialize()
|
49 |
messages.append({"role": "user", "content": content})
|
50 |
|
|
|
|
|
|
|
|
|
|
|
51 |
response = await acompletion(
|
52 |
-
model=model, messages=messages, stream=True, max_tokens=128
|
53 |
)
|
54 |
|
55 |
message = None
|
@@ -135,7 +136,6 @@ with sqlite3.connect("voting_counts.db") as conn:
|
|
135 |
api_key_input = pn.widgets.PasswordInput(
|
136 |
placeholder="Mistral API Key", stylesheets=[".bk-input {color: black};"]
|
137 |
)
|
138 |
-
pn.bind(set_api_key, api_key_input, watch=True)
|
139 |
|
140 |
# main
|
141 |
tabs = pn.Tabs()
|
@@ -148,6 +148,7 @@ chat_interface_kwargs = dict(
|
|
148 |
show_clear=False,
|
149 |
show_stop=False,
|
150 |
show_button_name=False,
|
|
|
151 |
)
|
152 |
header_a = pn.pane.Markdown("## Model: A")
|
153 |
chat_interface_a = pn.chat.ChatInterface(
|
|
|
25 |
]
|
26 |
|
27 |
|
|
|
|
|
|
|
|
|
28 |
async def respond(content, user, instance):
|
29 |
"""
|
30 |
Respond to the user in the chat interface.
|
|
|
44 |
messages = instance.serialize()
|
45 |
messages.append({"role": "user", "content": content})
|
46 |
|
47 |
+
if api_key_input.value:
|
48 |
+
api_key = api_key_input.value
|
49 |
+
else:
|
50 |
+
api_key = os.environ.get("MISTRAL_API_KEY")
|
51 |
+
|
52 |
response = await acompletion(
|
53 |
+
model=model, messages=messages, stream=True, max_tokens=128, api_key=api_key
|
54 |
)
|
55 |
|
56 |
message = None
|
|
|
136 |
api_key_input = pn.widgets.PasswordInput(
|
137 |
placeholder="Mistral API Key", stylesheets=[".bk-input {color: black};"]
|
138 |
)
|
|
|
139 |
|
140 |
# main
|
141 |
tabs = pn.Tabs()
|
|
|
148 |
show_clear=False,
|
149 |
show_stop=False,
|
150 |
show_button_name=False,
|
151 |
+
callback_exception="verbose",
|
152 |
)
|
153 |
header_a = pn.pane.Markdown("## Model: A")
|
154 |
chat_interface_a = pn.chat.ChatInterface(
|