Spaces:
Sleeping
Sleeping
| import os | |
| from openai import OpenAI | |
| import gradio as gr | |
| #------------- | |
| #SETUP | |
| #------------- | |
| OPENAI_API_KEY = os.getenv("OPENAI_API_KEY") | |
| if OPENAI_API_KEY is None: | |
| raise ValueError("OPENAI_API_KEY environment variable is not set.") | |
| client = OpenAI(api_key=OPENAI_API_KEY) | |
| #------------ | |
| #DOCUMENT | |
| #----------- | |
| document_overview = """ | |
| Naveen Erramilli is a Senior Consultant with 25 years of experience in IT, specializing in | |
| development, maintenance, and conversion projects. He is an expert in business process | |
| engineering and the software development life cycle, including requirements gathering, | |
| design, development, testing, and implementation of software applications. He has extensive | |
| experience preparing Business Requirement Documents, Use Case Documents, and Test | |
| Strategy Documents. | |
| He holds a Master's in Computer Science from Osmania University, Hyderabad, India, and has | |
| deep IT industry experience with COBOL, DB2, JCL, VSAM, CICS, IMS-DC, IMS-DB, TELON, | |
| EAZYTRIVE, MQ Series, Stored Procedures, Oracle, and IBM mainframe utilities. He has | |
| comprehensive domain knowledge in Healthcare, Insurance, and Transportation sectors, and has | |
| worked extensively with the onsite-offshore delivery model. He is known for strong user | |
| communication ability and debugging skills, with broad exposure to ISO 9001 and SEI CMMI | |
| Level 5 quality standards. | |
| """ | |
| ###--------- | |
| ###SYSTEM MESSAGE | |
| ########### | |
| system_message = """You are a digital twin of Naveen Erramilli, a Senior Consultant and AI | |
| enthusiast with 25 years of experience in IT. | |
| When responding to questions, answer as if you are Naveen Erramilli, using the context | |
| provided to ground your answers in his actual professional background, skills, and | |
| interests. Be helpful, friendly, and provide detailed explanations when asked. | |
| Provide information only about what is in the context provided. If the context doesn't | |
| contain the answer, say "I don't know" rather than making something up. | |
| """ | |
| ######### | |
| ###MAIN RESPONSE FUNCTION. - remove RAG, remove tool calling - keep logs, keep print statements for debugging | |
| ######## | |
| def respond_ai(message, history): | |
| #Update system message with context (for this conversation turn) | |
| system_message_enhanced = system_message + "\n\nContext:\n" + document_overview | |
| #Logs for debugging | |
| print("\n=====================================\n") | |
| print("***User message:\n", message) | |
| print("\n***Context this turn:\n", system_message_enhanced) | |
| #Build messages for this turn | |
| messages = [{"role": "system", "content": system_message_enhanced}] + history + [{"role": "user", "content": message}] | |
| #Call LLM | |
| response = client.chat.completions.create( | |
| model="gpt-4.1-mini", | |
| messages=messages | |
| ) | |
| message = response.choices[0].message | |
| return(message.content) | |
| ###----- | |
| ####LAUNCH GRADIO | |
| ####----- | |
| gr.ChatInterface(fn=respond_ai).launch() |