1 line
5.5 KiB
JSON
1 line
5.5 KiB
JSON
{"repo": "cameronjoejones/deepseek-streamlit", "files": {"app.py": {"556dcc0d6f2cfc124c525dfaec493221290e6e0d": {"t": 1785745979.3942616, "n": 2488, "h": "3b296ff32732273e", "c": "import streamlit as st\nfrom openai import OpenAI\n\n# session state for chat history\nif \"messages\" not in st.session_state:\n st.session_state.messages = [\n {\"role\": \"assistant\", \"content\": \"Hello! How can I help you today?\"}\n ]\n\napi_key = st.secrets[\"api_key\"]\n\n\ndef deepseek_chat(api_key: str, messages: list) -> str:\n try:\n client = OpenAI(api_key=api_key, base_url=\"https://api.deepseek.com\")\n response = client.chat.completions.create(\n model=\"deepseek-chat\",\n messages=[\n {\"role\": \"system\", \"content\": \"You are a helpful assistant\"},\n *messages\n ],\n stream=False\n )\n return response.choices[0].message.content\n except Exception as e:\n st.error(f\"Error occurred: {str(e)}\")\n return \"\"\n\n\ndef main():\n st.title('🤖 DeepSeek Chatbot')\n\n with st.sidebar:\n st.header(\"📚 User Guide\")\n st.markdown(\"\"\"\n ### How to Use\n 1. **Start Chatting**: Type your message in the input box at the bottom of the chat\n 2. **Continue Conversation**: The chatbot remembers your conversation, so you can ask follow-up questions\n 3. **View History**: Scroll up to see your chat history\n \n ### Tips\n - Be specific with your questions\n - Ask follow-up questions for clarification\n - Use the reset button to start a fresh conversation\n \n ### Need Help?\n If you encounter any issues, try resetting the chat using the button below.\n \"\"\")\n\n if st.button(\"Reset Chat\"):\n st.session_state.messages = [\n {\"role\": \"assistant\", \"content\": \"Hello! How can I help you today?\"}\n ]\n st.rerun()\n\n for message in st.session_state.messages:\n with st.chat_message(message[\"role\"]):\n st.write(message[\"content\"])\n\n if prompt := st.chat_input(\"What's on your mind?\"):\n st.session_state.messages.append({\"role\": \"user\", \"content\": prompt})\n\n with st.chat_message(\"user\"):\n st.write(prompt)\n\n with st.chat_message(\"assistant\"):\n with st.spinner(\"Thinking...\"):\n response = deepseek_chat(api_key, st.session_state.messages)\n if response:\n st.write(response)\n st.session_state.messages.append(\n {\"role\": \"assistant\", \"content\": response})\n\n\nif __name__ == \"__main__\":\n main()\n"}, "d376360e5cf1431ce32f7b96d4738e6e3029e8d7": {"t": 1785758446.5176773, "n": 2488, "h": "3b296ff32732273e", "c": "import streamlit as st\nfrom openai import OpenAI\n\n# session state for chat history\nif \"messages\" not in st.session_state:\n st.session_state.messages = [\n {\"role\": \"assistant\", \"content\": \"Hello! How can I help you today?\"}\n ]\n\napi_key = st.secrets[\"api_key\"]\n\n\ndef deepseek_chat(api_key: str, messages: list) -> str:\n try:\n client = OpenAI(api_key=api_key, base_url=\"https://api.deepseek.com\")\n response = client.chat.completions.create(\n model=\"deepseek-chat\",\n messages=[\n {\"role\": \"system\", \"content\": \"You are a helpful assistant\"},\n *messages\n ],\n stream=False\n )\n return response.choices[0].message.content\n except Exception as e:\n st.error(f\"Error occurred: {str(e)}\")\n return \"\"\n\n\ndef main():\n st.title('🤖 DeepSeek Chatbot')\n\n with st.sidebar:\n st.header(\"📚 User Guide\")\n st.markdown(\"\"\"\n ### How to Use\n 1. **Start Chatting**: Type your message in the input box at the bottom of the chat\n 2. **Continue Conversation**: The chatbot remembers your conversation, so you can ask follow-up questions\n 3. **View History**: Scroll up to see your chat history\n \n ### Tips\n - Be specific with your questions\n - Ask follow-up questions for clarification\n - Use the reset button to start a fresh conversation\n \n ### Need Help?\n If you encounter any issues, try resetting the chat using the button below.\n \"\"\")\n\n if st.button(\"Reset Chat\"):\n st.session_state.messages = [\n {\"role\": \"assistant\", \"content\": \"Hello! How can I help you today?\"}\n ]\n st.rerun()\n\n for message in st.session_state.messages:\n with st.chat_message(message[\"role\"]):\n st.write(message[\"content\"])\n\n if prompt := st.chat_input(\"What's on your mind?\"):\n st.session_state.messages.append({\"role\": \"user\", \"content\": prompt})\n\n with st.chat_message(\"user\"):\n st.write(prompt)\n\n with st.chat_message(\"assistant\"):\n with st.spinner(\"Thinking...\"):\n response = deepseek_chat(api_key, st.session_state.messages)\n if response:\n st.write(response)\n st.session_state.messages.append(\n {\"role\": \"assistant\", \"content\": response})\n\n\nif __name__ == \"__main__\":\n main()\n"}}}} |