SimaFarazi's picture
add new directory for stream app with rag
605fc97
raw
history blame contribute delete
856 Bytes
from langserve import RemoteRunnable
# Hit our enpoint with specified rout
# If we put /simple/stream, it complains; because chain.stream will hit /simple/stream endpoint
url = "https://simafarazi-backend-c.hf.space/history"
chain = RemoteRunnable(url) #Client for iteracting with LangChain runnables that are hosted as LangServe endpoints
stream = chain.stream(input={"question":"among these cities, which one is better to find a job for machine learning engineer?",
"username": "Sima"}) # .stream() and .invoke() are standard methods to interact with hosted runnables
for chunk in stream: # Each chunk corresponds to a token/word
#end="": prints worlds one after each other, an not in a separate lines
#flush=True: prints world to the screen immidiately without any buffer
print(chunk, end="", flush=True)