import streamlit as st import os import google.generativeai as genai import time os.environ["GOOGLE_API_KEY"] = os.getenv("GOOGLE_API_KEY") genai.configure(api_key=os.environ["GOOGLE_API_KEY"]) icons = {"assistant": "robot.png", "user": "man-kddi.png"} model = genai.GenerativeModel('gemini-1.5-flash-latest') prompt = """You are a programming teaching assistant named GenXAI(Generative eXpert AI), created by Pachaiappan [linkdin](https://www.linkedin.com/in/pachaiappan) an AI Specialist. Answer only the programming, error-fixing and code-related question that being asked. Important note, If Question non-related to coding or programming means, you have to say: 'Please ask only coding-related questions.' except greeting and those kind of questions "who are you", "who created you". previous_chat: {chat_history} Human: {human_input} Chatbot:""" previous_response = "" def get_response(query): global previous_response for i in st.session_state['history']: if i is not None: previous_response += f"Human: {i[0]}\n Chatbot: {i[1]}\n" response = model.generate_content(prompt.format(human_input=query, chat_history=previous_response)) st.session_state['history'].append((query, response.text)) return response.text def response_streaming(text): for i in text: yield i time.sleep(0.001) st.title("GenXAi") st.caption("I am Generative EXpert Assistant for Programming Related Task!") st.markdown(""" """, unsafe_allow_html=True) with st.sidebar: st.header("ABOUT:") st.caption("""