()
| 3 | import json |
| 4 | |
| 5 | def main(): |
| 6 | st.set_page_config(page_title="g1 prototype", page_icon="🧠", layout="wide") |
| 7 | |
| 8 | st.title("g1: Using Llama-3.1 70b on Groq to create o1-like reasoning chains") |
| 9 | |
| 10 | st.markdown(""" |
| 11 | This is an early prototype of using prompting to create o1-like reasoning chains to improve output accuracy. It is not perfect and accuracy has yet to be formally evaluated. It is powered by Groq so that the reasoning step is fast! |
| 12 | |
| 13 | Open source [repository here](https://github.com/bklieger-groq) |
| 14 | """) |
| 15 | |
| 16 | # Text input for user query |
| 17 | user_query = st.text_input("Enter your query:", placeholder="e.g., How many 'R's are in the word strawberry?") |
| 18 | |
| 19 | if user_query: |
| 20 | st.write("Generating response...") |
| 21 | |
| 22 | # Create empty elements to hold the generated text and total time |
| 23 | response_container = st.empty() |
| 24 | time_container = st.empty() |
| 25 | |
| 26 | # Generate and display the response |
| 27 | for steps, total_thinking_time in generate_response(user_query): |
| 28 | with response_container.container(): |
| 29 | for i, (title, content, thinking_time) in enumerate(steps): |
| 30 | # Ensure content is a string |
| 31 | if not isinstance(content, str): |
| 32 | content = json.dumps(content) |
| 33 | if title.startswith("Final Answer"): |
| 34 | st.markdown(f"### {title}") |
| 35 | if '```' in content: |
| 36 | parts = content.split('```') |
| 37 | for index, part in enumerate(parts): |
| 38 | if index % 2 == 0: |
| 39 | st.markdown(part) |
| 40 | else: |
| 41 | if '\n' in part: |
| 42 | lang_line, code = part.split('\n', 1) |
| 43 | lang = lang_line.strip() |
| 44 | else: |
| 45 | lang = '' |
| 46 | code = part |
| 47 | st.code(part, language=lang) |
| 48 | else: |
| 49 | st.markdown(content.replace('\n', '<br>'), unsafe_allow_html=True) |
| 50 | else: |
| 51 | with st.expander(title, expanded=True): |
| 52 | st.markdown(content.replace('\n', '<br>'), unsafe_allow_html=True) |
| 53 | |
| 54 | # Only show total time when it's available at the end |
| 55 | if total_thinking_time is not None: |
| 56 | time_container.markdown(f"**Total thinking time: {total_thinking_time:.2f} seconds**") |
| 57 | |
| 58 | if __name__ == "__main__": |
| 59 | main() |
no test coverage detected