Rizz / api.py
aliabid94's picture
aliabid94 HF staff
Upload folder using huggingface_hub
08d94c4 verified
from openai import OpenAI
import os
client = OpenAI(api_key=os.environ["OPENAI_API_KEY"])
def generate_scenario(gender):
PROMPT = f"""Create a scenario where you're see a {gender} you're interested in. You haven't yet approached them yet but are interested. Keep it brief, around 20 words. For example: 'There's a cute {gender} in my boxing class. I approach her after a class.' or 'I see two {gender}s having coffee at the table next to mine.'."""
return llm(PROMPT)
def suggest_next_line(scenario, history):
PROMPT = f"""This is my scenario: {scenario} \n\n"""
if len(history) == 0:
PROMPT += "Suggest a line with which I can introduce myself or strike up a conversation."
else:
PROMPT += f"""This is the conversation so far: \n\n{format_history(history)} \n\nSuggest my next response. Provide the response and nothing else."""
return llm(PROMPT)
def generate_response(scenario, history, personality, interested):
PROMPT = f"""This is my scenario: {scenario}. Roleplay the conversation with me. Provide the response and nothing else. You're personality is {personality}. You are {'interested' if interested else 'not interested'} in me.
The conversation so far: \n\n{format_history(history)}
Only provide the response and nothing else.
"""
return llm(PROMPT)
def transcribe_audio(audio_path):
with open(audio_path, "rb") as audio_file:
transcript = client.audio.transcriptions.create(
model="whisper-1",
file=audio_file
)
return transcript.text
def llm(prompt):
response = client.completions.create(
model="gpt-3.5-turbo-instruct",
prompt=prompt,
temperature=0.9,
max_tokens=100,
top_p=1,
frequency_penalty=0.0,
presence_penalty=0.6,
)
return response.choices[0].text.strip()
def format_history(history):
return "\n\n".join([f"Me: {line[0]} \nThem: {line[1] if line[1] else ''}" for line in history])