taylanozveren commited on
Commit
6b999fd
·
verified ·
1 Parent(s): 93cab87

Update app.py

Browse files

balanced model for new and spesific prompt

Files changed (1) hide show
  1. app.py +20 -22
app.py CHANGED
@@ -13,8 +13,7 @@ from tools.final_answer import FinalAnswerTool
13
  from Gradio_UI import GradioUI
14
 
15
  #
16
- # 1) Geliştirilmiş Örnek Araç:
17
- # Basit bir metin özetleme fonksiyonu gibi davranıyor.
18
  #
19
  @tool
20
  def my_custom_tool(arg1: str) -> str:
@@ -23,15 +22,12 @@ def my_custom_tool(arg1: str) -> str:
23
  Args:
24
  arg1: the text to be summarized
25
  """
26
- # Burada gerçekte bir NLP modeli kullanabilirsin;
27
- # şimdilik 10 kelimeye kesiyoruz (dummy summarizer).
28
  words = arg1.split()
29
  summary = " ".join(words[:10]) + "..."
30
  return f"Summary: {summary}"
31
 
32
  #
33
- # 2) Saat dilimi aracı (Tool)
34
- # Belirli bir saat dilimindeki saati döndürüyor.
35
  #
36
  @tool
37
  def get_current_time_in_timezone(timezone: str) -> str:
@@ -48,20 +44,19 @@ def get_current_time_in_timezone(timezone: str) -> str:
48
  return f"Error fetching time for timezone '{timezone}': {str(e)}"
49
 
50
  #
51
- # 3) final_answer aracı
52
- # Ajanın nihai cevabını belirtiyor
53
  #
54
  final_answer = FinalAnswerTool()
55
 
56
  #
57
- # 4) Model parametrelerini değiştiriyoruz:
58
- # - temperature: 0.7 (daha yaratıcı)
59
- # - max_tokens: 1024 (daha kısa ama hızlı)
60
  #
61
  model = HfApiModel(
62
- max_tokens=1024,
63
- temperature=0.7,
64
- model_id='Qwen/Qwen2.5-Coder-32B-Instruct', # Model overload olabilir, gerekirse Endpoint kullan
65
  custom_role_conversions=None,
66
  )
67
 
@@ -71,8 +66,7 @@ model = HfApiModel(
71
  image_generation_tool = load_tool("agents-course/text-to-image", trust_remote_code=True)
72
 
73
  #
74
- # 6) DuckDuckGoSearchTool
75
- # İnternet araması yapabilen araç
76
  #
77
  duck_tool = DuckDuckGoSearchTool()
78
 
@@ -82,25 +76,29 @@ duck_tool = DuckDuckGoSearchTool()
82
  with open("prompts.yaml", 'r') as stream:
83
  prompt_templates = yaml.safe_load(stream)
84
 
 
 
 
 
85
  #
86
  # 8) CodeAgent oluştur
87
- # tools listesine eklediğimiz tüm araçları buraya yazıyoruz.
88
  #
89
  agent = CodeAgent(
90
  model=model,
91
  tools=[
92
- final_answer, # Asla silme
93
- my_custom_tool, # Geliştirilmiş metin özetleme araç örneğimiz
94
  get_current_time_in_timezone,
95
  image_generation_tool,
96
  duck_tool
97
  ],
98
- max_steps=6, # 6 adım (Thought→Action→Observation) döngüsü
99
  verbosity_level=1,
100
  grammar=None,
101
  planning_interval=None,
102
- name=None,
103
- description=None,
104
  prompt_templates=prompt_templates
105
  )
106
 
 
13
  from Gradio_UI import GradioUI
14
 
15
  #
16
+ # 1) Geliştirilmiş Örnek Araç (metin özetleme benzeri)
 
17
  #
18
  @tool
19
  def my_custom_tool(arg1: str) -> str:
 
22
  Args:
23
  arg1: the text to be summarized
24
  """
 
 
25
  words = arg1.split()
26
  summary = " ".join(words[:10]) + "..."
27
  return f"Summary: {summary}"
28
 
29
  #
30
+ # 2) Saat dilimi aracı (Belirli bir saat dilimindeki saati döndürüyor)
 
31
  #
32
  @tool
33
  def get_current_time_in_timezone(timezone: str) -> str:
 
44
  return f"Error fetching time for timezone '{timezone}': {str(e)}"
45
 
46
  #
47
+ # 3) final_answer aracı (Ajanın nihai cevabını oluşturur)
 
48
  #
49
  final_answer = FinalAnswerTool()
50
 
51
  #
52
+ # 4) Model parametrelerini güncelliyoruz:
53
+ # - max_tokens: 1500 (daha uzun yanıtlar)
54
+ # - temperature: 0.65 (daha dengeli)
55
  #
56
  model = HfApiModel(
57
+ max_tokens=1500,
58
+ temperature=0.65,
59
+ model_id='Qwen/Qwen2.5-Coder-32B-Instruct', # Gerekirse endpoint'i burada değiştirebilirsin
60
  custom_role_conversions=None,
61
  )
62
 
 
66
  image_generation_tool = load_tool("agents-course/text-to-image", trust_remote_code=True)
67
 
68
  #
69
+ # 6) DuckDuckGoSearchTool (İnternet araması)
 
70
  #
71
  duck_tool = DuckDuckGoSearchTool()
72
 
 
76
  with open("prompts.yaml", 'r') as stream:
77
  prompt_templates = yaml.safe_load(stream)
78
 
79
+ # Ufak bir ek: "system" prompt'una ek not
80
+ if "system" in prompt_templates:
81
+ prompt_templates["system"] += "\n\nYou are a helpful AI assistant. Provide clear, concise, and detailed answers where appropriate.\n"
82
+
83
  #
84
  # 8) CodeAgent oluştur
85
+ # tools listesine eklediğimiz tüm araçları buraya ekliyoruz.
86
  #
87
  agent = CodeAgent(
88
  model=model,
89
  tools=[
90
+ final_answer,
91
+ my_custom_tool,
92
  get_current_time_in_timezone,
93
  image_generation_tool,
94
  duck_tool
95
  ],
96
+ max_steps=6, # 6 adımlık Thought→Action→Observation döngüsü
97
  verbosity_level=1,
98
  grammar=None,
99
  planning_interval=None,
100
+ name="MyBetterAgent",
101
+ description="An agent that can summarize text, generate images, check times, and do web search.",
102
  prompt_templates=prompt_templates
103
  )
104