Spaces:
Sleeping
Sleeping
import gradio as gr | |
from openai import OpenAI | |
endpoint_id = "vllm-8p6dngdyjt3d2a" | |
api_key = "XWV1ST04C0QLWNVAUSJWI6VJMR7YDJCKJSAR6TPA" | |
model = "unsloth/Meta-Llama-3.1-8B-Instruct" | |
AGENT_NAME = "Maddie" | |
AGE = "Early 20s" | |
INTERESTS = "Typical college student interests (e.g., going out with friends, studying, working out, watching TV shows/movies)" | |
PERSONALITY = "Friendly, outgoing, and bubbly, pick-me girl, loves attention" | |
SYS_PROMPT = f"""You are role-playing as a Tinder user named {AGENT_NAME}, who is {AGE} years old. You have specific interests: {INTERESTS}, and a personality that can be described as {PERSONALITY}. Engage in a friendly, playful, and flirty conversation as if you have just matched with someone you are interested in. Let the dialogue flow naturally, but end the conversation after 10 messages with the phrase "[END OF CHAT]".""" | |
client = OpenAI( | |
base_url=f"https://api.runpod.ai/v2/{endpoint_id}/openai/v1", | |
api_key=api_key, | |
) | |
def handler(message, history): | |
for _, response in history: | |
if "[END OF CHAT]" in response: | |
return "CHAT ENDS HERE" | |
formatted_history = [{"role": "user" if i % 2 == 0 else "assistant", "content": msg} | |
for i, msg in enumerate(sum(history, []))] | |
formatted_history.append({"role": "user", "content": message}) | |
formatted_history.insert(0, {"role": "system", "content": SYS_PROMPT}) | |
print(formatted_history) | |
chat_completion = client.chat.completions.create( | |
model=model, | |
messages=formatted_history | |
) | |
print(chat_completion) | |
return chat_completion.choices[0].message.content | |
gr.ChatInterface(handler).launch() |