I have a callback which looks something like this.
When I comment out the background=
and running=
lines, the callback works and outputs as expected.
When I have the background=
and running=
lines activated, the callback does not go past the OpenAI query line, and the button is no longer disabled (indicating that the callback has finished).
I do have other background callbacks working in the same app.
import dash
from dash.dependencies import Input, Output, State
import openai
@app.callback(
Output('data-store', 'data'),
State('textfield1', 'value'),
State('textfield2, 'value'),
Input('button', 'n_clicks'),
prevent_initial_call=True,
background=True,
running=[ # Format: Output, While running, When complete
(Output('button', 'disabled'), True, False),
]
)
def generate_output(text1, text2, n_clicks):
if n_clicks is not None:
output = {"text1": text1, "text2": text2}
model = "text-davinci-003"
prompt = "xxx"
print("generating a response")
response = openai.Completion.create(engine=model, prompt=prompt, max_tokens=2000)
print("response generated")
return response
return no_update
The background callback manager is:
cache = diskcache.Cache("./cache")
background_callback_manager = DiskcacheManager(cache)