guidance
guidance copied to clipboard
Running guidance within Streamlit
Hello,
Like #11 , so I suppose the resolution will be similar. Creating this for future reference for other searches.
Pure intuition, Streamlit spawns worker threads to run the Python Script in, which may be decorrelated from any Asyncio loop you would start on initialization on the main thread through nest_asyncio. Though just creating/setting an asyncio loop in the script also doesn't register correctly :/
Using guidance==0.0.44 and streamlit==1.22.0
"""Run with `streamlit run app.py`"""
import guidance
import streamlit as st
#import asyncio
#loop = asyncio.new_event_loop()
#asyncio.set_event_loop(loop)
st.title("Test Guidance")
guidance.llm = guidance.llms.OpenAI("text-davinci-003")
prompt = guidance('''The best thing about the beach is {{~gen 'best' temperature=0.7 max_tokens=7}}''')
st.write(prompt())
File "guidance\__init__.py", line 15, in <module>
nest_asyncio.apply()
File "nest_asyncio.py", line 16, in apply
loop = loop or asyncio.get_event_loop()
File "nest_asyncio.py", line 45, in _get_event_loop
loop = events.get_event_loop_policy().get_event_loop()
File "lib\asyncio\events.py", line 656, in get_event_loop
raise RuntimeError('There is no current event loop in thread %r.'
RuntimeError: There is no current event loop in thread 'ScriptRunner.scriptThread'.
Have a nice day