File size: 2,037 Bytes
08d94c4
 
 
 
2a53e07
 
08d94c4
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
2a53e07
08d94c4
 
 
 
 
 
 
2a53e07
08d94c4
 
 
 
 
 
 
 
 
 
 
 
2a53e07
08d94c4
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
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])