Spaces:
Running
Running
import os | |
import gradio as gr | |
from openai import OpenAI | |
# Initialize the OpenAI client | |
client = OpenAI(api_key=os.getenv("OPENAI_API_KEY")) | |
# Define the response function | |
def respond( | |
message, | |
history: list[tuple[str, str]], | |
system_message, | |
role, | |
education, | |
passion, | |
fit, | |
anecdotes, | |
max_tokens, | |
temperature, | |
top_p, | |
): | |
# Construct the enhanced system prompt | |
enhanced_system_message = ( | |
f"{system_message}\n\n" | |
f"Role, Industry, Employer and Summary of Job Ad: {role}\n" | |
f"Summary of your Education and Work Experience: {education}\n" | |
f"Why are you passionate about this job: {passion}\n" | |
f"Why do you feel you are a good fit for this job: {fit}\n" | |
f"Anecdotes: {anecdotes}\n" | |
) | |
# Construct message history | |
messages = [{"role": "system", "content": enhanced_system_message}] | |
for user_msg, assistant_msg in history: | |
if user_msg: | |
messages.append({"role": "user", "content": user_msg}) | |
if assistant_msg: | |
messages.append({"role": "assistant", "content": assistant_msg}) | |
messages.append({"role": "user", "content": message}) | |
# Generate and stream response | |