alphayomega commited on
Commit
5f6daba
1 Parent(s): fd9c480

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +14 -7
app.py CHANGED
@@ -88,23 +88,30 @@ def generate_chat_responses(chat_completion) -> Generator[str, None, None]:
88
  if chunk.choices[0].delta.content:
89
  yield chunk.choices[0].delta.content
90
 
91
- # Manejar la entrada del chat del usuario
92
- if prompt := st.chat_input(
93
  "# Extract the benefits of the product, not the features. # You should be as brief as possible. # Omit the price, if any. # Do not mention the name of the product. # Use 3 paragraphs. # Try to synthesize or summarize. # Focus only on the benefits. # Highlight how this product helps the customer. # Always respond in Spanish. # The text you create will be used in an e-commerce product sales page through the Internet, so it must be persuasive, attractive, and above all very short and summarized. # Remember to keep the text short, summarized, synthesized in three paragraphs. # Surprise me with your best ideas! # Always answers in AMERICAN SPANISH. Stop after finish the first content genreated."
94
- ):
 
 
 
95
  st.session_state.messages.append({"role": "user", "content": prompt})
96
 
97
  with st.chat_message("user", avatar="🧑‍💻"):
98
  st.markdown(prompt)
99
 
 
 
 
 
 
 
 
100
  # Obtener respuesta de la API de Groq
101
  try:
102
  chat_completion = client.chat.completions.create(
103
  model=model_option,
104
- messages=[
105
- {"role": m["role"], "content": m["content"]}
106
- for m in st.session_state.messages
107
- ],
108
  max_tokens=max_tokens,
109
  stream=True,
110
  )
 
88
  if chunk.choices[0].delta.content:
89
  yield chunk.choices[0].delta.content
90
 
91
+ # Instrucción privada que se aplicará a cada mensaje
92
+ private_instruction = (
93
  "# Extract the benefits of the product, not the features. # You should be as brief as possible. # Omit the price, if any. # Do not mention the name of the product. # Use 3 paragraphs. # Try to synthesize or summarize. # Focus only on the benefits. # Highlight how this product helps the customer. # Always respond in Spanish. # The text you create will be used in an e-commerce product sales page through the Internet, so it must be persuasive, attractive, and above all very short and summarized. # Remember to keep the text short, summarized, synthesized in three paragraphs. # Surprise me with your best ideas! # Always answers in AMERICAN SPANISH. Stop after finish the first content genreated."
94
+ )
95
+
96
+ # Manejar la entrada del chat del usuario
97
+ if prompt := st.chat_input("Escribe tu mensaje aquí..."):
98
  st.session_state.messages.append({"role": "user", "content": prompt})
99
 
100
  with st.chat_message("user", avatar="🧑‍💻"):
101
  st.markdown(prompt)
102
 
103
+ # Preparar los mensajes para la API, incluyendo la instrucción privada
104
+ messages_for_api = [
105
+ {"role": "system", "content": private_instruction},
106
+ {"role": m["role"], "content": m["content"]}
107
+ for m in st.session_state.messages
108
+ ]
109
+
110
  # Obtener respuesta de la API de Groq
111
  try:
112
  chat_completion = client.chat.completions.create(
113
  model=model_option,
114
+ messages=messages_for_api,
 
 
 
115
  max_tokens=max_tokens,
116
  stream=True,
117
  )