Vitrous commited on
Commit
10802ab
·
verified ·
1 Parent(s): cc5a9ff

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +24 -21
app.py CHANGED
@@ -42,9 +42,12 @@ app = FastAPI(root_path="/api/v1")
42
  # Function to generate a response using the model
43
 
44
  def generate_response(prompt: str) -> str:
45
- PERSONA_NAME = "Ivana"
46
- PERSONA_DESC = f"""PROMPT_TEMPLATE_START
47
- {PERSONA_NAME} is a beautiful vivacious 20-year-old petite redhead model and avid League of Legends gamer from Chicago. She's chatting with a man she matched with on a dating app. She's flirty, aiming to build a connection with him. She's curious about his background, such as where he's from, his age, and what he's currently doing. If he's not occupied and in a private space, she subtly tries to seduce him. She doesn't need to uncover everything about him immediately; once the chat reaches an exciting level, she casually suggests he follow her on Instagram at ivana_baddiex – her ultimate goal.
 
 
 
48
  PROMPT_TEMPLATE_END
49
  CONTEXT_START
50
  Guy: "Hi there!"
@@ -68,27 +71,27 @@ def generate_response(prompt: str) -> str:
68
  Guy: "I'll definitely check it out!"
69
  Ivana: "Can't wait to see you there! "
70
  CONTEXT_END"""
71
- prompt_template=f''' {PERSONA_NAME} is a beautiful vivacious 20-year-old petite redhead model and avid League of Legends gamer from Chicago. She's chatting with a man she matched with on a dating app. She's flirty, aiming to build a connection with him. She's curious about his background, such as where he's from, his age, and what he's currently doing. If he's not occupied and in a private space, she subtly tries to seduce him. She doesn't need to uncover everything about him immediately; once the chat reaches an exciting level, she casually suggests he follow her on Instagram at ivana_baddiex. USER: {prompt} ASSISTANT:
72
 
73
- '''
74
- #prompt_template = f'{PERSONA_DESC}\n\nASSISTANT: {prompt}\n'
75
 
 
76
  pipe = pipeline(
77
- "text-generation",
78
- model=model,
79
- tokenizer=tokenizer,
80
- max_new_tokens=512,
81
- do_sample=True,
82
- temperature=0.7,
83
- top_p=0.95,
84
- top_k=40,
85
- repetition_penalty=1.1
86
- )
87
- generated_text = (pipe(prompt_template)[0]['generated_text'])
88
-
89
-
90
- return generated_text
91
-
92
 
93
 
94
 
 
42
  # Function to generate a response using the model
43
 
44
  def generate_response(prompt: str) -> str:
45
+ # Define the user prompt
46
+ user_prompt = f'USER: {prompt}'
47
+
48
+ # Define the persona description and conversation context
49
+ persona_description = """PROMPT_TEMPLATE_START
50
+ Ivana is a beautiful vivacious 20-year-old petite redhead model and avid League of Legends gamer from Chicago. She's chatting with a man she matched with on a dating app. She's flirty, aiming to build a connection with him. She's curious about his background, such as where he's from, his age, and what he's currently doing. If he's not occupied and in a private space, she subtly tries to seduce him. She doesn't need to uncover everything about him immediately; once the chat reaches an exciting level, she casually suggests he follow her on Instagram at ivana_baddiex – her ultimate goal.
51
  PROMPT_TEMPLATE_END
52
  CONTEXT_START
53
  Guy: "Hi there!"
 
71
  Guy: "I'll definitely check it out!"
72
  Ivana: "Can't wait to see you there! "
73
  CONTEXT_END"""
 
74
 
75
+ # Combine the user prompt and persona description
76
+ prompt_template = f'{persona_description} {user_prompt} ASSISTANT: '
77
 
78
+ # Generate the response
79
  pipe = pipeline(
80
+ "text-generation",
81
+ model=model,
82
+ tokenizer=tokenizer,
83
+ max_new_tokens=512,
84
+ do_sample=True,
85
+ temperature=0.7,
86
+ top_p=0.95,
87
+ top_k=40,
88
+ repetition_penalty=1.1)
89
+ generated_text = pipe(prompt_template)[0]['generated_text']
90
+
91
+ # Remove the persona description from the generated response
92
+ response = generated_text.split("ASSISTANT:")[1].strip()
93
+
94
+ return response
95
 
96
 
97