Spaces:
Running
Running
daniel-cerebras
commited on
Update app.py
Browse files
app.py
CHANGED
@@ -114,6 +114,7 @@ def generate_response(api_key: str, prompt: str) -> Generator[Tuple[List[Tuple[s
|
|
114 |
def respond(api_key: str, message: str, history: List[Tuple[str, str]]) -> Generator[Tuple[List[Tuple[str, str]], str], None, None]:
|
115 |
"""
|
116 |
Generator function to handle responses and yield updates for streaming.
|
|
|
117 |
"""
|
118 |
if not api_key:
|
119 |
yield history, "Please provide a valid Cerebras API key."
|
@@ -126,9 +127,11 @@ def respond(api_key: str, message: str, history: List[Tuple[str, str]]) -> Gener
|
|
126 |
conversation = history.copy()
|
127 |
for title, content in steps[len(conversation):]:
|
128 |
if title.startswith("Step") or title == "Final Answer":
|
129 |
-
|
|
|
130 |
else:
|
131 |
-
|
|
|
132 |
yield conversation, f"**Total API call time:** {total_time:.2f} seconds\n**Completion tokens:** {total_completion_tokens}\n**Overall average tokens/s:** {avg_tokens_per_second:.2f}"
|
133 |
|
134 |
def main():
|
@@ -180,4 +183,4 @@ def main():
|
|
180 |
demo.launch()
|
181 |
|
182 |
if __name__ == "__main__":
|
183 |
-
main()
|
|
|
114 |
def respond(api_key: str, message: str, history: List[Tuple[str, str]]) -> Generator[Tuple[List[Tuple[str, str]], str], None, None]:
|
115 |
"""
|
116 |
Generator function to handle responses and yield updates for streaming.
|
117 |
+
The conversation will now show the newest message at the top.
|
118 |
"""
|
119 |
if not api_key:
|
120 |
yield history, "Please provide a valid Cerebras API key."
|
|
|
127 |
conversation = history.copy()
|
128 |
for title, content in steps[len(conversation):]:
|
129 |
if title.startswith("Step") or title == "Final Answer":
|
130 |
+
# Prepend new messages to display newest first
|
131 |
+
conversation.insert(0, (title, content))
|
132 |
else:
|
133 |
+
# Prepend any other messages
|
134 |
+
conversation.insert(0, (title, content))
|
135 |
yield conversation, f"**Total API call time:** {total_time:.2f} seconds\n**Completion tokens:** {total_completion_tokens}\n**Overall average tokens/s:** {avg_tokens_per_second:.2f}"
|
136 |
|
137 |
def main():
|
|
|
183 |
demo.launch()
|
184 |
|
185 |
if __name__ == "__main__":
|
186 |
+
main()
|