CihanYakar commited on
Commit
0552543
·
1 Parent(s): 6f14f11
Files changed (2) hide show
  1. app/main.py +23 -20
  2. requirements.txt +4 -4
app/main.py CHANGED
@@ -22,6 +22,11 @@ app.add_middleware(
22
  # Cache dosya yolu
23
  CACHE_FILE = "menu_cache.json"
24
 
 
 
 
 
 
25
 
26
  def get_current_date() -> str:
27
  """Günün tarihini YYYY-MM-DD formatında döndürür"""
@@ -53,37 +58,36 @@ def save_cache(cache_data: Dict) -> None:
53
 
54
 
55
  async def generate_menu() -> Dict:
56
- """You.com API kullanarak menü oluşturur"""
57
  try:
58
- API_URL = "https://you-chat-api.p.rapidapi.com/chat"
59
 
60
  headers = {
61
- "content-type": "application/json",
62
- "X-RapidAPI-Key": os.getenv("RAPIDAPI_KEY", "5be34cd499mshf5625891d9f2e6bp16cf0ajsn3cbc0c13edac"),
63
- "X-RapidAPI-Host": "you-chat-api.p.rapidapi.com"
64
  }
65
 
66
  data = {
67
- "question": """Türk mutfağına uygun günlük bir menü oluştur. Şu şekilde olmalı:
68
- - Kahvaltı: Tipik bir Türk kahvaltısı
69
- - Öğle: Ana yemek ve yanında
70
- - Akşam: Ana yemek ve yanında
71
-
72
- Lütfen mevsime uygun ve sağlıklı seçimler yap. Sadece menüyü liste olarak ver ve menüyü Türkçe hazırla.""",
73
- "chat": []
 
 
 
 
74
  }
75
 
76
  print("API isteği gönderiliyor...")
77
- print(f"API URL: {API_URL}")
78
- print(f"Headers: {headers}")
79
- print(f"Data: {json.dumps(data, ensure_ascii=False)}")
80
-
81
- response = requests.post(API_URL, json=data, headers=headers, timeout=30)
82
  print(f"API yanıtı status: {response.status_code}")
83
- print(f"API yanıtı: {response.text}")
84
 
85
  if response.status_code == 200:
86
- menu_text = response.json()['text']
87
  return {
88
  "date": get_current_date(),
89
  "menu": menu_text
@@ -107,7 +111,6 @@ async def get_menu():
107
  current_date = get_current_date()
108
 
109
  print(f"Cache kontrolü yapılıyor... Tarih: {current_date}")
110
- print(f"Mevcut cache: {json.dumps(cache, ensure_ascii=False)}")
111
 
112
  # Cache kontrolü
113
  if current_date in cache:
 
22
  # Cache dosya yolu
23
  CACHE_FILE = "menu_cache.json"
24
 
25
+ # Environment variable'dan API key'i al
26
+ CLAUDE_API_KEY = os.getenv("CLAUDE_API_KEY")
27
+ if not CLAUDE_API_KEY:
28
+ raise Exception("CLAUDE_API_KEY environment variable is not set")
29
+
30
 
31
  def get_current_date() -> str:
32
  """Günün tarihini YYYY-MM-DD formatında döndürür"""
 
58
 
59
 
60
  async def generate_menu() -> Dict:
61
+ """Claude API kullanarak menü oluşturur"""
62
  try:
63
+ API_URL = "https://api.anthropic.com/v1/messages"
64
 
65
  headers = {
66
+ "Content-Type": "application/json",
67
+ "anthropic-version": "2023-06-01",
68
+ "x-api-key": CLAUDE_API_KEY
69
  }
70
 
71
  data = {
72
+ "model": "claude-3-opus-20240229",
73
+ "max_tokens": 1024,
74
+ "messages": [{
75
+ "role": "user",
76
+ "content": """Türk mutfağına uygun günlük bir menü oluştur. Şu şekilde olmalı:
77
+ - Kahvaltı: Tipik bir Türk kahvaltısı
78
+ - Öğle: Ana yemek ve yanında
79
+ - Akşam: Ana yemek ve yanında
80
+
81
+ Lütfen mevsime uygun ve sağlıklı seçimler yap. Sadece menüyü liste olarak ver ve menüyü Türkçe hazırla."""
82
+ }]
83
  }
84
 
85
  print("API isteği gönderiliyor...")
86
+ response = requests.post(API_URL, json=data, headers=headers)
 
 
 
 
87
  print(f"API yanıtı status: {response.status_code}")
 
88
 
89
  if response.status_code == 200:
90
+ menu_text = response.json()['content'][0]['text']
91
  return {
92
  "date": get_current_date(),
93
  "menu": menu_text
 
111
  current_date = get_current_date()
112
 
113
  print(f"Cache kontrolü yapılıyor... Tarih: {current_date}")
 
114
 
115
  # Cache kontrolü
116
  if current_date in cache:
requirements.txt CHANGED
@@ -1,4 +1,4 @@
1
- fastapi==0.104.1
2
- uvicorn==0.24.0
3
- python-dotenv==1.0.0
4
- requests==2.31.0
 
1
+ fastapi
2
+ uvicorn
3
+ requests
4
+ python-dotenv