matthoffner commited on
Commit
5deafe7
ยท
1 Parent(s): a8d1661

Update main.py

Browse files
Files changed (1) hide show
  1. main.py +6 -9
main.py CHANGED
@@ -57,7 +57,7 @@ async def demo():
57
  justify-content: center;
58
  }
59
 
60
- #logs {
61
  align-items: center;
62
  background-color: #fff0db;
63
  box-shadow:
@@ -74,10 +74,7 @@ async def demo():
74
  </head>
75
 
76
  <body>
77
-
78
- <h1>StoryWriter Demo</h1>
79
- <div id="content">
80
- </div>
81
 
82
  <script>
83
  var source = new EventSource("https://matthoffner-storywriter.hf.space/stream");
@@ -94,14 +91,14 @@ async def demo():
94
 
95
  @app.get("/stream")
96
  async def chat(prompt = "Once upon a time there was a "):
97
- completion = llm(prompt)
98
  async def server_sent_events(chat_chunks):
99
  yield prompt
100
- for chat_chunk in chat_chunks:
101
- yield chat_chunk
102
  yield ""
103
 
104
- return EventSourceResponse(server_sent_events(completion))
105
 
106
  @app.post("/v1/chat/completions")
107
  async def chat(request: ChatCompletionRequest, response_mode=None):
 
57
  justify-content: center;
58
  }
59
 
60
+ #content {
61
  align-items: center;
62
  background-color: #fff0db;
63
  box-shadow:
 
74
  </head>
75
 
76
  <body>
77
+ <div id="content"></div>
 
 
 
78
 
79
  <script>
80
  var source = new EventSource("https://matthoffner-storywriter.hf.space/stream");
 
91
 
92
  @app.get("/stream")
93
  async def chat(prompt = "Once upon a time there was a "):
94
+ tokens = llm(prompt)
95
  async def server_sent_events(chat_chunks):
96
  yield prompt
97
+ for chat_chunk in llm.generate(chat_chunks):
98
+ yield llm.detokenize(chat_chunk)
99
  yield ""
100
 
101
+ return EventSourceResponse(server_sent_events(tokens))
102
 
103
  @app.post("/v1/chat/completions")
104
  async def chat(request: ChatCompletionRequest, response_mode=None):