Rob Learsch commited on
Commit
f817407
·
1 Parent(s): c6204c3

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +16 -15
app.py CHANGED
@@ -137,21 +137,22 @@ def chat_with_musician(user_input, history, artist):
137
  return f"Error: {str(e)}"
138
 
139
  lyric_response = artist_response(gemma_response, artist)
140
- if lyric_response == messages[-2]["content"]:
141
- # If the response is the same as the last one, get a new one:
142
- messages[-1]={"role": "user", "content": system_message_repeated + "\n\n" + user_input}
143
- try:
144
- response = client.chat_completion(
145
- messages=messages,
146
- model="google/gemma-2-2b-it",
147
- max_tokens=256,
148
- temperature=0.75,
149
- #top_p=0.9
150
- )
151
- gemma_response= response["choices"][0]["message"]["content"]
152
- except Exception as e:
153
- return f"Error: {str(e)}"
154
- lyric_response = artist_response(gemma_response, artist)
 
155
 
156
  history.append({"role": "user", "content": user_input})
157
  history.append({"role": "assistant", "content": lyric_response})
 
137
  return f"Error: {str(e)}"
138
 
139
  lyric_response = artist_response(gemma_response, artist)
140
+ if len(messages)>1:
141
+ if lyric_response == messages[-2]["content"]:
142
+ # If the response is the same as the last one, get a new one:
143
+ messages[-1]={"role": "user", "content": system_message_repeated + "\n\n" + user_input}
144
+ try:
145
+ response = client.chat_completion(
146
+ messages=messages,
147
+ model="google/gemma-2-2b-it",
148
+ max_tokens=256,
149
+ temperature=0.75,
150
+ #top_p=0.9
151
+ )
152
+ gemma_response= response["choices"][0]["message"]["content"]
153
+ except Exception as e:
154
+ return f"Error: {str(e)}"
155
+ lyric_response = artist_response(gemma_response, artist)
156
 
157
  history.append({"role": "user", "content": user_input})
158
  history.append({"role": "assistant", "content": lyric_response})