-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathprompts.py
36 lines (25 loc) · 902 Bytes
/
prompts.py
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
import os
import torch
import torch.nn as nn
import bitsandbytes as bnb
from datasets import load_dataset
import transformers
import time
import glob
def speaker_id_to_name(speaker_id):
if speaker_id.lower() == "biden":
return "Joe Biden"
elif speaker_id.lower() == "trump":
return "Donald Trump"
else:
raise ValueError(f"Invalid speaker id: {speaker_id}")
def generate_prompt(context, speaker_id):
return f"""Below is context that describes a conversation, paired with the name of the next speaker in the conversation. Write a response that appropriately continues the conversation as the next speaker.
### Context:
{context}
### Speaker:
{speaker_id_to_name(speaker_id)}
### {speaker_id_to_name(speaker_id)}:"""
def create_context_and_generate_prompt(input, speaker):
context = f"PersonA: '{input}'"
return generate_prompt(context, speaker)