SSEclient #40
-
I can't seem to be able to get streaming to work with sseclient in python. I must be doing something wrong. Here is my server side: @app.post("/", response_model=CompletionResponse)
async def completion(request: CompletionRequest = Body(...)):
llm = OpenAI(
openai_api_base=api_base, openai_api_key=api_key, streaming=True, verbose=True
)
template = "You are a helpful assistant.\
\n\n### Instruction:\n{question}\n\n### Response:\n"
prompt = PromptTemplate(template=template, input_variables=["question"])
llm_chain = LLMChain(prompt=prompt, llm=llm)
return StreamingResponse.from_chain(
llm_chain, request.prompt, media_type="text/event-stream"
) And here is the client: prompt = input("Enter prompt: ")
print("Assistant:", end=" ")
url = "http://localhost:7000/"
response = requests.post(url, stream=True, json={"prompt": prompt}, headers={"accept": "text/event-stream", "Content-Type": "application/json"})
sseClient = sseclient.SSEClient(response)
for event in sseClient.events():
print("received event") What's happening is that I don't seem to be receiving events. It works fine if I use curl like so
|
Beta Was this translation helpful? Give feedback.
Answered by
rodrigo-pedro
May 13, 2023
Replies: 2 comments
-
Nevermind i just realized you have a gradio example. It works with iter_content |
Beta Was this translation helpful? Give feedback.
0 replies
Answer selected by
ajndkr
-
@rodrigo-pedro i will update the docs to add an example for client side code. |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Nevermind i just realized you have a gradio example. It works with iter_content