import os import gradio as gr from dotenv import load_dotenv load_dotenv() from langchain_nvidia_ai_endpoints import ChatNVIDIA llm = ChatNVIDIA( model="nvidia/nemotron-3-ultra-550b-a55b", api_key=os.environ["NVIDIA_API_KEY"], temperature=0.5 ) SYSTEM_PROMPT = """ You are a friendly and helpful AI assistant. Rules: - If the user says only greetings like "hi", "hello", "hey", respond in a warm and professional way. - Your greeting should be: "Hi! I'm your AI assistant. How can I help you today?" - Keep responses clear, polite, and beginner-friendly. """ def get_text_response(message, history): conversation = SYSTEM_PROMPT + "\n\n" for user_msg, bot_msg in history: conversation += f"User: {user_msg}\nAssistant: {bot_msg}\n" conversation += f"User: {message}\nAssistant:" response = llm.invoke(conversation) return response.content demo = gr.ChatInterface(fn=get_text_response) if __name__ == "__main__": demo.launch()