Futuresony commited on
Commit
e908972
·
verified ·
1 Parent(s): 7561eb5

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +13 -11
app.py CHANGED
@@ -3,28 +3,30 @@ from huggingface_hub import InferenceClient
3
 
4
  client = InferenceClient("Futuresony/future_ai_12_10_2024.gguf")
5
 
6
- # Store chat history
7
- def format_alpaca_prompt(user_input, history, system_prompt):
8
- """Formats input in Alpaca/LLaMA style with history"""
9
- history_text = "\n".join([f"User: {h[0]}\nAssistant: {h[1]}" for h in history])
10
- prompt = f"""{system_prompt}\n{history_text}\nUser: {user_input}\nAssistant:"""
11
  return prompt
12
 
13
  def respond(message, history, system_message, max_tokens, temperature, top_p):
14
- formatted_prompt = format_alpaca_prompt(message, history, system_message)
15
-
16
  response = client.text_generation(
17
  formatted_prompt,
18
  max_new_tokens=max_tokens,
19
  temperature=temperature,
20
  top_p=top_p,
21
  )
22
-
23
- # Extract only the response
24
  cleaned_response = response.strip()
25
 
26
- history.append((message, cleaned_response)) # Store conversation history
27
- yield cleaned_response # ✅ Output only the answer
 
 
28
 
29
  demo = gr.ChatInterface(
30
  respond,
 
3
 
4
  client = InferenceClient("Futuresony/future_ai_12_10_2024.gguf")
5
 
6
+ # Store conversation history
7
+ def format_alpaca_prompt(history, user_input, system_prompt):
8
+ """Formats input in Alpaca/LLaMA style with conversation history"""
9
+ formatted_history = "\n".join([f"User: {h[0]}\nAssistant: {h[1]}" for h in history])
10
+ prompt = f"""{system_prompt}\n{formatted_history}\nUser: {user_input}\nAssistant:"""
11
  return prompt
12
 
13
  def respond(message, history, system_message, max_tokens, temperature, top_p):
14
+ formatted_prompt = format_alpaca_prompt(history, message, system_message)
15
+
16
  response = client.text_generation(
17
  formatted_prompt,
18
  max_new_tokens=max_tokens,
19
  temperature=temperature,
20
  top_p=top_p,
21
  )
22
+
23
+ # Extract only the response
24
  cleaned_response = response.strip()
25
 
26
+ # Update history
27
+ history.append((message, cleaned_response))
28
+
29
+ yield cleaned_response # Output only the answer
30
 
31
  demo = gr.ChatInterface(
32
  respond,