일 년 전 · 최용빈 님의 답변 업데이트
파이썬 오류 좀 고쳐주세요 ㅠㅠ
import time import requests import streamlit as st API_BASE_URL = "http://localhost:8000/qna" # Fastapi로 api 생성 def request_chat_api(user_message: str) -> str: url = API_BASE_URL resp = requests.post( url, json={ "user_message": user_message, }, ) resp = resp.json() print(resp) return resp["answer"] def init_streamlit(): st.set_page_config(page_title='Dr. KHU', page_icon='🩺') if "messages" not in st.session_state: st.session_state.messages = [{"role": "assistant", "content": "안녕하세요! Dr.seo입니다🩺"}] # Initialize chat history if "messages" not in st.session_state: st.session_state.messages = [] # Display chat messages from history on app rerun for message in st.session_state.messages: with st.chat_message(message["role"]): st.markdown(message["content"]) def chat_main(): if message := st.chat_input(""): # Add user message to chat history st.session_state.messages.append({"role": "user", "content": message}) # Display user message in chat message container with st.chat_message("user"): st.markdown(message) # Display assistant response in chat message container assistant_response = request_chat_api(message) with st.chat_message("assistant"): message_placeholder = st.empty() full_response = "" for lines in assistant_response.split("\n"): for chunk in lines.split(): full_response += chunk + " " time.sleep(0.05) # Add a blinking cursor to simulate typing message_placeholder.markdown(full_response) full_response += "\n" message_placeholder.markdown(full_response) # Add assistant response to chat history st.session_state.messages.append( {"role": "assistant", "content": full_response} ) if __name__ == "__main__": init_streamlit() chat_main() 이 코드를 실행시키면 자꾸 AttributeError: st.session_state has no attribute "messages". Did you forget to initialize it? More info: https://docs.streamlit.io/library/advanced-features/session-state#initialization 라고 뜨네요..
개발자
#파이썬
#python
답변 2
댓글 1
보충이 필요해요 2
조회 352
2년 전 · 커리어리 AI 봇 님의 새로운 답변
마크다운 적용이 안됩니다 ㅠ
import React from "react"; import { ReactHTML } from "react"; import ReactMarkdown from 'react-markdown'; import { useState } from 'react'; const asdf = (props) => { const markdownContent = ` # 시작 블라블라블라 - 순서 없는 목록 1 - 목록 1.1 - 목록 1.2 - 순서 없는 목록 2 ` return ( <Container> <ContainerContent> <ReactMarkdown>{markdownContent}</ReactMarkdown> </ContainerContent> </Container> ) } export default asdf; const markdownContent ='' 안에 마크다운 양식이 적용이안됩니다 ㅠㅠ 왜이럴까여...
개발자
#react
#markdown
답변 2
댓글 0
보충이 필요해요 1
조회 820
2년 전 · 커리어리 AI 봇 님의 새로운 답변
리엑트에서 마크다운 형식 실행하기
const [markdownContent, setMArkdownContent ] = useState() ()안에 마크다운 문법 텍스트를 넣으면 문법이 꺠져서 실행됨 ><br>
개발자
#react
#markdown
답변 2
댓글 4
추천해요 1
보충이 필요해요 1
조회 695