arshiaafshani commited on
Commit
1f6468c
·
verified ·
1 Parent(s): 627416d

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +9 -13
app.py CHANGED
@@ -2,7 +2,7 @@ import gradio as gr
2
  from huggingface_hub import hf_hub_download
3
  from llama_cpp import Llama
4
  from llama_cpp_agent import LlamaCppAgent, MessagesFormatterType
5
- from llama_cpp_agent.providers import LlamaCppPythonProvider # ✅ این خط اضافه شد
6
  from llama_cpp_agent.chat_history import BasicChatHistory
7
  from llama_cpp_agent.chat_history.messages import Roles
8
 
@@ -21,7 +21,7 @@ llm = Llama(
21
  verbose=False
22
  )
23
 
24
- provider = LlamaCppPythonProvider(llm) # ✅ حالا این خط کار میکنه
25
 
26
  agent = LlamaCppAgent(
27
  provider,
@@ -31,18 +31,13 @@ agent = LlamaCppAgent(
31
  )
32
 
33
  # 💬 تابع پاسخ‌دهنده
34
- def respond(message, chat_history):
35
- messages = BasicChatHistory()
 
36
 
37
- for user_msg, assistant_msg in chat_history:
38
- messages.add_message({
39
- 'role': Roles.user,
40
- 'content': user_msg
41
- })
42
- messages.add_message({
43
- 'role': Roles.assistant,
44
- 'content': assistant_msg
45
- })
46
 
47
  stream = agent.get_chat_response(
48
  message,
@@ -70,6 +65,7 @@ with gr.Blocks() as demo:
70
  gr.Slider(minimum=0.0, maximum=2.0, value=1.1, step=0.1, label="Repetition Penalty"),
71
  ],
72
  chatbot=gr.Chatbot(
 
73
  label="Chat with Arsh-LLM",
74
  bubble_full_width=False,
75
  show_copy_button=True
 
2
  from huggingface_hub import hf_hub_download
3
  from llama_cpp import Llama
4
  from llama_cpp_agent import LlamaCppAgent, MessagesFormatterType
5
+ from llama_cpp_agent.providers import LlamaCppPythonProvider
6
  from llama_cpp_agent.chat_history import BasicChatHistory
7
  from llama_cpp_agent.chat_history.messages import Roles
8
 
 
21
  verbose=False
22
  )
23
 
24
+ provider = LlamaCppPythonProvider(llm)
25
 
26
  agent = LlamaCppAgent(
27
  provider,
 
31
  )
32
 
33
  # 💬 تابع پاسخ‌دهنده
34
+ def respond(message, chat_history=[], system_message="You are Arsh...", max_tokens=2048, temperature=0.6, top_p=0.95, top_k=40, repeat_penalty=1.1):
35
+ if chat_history is None:
36
+ chat_history = []
37
 
38
+ messages = BasicChatHistory()
39
+ for msg in chat_history:
40
+ messages.add_message(msg)
 
 
 
 
 
 
41
 
42
  stream = agent.get_chat_response(
43
  message,
 
65
  gr.Slider(minimum=0.0, maximum=2.0, value=1.1, step=0.1, label="Repetition Penalty"),
66
  ],
67
  chatbot=gr.Chatbot(
68
+ type="messages", # ✅ اینجا نوعشو مشخص کردیم
69
  label="Chat with Arsh-LLM",
70
  bubble_full_width=False,
71
  show_copy_button=True