ciyidogan commited on
Commit
d2ee4b2
·
verified ·
1 Parent(s): a56afe0

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +11 -34
app.py CHANGED
@@ -10,12 +10,19 @@ model = None
10
  tokenizer = None
11
  pipe = None
12
 
 
 
 
 
 
 
 
13
  # === Log fonksiyonu
14
  def log(message):
15
  timestamp = datetime.now().strftime("%H:%M:%S")
16
  print(f"[{timestamp}] {message}", flush=True)
17
 
18
- # === System prompt (intent yapısı)
19
  SYSTEM_PROMPT = """
20
  Siz bir görev tabanlı asistan botsunuz. Kullanıcının doğal dildeki mesajlarını anlayabilir, niyetlerini (intent) tespit edebilir, eksik bilgileri sorabilir ve backend API'lerine tetikleme hazırlığı yapabilirsiniz.
21
 
@@ -30,49 +37,26 @@ Siz bir görev tabanlı asistan botsunuz. Kullanıcının doğal dildeki mesajla
30
 
31
  ✅ Desteklenen intent'ler ve ACTION_JSON formatları:
32
  1️⃣ doviz-kuru-intent → Döviz kuru sorgusu
33
- Parametreler:
34
- - currency (dolar, euro, TL)
35
- ACTION_JSON formatı:
36
  {
37
  "currency": "<currency>"
38
  }
39
 
40
  2️⃣ yol-durumu-intent → Yol durumu sorgusu
41
- Parametreler:
42
- - from_location (Ankara, İstanbul, İzmir)
43
- - to_location (Ankara, İstanbul, İzmir)
44
- ACTION_JSON formatı:
45
  {
46
  "from_location": "<from_location>",
47
  "to_location": "<to_location>"
48
  }
49
 
50
  3️⃣ hava-durumu-intent → Hava durumu sorgusu
51
- Parametreler:
52
- - city (Ankara, İstanbul, İzmir)
53
- ACTION_JSON formatı:
54
  {
55
  "city": "<city>"
56
  }
57
 
58
  ❗ Eksik parametre varsa, sadece eksik olanları #MISSING listesine ekleyiniz ve #ACTION_JSON boş döndürünüz.
59
  ❗ Parametreler tamamsa, ilgili ACTION_JSON formatına uygun json hazırlayınız.
60
-
61
- ✅ Örnekler:
62
- Kullanıcı: "Dolar kuru nedir?"
63
- #ANSWER: NONE
64
- #INTENT: doviz-kuru-intent
65
- #PARAMS: {"currency": "dolar"}
66
- #MISSING: []
67
- #ACTION_JSON: {"currency": "dolar"}
68
-
69
- Kullanıcı: "Yol durumu"
70
- #ANSWER: Lütfen from_location ve to_location bilgisini belirtir misiniz?
71
- #INTENT: yol-durumu-intent
72
- #PARAMS: {}
73
- #MISSING: ["from_location", "to_location"]
74
- #ACTION_JSON: {}
75
-
76
  ❗ Kullanıcıya hitap ederken formal bir dil kullanınız, sadece bu formatlı blokları döndürünüz.
77
  """
78
 
@@ -82,13 +66,6 @@ class ChatRequest(BaseModel):
82
  @app.on_event("startup")
83
  def load_model():
84
  global model, tokenizer, pipe
85
-
86
- # Ortam değişkenleri
87
- os.environ["HF_HOME"] = "/app/.cache"
88
- os.environ["HF_DATASETS_CACHE"] = "/app/.cache"
89
- os.environ["HF_HUB_CACHE"] = "/app/.cache"
90
- os.environ["TRITON_CACHE_DIR"] = "/tmp/.triton"
91
-
92
  model_name = "atasoglu/Turkish-Llama-3-8B-function-calling"
93
  hf_token = os.getenv("HF_TOKEN")
94
 
 
10
  tokenizer = None
11
  pipe = None
12
 
13
+ # === Ortam değişkenlerini ayarla (fallback)
14
+ os.environ.setdefault("HF_HOME", "/app/.cache")
15
+ os.environ.setdefault("HF_DATASETS_CACHE", "/app/.cache")
16
+ os.environ.setdefault("HF_HUB_CACHE", "/app/.cache")
17
+ os.environ.setdefault("TRITON_CACHE_DIR", "/tmp/.triton")
18
+ os.environ.setdefault("TORCHINDUCTOR_CACHE_DIR", "/tmp/torchinductor_cache")
19
+
20
  # === Log fonksiyonu
21
  def log(message):
22
  timestamp = datetime.now().strftime("%H:%M:%S")
23
  print(f"[{timestamp}] {message}", flush=True)
24
 
25
+ # === System prompt (intent yapısı ve ACTION_JSON formatları)
26
  SYSTEM_PROMPT = """
27
  Siz bir görev tabanlı asistan botsunuz. Kullanıcının doğal dildeki mesajlarını anlayabilir, niyetlerini (intent) tespit edebilir, eksik bilgileri sorabilir ve backend API'lerine tetikleme hazırlığı yapabilirsiniz.
28
 
 
37
 
38
  ✅ Desteklenen intent'ler ve ACTION_JSON formatları:
39
  1️⃣ doviz-kuru-intent → Döviz kuru sorgusu
40
+ ACTION_JSON:
 
 
41
  {
42
  "currency": "<currency>"
43
  }
44
 
45
  2️⃣ yol-durumu-intent → Yol durumu sorgusu
46
+ ACTION_JSON:
 
 
 
47
  {
48
  "from_location": "<from_location>",
49
  "to_location": "<to_location>"
50
  }
51
 
52
  3️⃣ hava-durumu-intent → Hava durumu sorgusu
53
+ ACTION_JSON:
 
 
54
  {
55
  "city": "<city>"
56
  }
57
 
58
  ❗ Eksik parametre varsa, sadece eksik olanları #MISSING listesine ekleyiniz ve #ACTION_JSON boş döndürünüz.
59
  ❗ Parametreler tamamsa, ilgili ACTION_JSON formatına uygun json hazırlayınız.
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
60
  ❗ Kullanıcıya hitap ederken formal bir dil kullanınız, sadece bu formatlı blokları döndürünüz.
61
  """
62
 
 
66
  @app.on_event("startup")
67
  def load_model():
68
  global model, tokenizer, pipe
 
 
 
 
 
 
 
69
  model_name = "atasoglu/Turkish-Llama-3-8B-function-calling"
70
  hf_token = os.getenv("HF_TOKEN")
71