Spaces:
Running
Running
Commit
ยท
26b05fb
1
Parent(s):
07b635d
Update main.py
Browse files
main.py
CHANGED
|
@@ -79,16 +79,28 @@ async def demo():
|
|
| 79 |
return HTMLResponse(content=html_content, status_code=200)
|
| 80 |
|
| 81 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 82 |
@app.get("/stream")
|
| 83 |
async def chat(prompt = "Once upon a time there was a "):
|
| 84 |
-
tokens = llm(prompt)
|
| 85 |
-
async def server_sent_events(chat_chunks):
|
| 86 |
yield prompt
|
| 87 |
for chat_chunk in llm.generate(chat_chunks):
|
| 88 |
yield llm.detokenize(chat_chunk)
|
| 89 |
yield ""
|
| 90 |
|
| 91 |
-
return EventSourceResponse(server_sent_events(tokens))
|
| 92 |
|
| 93 |
@app.post("/v1/chat/completions")
|
| 94 |
async def chat(request: ChatCompletionRequest, response_mode=None):
|
|
|
|
| 79 |
return HTMLResponse(content=html_content, status_code=200)
|
| 80 |
|
| 81 |
|
| 82 |
+
@app.get("/v1")
|
| 83 |
+
async def flow(prompt = ""):
|
| 84 |
+
completion = llm(prompt)
|
| 85 |
+
async def server_sent_events(chat_chunks):
|
| 86 |
+
yield prompt
|
| 87 |
+
for chat_chunk in chat_chunks:
|
| 88 |
+
yield chat_chunk
|
| 89 |
+
yield ""
|
| 90 |
+
|
| 91 |
+
return EventSourceResponse(server_sent_events(completion))
|
| 92 |
+
|
| 93 |
+
|
| 94 |
@app.get("/stream")
|
| 95 |
async def chat(prompt = "Once upon a time there was a "):
|
| 96 |
+
tokens = llm.tokenize(prompt)
|
| 97 |
+
async def server_sent_events(chat_chunks, llm):
|
| 98 |
yield prompt
|
| 99 |
for chat_chunk in llm.generate(chat_chunks):
|
| 100 |
yield llm.detokenize(chat_chunk)
|
| 101 |
yield ""
|
| 102 |
|
| 103 |
+
return EventSourceResponse(server_sent_events(tokens, llm))
|
| 104 |
|
| 105 |
@app.post("/v1/chat/completions")
|
| 106 |
async def chat(request: ChatCompletionRequest, response_mode=None):
|