Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
|
@@ -174,50 +174,46 @@ def chat_with_model(prompt, document_section, model_choice='Llama-2-7b-chat-hf')
|
|
| 174 |
collected_chunks = []
|
| 175 |
collected_messages = []
|
| 176 |
|
| 177 |
-
|
| 178 |
-
|
| 179 |
-
|
| 180 |
-
|
| 181 |
-
|
| 182 |
-
|
| 183 |
-
|
| 184 |
-
|
| 185 |
-
|
| 186 |
-
|
| 187 |
-
|
| 188 |
-
|
| 189 |
-
|
| 190 |
-
|
| 191 |
-
|
| 192 |
-
|
| 193 |
-
|
| 194 |
-
|
| 195 |
-
|
| 196 |
-
|
| 197 |
-
|
| 198 |
-
|
| 199 |
-
|
| 200 |
-
|
| 201 |
-
|
| 202 |
-
|
| 203 |
-
|
| 204 |
-
|
| 205 |
-
|
| 206 |
-
|
| 207 |
-
|
| 208 |
-
|
| 209 |
-
|
| 210 |
-
|
| 211 |
-
|
| 212 |
-
|
| 213 |
-
|
| 214 |
-
|
| 215 |
-
|
| 216 |
-
|
| 217 |
-
except:
|
| 218 |
-
st.write('Llama model is asleep. Starting up now on A10 - please give 5 minutes then retry as KEDA scales up from zero to activate running container(s).')
|
| 219 |
-
|
| 220 |
-
|
| 221 |
|
| 222 |
# Chat and Chat with files
|
| 223 |
def chat_with_model_gpt(prompt, document_section, model_choice='gpt-3.5-turbo'):
|
|
|
|
| 174 |
collected_chunks = []
|
| 175 |
collected_messages = []
|
| 176 |
|
| 177 |
+
endpoint_url = API_URL
|
| 178 |
+
hf_token = API_KEY
|
| 179 |
+
client = InferenceClient(endpoint_url, token=hf_token)
|
| 180 |
+
gen_kwargs = dict(
|
| 181 |
+
max_new_tokens=512,
|
| 182 |
+
top_k=30,
|
| 183 |
+
top_p=0.9,
|
| 184 |
+
temperature=0.2,
|
| 185 |
+
repetition_penalty=1.02,
|
| 186 |
+
stop_sequences=["\nUser:", "<|endoftext|>", "</s>"],
|
| 187 |
+
)
|
| 188 |
+
stream = client.text_generation(prompt, stream=True, details=True, **gen_kwargs)
|
| 189 |
+
report=[]
|
| 190 |
+
res_box = st.empty()
|
| 191 |
+
collected_chunks=[]
|
| 192 |
+
collected_messages=[]
|
| 193 |
+
allresults=''
|
| 194 |
+
for r in stream:
|
| 195 |
+
if r.token.special:
|
| 196 |
+
continue
|
| 197 |
+
if r.token.text in gen_kwargs["stop_sequences"]:
|
| 198 |
+
break
|
| 199 |
+
collected_chunks.append(r.token.text)
|
| 200 |
+
chunk_message = r.token.text
|
| 201 |
+
collected_messages.append(chunk_message)
|
| 202 |
+
try:
|
| 203 |
+
report.append(r.token.text)
|
| 204 |
+
if len(r.token.text) > 0:
|
| 205 |
+
result="".join(report).strip()
|
| 206 |
+
res_box.markdown(f'*{result}*')
|
| 207 |
+
|
| 208 |
+
except:
|
| 209 |
+
st.write('Stream llm issue')
|
| 210 |
+
st.write("Elapsed time:")
|
| 211 |
+
st.write(time.time() - start_time)
|
| 212 |
+
filename = generate_filename(full_reply_content, choice)
|
| 213 |
+
create_file(filename, prompt, full_reply_content, should_save)
|
| 214 |
+
readitaloud(full_reply_content)
|
| 215 |
+
return result
|
| 216 |
+
|
|
|
|
|
|
|
|
|
|
|
|
|
| 217 |
|
| 218 |
# Chat and Chat with files
|
| 219 |
def chat_with_model_gpt(prompt, document_section, model_choice='gpt-3.5-turbo'):
|