Add internet

Hi ho to add inernet search to this code ?

import openai
import streamlit as st

st.title("ChatGPT-like clone")

openai.api_key = st.secrets["OPENAI_API_KEY"]

if "openai_model" not in st.session_state:
    st.session_state["openai_model"] = "gpt-3.5-turbo"

if "messages" not in st.session_state:
    st.session_state.messages = []

for message in st.session_state.messages:
    with st.chat_message(message["role"]):
        st.markdown(message["content"])

if prompt := st.chat_input("What is up?"):
    st.session_state.messages.append({"role": "user", "content": prompt})
    with st.chat_message("user"):
        st.markdown(prompt)

    with st.chat_message("assistant"):
        message_placeholder = st.empty()
        full_response = ""
        for response in openai.ChatCompletion.create(
            model=st.session_state["openai_model"],
            messages=[
                {"role": m["role"], "content": m["content"]}
                for m in st.session_state.messages
            ],
            stream=True,
        ):
            full_response += response.choices[0].delta.get("content", "")
            message_placeholder.markdown(full_response + "β–Œ")
        message_placeholder.markdown(full_response)
    st.session_state.messages.append({"role": "assistant", "content": full_response})

Regards

Hey @Phil1,

Can you clarify what you mean by adding internet search? Are you hoping to add a text input box where users can type their search terms and then have results from an internet search engine appear on the page?

I’d like this app (same UI):
https://doc-chat-llm.streamlit.app/?utm_medium=oembed

To chat with an AI that has the ability to connect to the internet. If I ask, β€œWho won the Women’s U.S. Open in 2022?” I receive an answer.

Regards
Phil

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.