Spaces:
Running
Running
matthoffner
commited on
Commit
ยท
716d802
1
Parent(s):
acba6f4
Update main.py
Browse files
main.py
CHANGED
@@ -32,11 +32,22 @@ async def index():
|
|
32 |
class ChatCompletionRequest(BaseModel):
|
33 |
prompt: str
|
34 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
35 |
@app.post("/v1/chat/completions")
|
36 |
async def chat(request: ChatCompletionRequest, response_mode=None):
|
37 |
completion = llm(request.prompt)
|
38 |
async def server_sent_events(chat_chunks):
|
39 |
for chat_chunk in chat_chunks:
|
|
|
40 |
yield dict(data=json.dumps(chat_chunk))
|
41 |
yield dict(data="[DONE]")
|
42 |
|
|
|
32 |
class ChatCompletionRequest(BaseModel):
|
33 |
prompt: str
|
34 |
|
35 |
+
@app.get("/stream")
|
36 |
+
async def chat(prompt = "Once upon a time there was a "):
|
37 |
+
completion = llm(prompt)
|
38 |
+
async def server_sent_events(chat_chunks):
|
39 |
+
for chat_chunk in chat_chunks:
|
40 |
+
yield dict(data=json.dumps(chat_chunk))
|
41 |
+
yield dict(data="[DONE]")
|
42 |
+
|
43 |
+
return EventSourceResponse(server_sent_events(completion))
|
44 |
+
|
45 |
@app.post("/v1/chat/completions")
|
46 |
async def chat(request: ChatCompletionRequest, response_mode=None):
|
47 |
completion = llm(request.prompt)
|
48 |
async def server_sent_events(chat_chunks):
|
49 |
for chat_chunk in chat_chunks:
|
50 |
+
print(chat_chunk)
|
51 |
yield dict(data=json.dumps(chat_chunk))
|
52 |
yield dict(data="[DONE]")
|
53 |
|