代码之家  ›  专栏  ›  技术社区  ›  Sharif Amlani

如何将Langchain的人工工具集成到Streamlight中

  •  0
  • Sharif Amlani  · 技术社区  · 2 年前

    我正在使用Langchain的人工工具作为我的应用程序的一部分。然而,我很难将其集成到streamlight中。

    我主要是想改变 input_func 函数中的参数:

    Human_Tool =load_tools(["human"], lm=llm, input_func=get_input)
    

    我尝试了很多不同的方法,但都没有成功。

    以下是我尝试过的一些方法:

       import streamlit as st
    
        def get_input() -> str:
            st.write("Insert your text below.")
            
            # Updated this line to include a label and hide it using label_visibility
            user_input = st.text_area(label="Your Text", value="", height=100, key=None, help=None, on_change=None, args=None, kwargs=None, label_visibility="hidden")
            
            submit_button = st.button("Submit")
    
            if submit_button:
                return user_input.strip()  # This will return the text entered by the user
            
            if not submit_button:
                with st.empty():
                    for remaining in range(3600, 0, -1):
                        st.write(f"You have {remaining//60} minutes and {remaining%60} seconds to enter the text.")
                        time.sleep(1)
                        st.empty()
    
            return ""  # Returning empty if no input after an hour or not submitted
    
    

    上面的代码打开一个streamlight框,它接受用户的输入,但不将用户的输入传递给代理。

    import streamlit as st
    import uuid
    
    def get_input() -> str:
        unique_key = str(uuid.uuid4())  
    
        user_input = st.text_area(
            "Insert your text below:",
            key=f"uniqueTextAreaKey_{unique_key}",
            value="",
            height=200,
        )
    
        if st.button("Submit", key=f"uniqueButtonKey_{unique_key}"):
            if user_input:  # check if user input is not empty
                st.session_state['user_input'] = user_input
                st.session_state['submitted'] = True
    
                st.success("Input submitted successfully!")
                return user_input.strip()
    
        elif 'submitted' in st.session_state and st.session_state['submitted']:
            st.success("Input already submitted.")
            return st.session_state['user_input'].strip()
    
        else:
            st.warning("Please enter text and press submit.")
    
        return ""
    

    这段代码还打开了一个流式文本框,但陷入了无限循环。

    我想问可能是什么 get_input langchains的Human Tool的函数,该函数与streamlight成功集成。

    0 回复  |  直到 2 年前