Spaces:
Runtime error
Runtime error
Commit ·
f44789d
1
Parent(s): 82f9871
ProAgenta temel işlevler kazandırıldı ve gradio arayüzü oluşturuldu.
Browse files- .gitignore +5 -0
- .gradio/certificate.pem +31 -0
- .idea/.gitignore +8 -0
- .idea/calendar-agent.iml +8 -0
- .idea/inspectionProfiles/Project_Default.xml +14 -0
- .idea/inspectionProfiles/profiles_settings.xml +6 -0
- .idea/misc.xml +7 -0
- .idea/modules.xml +8 -0
- .idea/vcs.xml +6 -0
- app.py +79 -0
- models/__pycache__/groq_model.cpython-310.pyc +0 -0
- models/__pycache__/novita_ai_model.cpython-310.pyc +0 -0
- models/groq_model.py +40 -0
- models/novita_ai_model.py +35 -0
- requirements.txt +8 -0
- tools/__pycache__/add_events.cpython-310.pyc +0 -0
- tools/__pycache__/delete_event.cpython-310.pyc +0 -0
- tools/__pycache__/get_events.cpython-310.pyc +0 -0
- tools/__pycache__/mail_sender.cpython-310.pyc +0 -0
- tools/__pycache__/search_events.cpython-310.pyc +0 -0
- tools/add_events.py +72 -0
- tools/delete_event.py +73 -0
- tools/get_events.py +93 -0
- tools/mail_sender.py +57 -0
- tools/search_events.py +67 -0
.gitignore
ADDED
|
@@ -0,0 +1,5 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
/data
|
| 2 |
+
DENEME.py
|
| 3 |
+
.env
|
| 4 |
+
tools.txt
|
| 5 |
+
app.txt
|
.gradio/certificate.pem
ADDED
|
@@ -0,0 +1,31 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
-----BEGIN CERTIFICATE-----
|
| 2 |
+
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
|
| 31 |
+
-----END CERTIFICATE-----
|
.idea/.gitignore
ADDED
|
@@ -0,0 +1,8 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# Default ignored files
|
| 2 |
+
/shelf/
|
| 3 |
+
/workspace.xml
|
| 4 |
+
# Editor-based HTTP Client requests
|
| 5 |
+
/httpRequests/
|
| 6 |
+
# Datasource local storage ignored files
|
| 7 |
+
/dataSources/
|
| 8 |
+
/dataSources.local.xml
|
.idea/calendar-agent.iml
ADDED
|
@@ -0,0 +1,8 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
<?xml version="1.0" encoding="UTF-8"?>
|
| 2 |
+
<module type="PYTHON_MODULE" version="4">
|
| 3 |
+
<component name="NewModuleRootManager">
|
| 4 |
+
<content url="file://$MODULE_DIR$" />
|
| 5 |
+
<orderEntry type="jdk" jdkName="Agents" jdkType="Python SDK" />
|
| 6 |
+
<orderEntry type="sourceFolder" forTests="false" />
|
| 7 |
+
</component>
|
| 8 |
+
</module>
|
.idea/inspectionProfiles/Project_Default.xml
ADDED
|
@@ -0,0 +1,14 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
<component name="InspectionProjectProfileManager">
|
| 2 |
+
<profile version="1.0">
|
| 3 |
+
<option name="myName" value="Project Default" />
|
| 4 |
+
<inspection_tool class="PyPackageRequirementsInspection" enabled="true" level="WARNING" enabled_by_default="true">
|
| 5 |
+
<option name="ignoredPackages">
|
| 6 |
+
<value>
|
| 7 |
+
<list size="1">
|
| 8 |
+
<item index="0" class="java.lang.String" itemvalue="rich" />
|
| 9 |
+
</list>
|
| 10 |
+
</value>
|
| 11 |
+
</option>
|
| 12 |
+
</inspection_tool>
|
| 13 |
+
</profile>
|
| 14 |
+
</component>
|
.idea/inspectionProfiles/profiles_settings.xml
ADDED
|
@@ -0,0 +1,6 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
<component name="InspectionProjectProfileManager">
|
| 2 |
+
<settings>
|
| 3 |
+
<option name="USE_PROJECT_PROFILE" value="false" />
|
| 4 |
+
<version value="1.0" />
|
| 5 |
+
</settings>
|
| 6 |
+
</component>
|
.idea/misc.xml
ADDED
|
@@ -0,0 +1,7 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
<?xml version="1.0" encoding="UTF-8"?>
|
| 2 |
+
<project version="4">
|
| 3 |
+
<component name="Black">
|
| 4 |
+
<option name="sdkName" value="C:\Users\alcmd\anaconda3" />
|
| 5 |
+
</component>
|
| 6 |
+
<component name="ProjectRootManager" version="2" project-jdk-name="Agents" project-jdk-type="Python SDK" />
|
| 7 |
+
</project>
|
.idea/modules.xml
ADDED
|
@@ -0,0 +1,8 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
<?xml version="1.0" encoding="UTF-8"?>
|
| 2 |
+
<project version="4">
|
| 3 |
+
<component name="ProjectModuleManager">
|
| 4 |
+
<modules>
|
| 5 |
+
<module fileurl="file://$PROJECT_DIR$/.idea/calendar-agent.iml" filepath="$PROJECT_DIR$/.idea/calendar-agent.iml" />
|
| 6 |
+
</modules>
|
| 7 |
+
</component>
|
| 8 |
+
</project>
|
.idea/vcs.xml
ADDED
|
@@ -0,0 +1,6 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
<?xml version="1.0" encoding="UTF-8"?>
|
| 2 |
+
<project version="4">
|
| 3 |
+
<component name="VcsDirectoryMappings">
|
| 4 |
+
<mapping directory="" vcs="Git" />
|
| 5 |
+
</component>
|
| 6 |
+
</project>
|
app.py
ADDED
|
@@ -0,0 +1,79 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
from dotenv import load_dotenv
|
| 2 |
+
load_dotenv()
|
| 3 |
+
|
| 4 |
+
import os
|
| 5 |
+
from smolagents import CodeAgent
|
| 6 |
+
import gradio as gr
|
| 7 |
+
|
| 8 |
+
from tools.add_events import add_calendar_event
|
| 9 |
+
from tools.delete_event import delete_calendar_event
|
| 10 |
+
from tools.get_events import get_calendar_events
|
| 11 |
+
from tools.mail_sender import send_calendar_via_email
|
| 12 |
+
from tools.search_events import search_calendar_events
|
| 13 |
+
|
| 14 |
+
from models.groq_model import GroqModel
|
| 15 |
+
|
| 16 |
+
# Groq API anahtarını ortam değişkeninden al
|
| 17 |
+
groq_api_key = os.environ.get("GROQ_API_KEY")
|
| 18 |
+
if not groq_api_key:
|
| 19 |
+
raise ValueError("GROQ_API_KEY ortam değişkeni tanımlı değil.")
|
| 20 |
+
|
| 21 |
+
# Groq Modelini başlat
|
| 22 |
+
groq_model = GroqModel(api_key=groq_api_key)
|
| 23 |
+
|
| 24 |
+
# CodeAgent'ı araçlar ve model ile oluştur
|
| 25 |
+
calendar_agent = CodeAgent(
|
| 26 |
+
tools=[add_calendar_event, delete_calendar_event, get_calendar_events, send_calendar_via_email, search_calendar_events],
|
| 27 |
+
model=groq_model,
|
| 28 |
+
max_steps=5 # İhtiyaca göre ayarlanabilir.
|
| 29 |
+
)
|
| 30 |
+
|
| 31 |
+
def process_message(message, history):
|
| 32 |
+
"""Kullanıcının mesajını alıp agent'a gönderir ve yanıtı döndürür."""
|
| 33 |
+
try:
|
| 34 |
+
agent_response = calendar_agent.run(message)
|
| 35 |
+
history.append((message, agent_response))
|
| 36 |
+
except Exception as e:
|
| 37 |
+
history.append((message, f"Bir hata oluştu: {e}"))
|
| 38 |
+
return history, ""
|
| 39 |
+
|
| 40 |
+
def create_interface():
|
| 41 |
+
with gr.Blocks(title="Takvim Asistanı") as demo:
|
| 42 |
+
gr.Markdown("# 📅 Takvim Asistanı")
|
| 43 |
+
gr.Markdown("""
|
| 44 |
+
Bu asistan Google Calendar'ınızı doğal dil komutlarıyla yönetmenize olanak tanır.
|
| 45 |
+
|
| 46 |
+
**Örnek komutlar:**
|
| 47 |
+
- "Bugünkü programımı göster"
|
| 48 |
+
- "Yarın saat 14:00'da toplantı ekle"
|
| 49 |
+
- "12 Mayıs günü ne var?"
|
| 50 |
+
- "Gelecek hafta Pazartesi 10:00-11:30 arası doktor randevusu ekle"
|
| 51 |
+
""")
|
| 52 |
+
|
| 53 |
+
chatbot = gr.Chatbot(height=500)
|
| 54 |
+
msg = gr.Textbox(placeholder="Takvim asistanınıza sorun veya istekte bulunun...",
|
| 55 |
+
label="Mesajınız")
|
| 56 |
+
clear = gr.Button("Temizle")
|
| 57 |
+
|
| 58 |
+
msg.submit(process_message, [msg, chatbot], [chatbot, msg], queue=True)
|
| 59 |
+
clear.click(lambda: None, None, chatbot, queue=False)
|
| 60 |
+
|
| 61 |
+
# Örnek komutlar için hızlı butonlar
|
| 62 |
+
example_buttons = [
|
| 63 |
+
"Bugünkü programımı göster",
|
| 64 |
+
"Yarın ne var?",
|
| 65 |
+
"Pazartesi toplantı ekle, saat 15:00'da",
|
| 66 |
+
"12 Mayıs günü etkinliklerimi göster"
|
| 67 |
+
]
|
| 68 |
+
|
| 69 |
+
gr.Examples(
|
| 70 |
+
examples=example_buttons,
|
| 71 |
+
inputs=msg
|
| 72 |
+
)
|
| 73 |
+
|
| 74 |
+
return demo
|
| 75 |
+
|
| 76 |
+
if __name__ == '__main__':
|
| 77 |
+
# Arayüzü oluştur ve başlat
|
| 78 |
+
demo = create_interface()
|
| 79 |
+
demo.launch(share=True)
|
models/__pycache__/groq_model.cpython-310.pyc
ADDED
|
Binary file (1.82 kB). View file
|
|
|
models/__pycache__/novita_ai_model.cpython-310.pyc
ADDED
|
Binary file (1.86 kB). View file
|
|
|
models/groq_model.py
ADDED
|
@@ -0,0 +1,40 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
from groq import Groq
|
| 2 |
+
from smolagents.memory import ChatMessage
|
| 3 |
+
import os
|
| 4 |
+
import json
|
| 5 |
+
|
| 6 |
+
class GroqModel:
|
| 7 |
+
"""smolagents ile uyumlu GroqModel sınıfı."""
|
| 8 |
+
def __init__(self, model_name="deepseek-r1-distill-llama-70b", api_key=None):
|
| 9 |
+
self.api_key = api_key or os.environ.get("GROQ_API_KEY")
|
| 10 |
+
if not self.api_key:
|
| 11 |
+
raise ValueError("Groq API anahtarı sağlanmadı veya ortam değişkeninde bulunamadı.")
|
| 12 |
+
self.client = Groq(api_key=self.api_key)
|
| 13 |
+
self.model_name = model_name
|
| 14 |
+
|
| 15 |
+
def generate(self, messages, stop=None, temperature=None, max_tokens=None, stop_sequences=None):
|
| 16 |
+
"""Groq API'sini kullanarak metin üretir."""
|
| 17 |
+
groq_messages = []
|
| 18 |
+
for msg in messages:
|
| 19 |
+
role = msg["role"]
|
| 20 |
+
content = msg["content"]
|
| 21 |
+
if role not in ["system", "user", "assistant"]:
|
| 22 |
+
role = "user" # Geçersiz rolü "user" olarak varsay
|
| 23 |
+
if not isinstance(content, str):
|
| 24 |
+
content = json.dumps(content) # Son çare olarak JSON'a çevir
|
| 25 |
+
groq_messages.append({"role": role, "content": content})
|
| 26 |
+
|
| 27 |
+
response = self.client.chat.completions.create(
|
| 28 |
+
messages=groq_messages,
|
| 29 |
+
model=self.model_name,
|
| 30 |
+
stop=stop,
|
| 31 |
+
temperature=temperature,
|
| 32 |
+
max_tokens=max_tokens
|
| 33 |
+
)
|
| 34 |
+
content = response.choices[0].message.content
|
| 35 |
+
return ChatMessage(role="assistant", content=str(content) if content is not None else "")
|
| 36 |
+
|
| 37 |
+
def __call__(self, messages, stop=None, temperature=None, max_tokens=None, stop_sequences=None):
|
| 38 |
+
"""Sınıfın çağrılabilir olmasını sağlar ve generate metodunu tetikler."""
|
| 39 |
+
output = self.generate(messages, stop, temperature, max_tokens, stop_sequences)
|
| 40 |
+
return {"content": output.content}
|
models/novita_ai_model.py
ADDED
|
@@ -0,0 +1,35 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
from openai import OpenAI
|
| 2 |
+
from smolagents.memory import ChatMessage
|
| 3 |
+
import os
|
| 4 |
+
|
| 5 |
+
class NovitaAIModel:
|
| 6 |
+
"""smolagents ile uyumlu Novita AI Model sınıfı."""
|
| 7 |
+
def __init__(self, model_name, api_key=None, base_url=None, max_tokens=512):
|
| 8 |
+
self.api_key = api_key or os.environ.get("NOVITA_API_KEY")
|
| 9 |
+
self.base_url = base_url or "https://api.novita.ai/v3/openai"
|
| 10 |
+
if not self.api_key:
|
| 11 |
+
raise ValueError("Novita AI API anahtarı sağlanmadı veya ortam değişkeninde bulunamadı.")
|
| 12 |
+
self.client = OpenAI(api_key=self.api_key, base_url=self.base_url)
|
| 13 |
+
self.model_name = model_name
|
| 14 |
+
self.max_tokens = max_tokens
|
| 15 |
+
|
| 16 |
+
def generate(self, messages, stop=None, temperature=None, max_tokens=None, stop_sequences=None):
|
| 17 |
+
"""Novita AI API'sini kullanarak metin üretir."""
|
| 18 |
+
openai_messages = []
|
| 19 |
+
for msg in messages:
|
| 20 |
+
openai_messages.append({"role": msg["role"], "content": msg["content"]})
|
| 21 |
+
|
| 22 |
+
response = self.client.chat.completions.create(
|
| 23 |
+
model=self.model_name,
|
| 24 |
+
messages=openai_messages,
|
| 25 |
+
stop=stop_sequences or stop,
|
| 26 |
+
temperature=temperature if temperature is not None else 1.0, # Varsayılan sıcaklık
|
| 27 |
+
max_tokens=max_tokens if max_tokens is not None else self.max_tokens
|
| 28 |
+
)
|
| 29 |
+
content = response.choices[0].message.content
|
| 30 |
+
return ChatMessage(role="assistant", content=str(content) if content is not None else "")
|
| 31 |
+
|
| 32 |
+
def __call__(self, messages, stop=None, temperature=None, max_tokens=None, stop_sequences=None):
|
| 33 |
+
"""Sınıfın çağrılabilir olmasını sağlar ve generate metodunu tetikler."""
|
| 34 |
+
output = self.generate(messages, stop, temperature, max_tokens, stop_sequences)
|
| 35 |
+
return ChatMessage(role="assistant", content=output.content)
|
requirements.txt
ADDED
|
@@ -0,0 +1,8 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
protobuf~=6.30.2
|
| 2 |
+
google-api-python-client~=2.169.0
|
| 3 |
+
smolagents~=1.15.0
|
| 4 |
+
pytz~=2025.2
|
| 5 |
+
python-dotenv~=1.1.0
|
| 6 |
+
groq~=0.24.0
|
| 7 |
+
openai~=1.75.0
|
| 8 |
+
gradio~=5.27.0
|
tools/__pycache__/add_events.cpython-310.pyc
ADDED
|
Binary file (2.54 kB). View file
|
|
|
tools/__pycache__/delete_event.cpython-310.pyc
ADDED
|
Binary file (2.76 kB). View file
|
|
|
tools/__pycache__/get_events.cpython-310.pyc
ADDED
|
Binary file (3.12 kB). View file
|
|
|
tools/__pycache__/mail_sender.cpython-310.pyc
ADDED
|
Binary file (2.11 kB). View file
|
|
|
tools/__pycache__/search_events.cpython-310.pyc
ADDED
|
Binary file (2.48 kB). View file
|
|
|
tools/add_events.py
ADDED
|
@@ -0,0 +1,72 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import os
|
| 2 |
+
import datetime
|
| 3 |
+
from datetime import timedelta
|
| 4 |
+
|
| 5 |
+
from google.oauth2.credentials import Credentials
|
| 6 |
+
from googleapiclient.discovery import build
|
| 7 |
+
from googleapiclient.errors import HttpError
|
| 8 |
+
from smolagents import tool
|
| 9 |
+
|
| 10 |
+
# Google Calendar API servisini oluştur (her tool çağrıldığında yeniden oluşturulabilir)
|
| 11 |
+
def get_calendar_service():
|
| 12 |
+
creds = Credentials.from_authorized_user_file(os.path.join(os.getcwd(), 'data', 'token.json'), ['https://www.googleapis.com/auth/calendar'])
|
| 13 |
+
service = build('calendar', 'v3', credentials=creds)
|
| 14 |
+
return service
|
| 15 |
+
|
| 16 |
+
@tool
|
| 17 |
+
def add_calendar_event(date_str: str, time: str, description: str) -> str:
|
| 18 |
+
"""
|
| 19 |
+
Google Calendar'a belirtilen tarih ve saatte yeni bir etkinlik ekler.
|
| 20 |
+
|
| 21 |
+
Args:
|
| 22 |
+
date_str (str): Etkinliğin tarihi (YYYY-MM-DD, DD-MM-YYYY veya DD/MM/YYYY formatında olabilir).
|
| 23 |
+
time (str): Etkinliğin başlangıç saati (HH:MM formatında).
|
| 24 |
+
description (str): Etkinliğin açıklaması.
|
| 25 |
+
|
| 26 |
+
Returns:
|
| 27 |
+
str: Etkinliğin başarıyla eklenip eklenmediğine dair bir mesaj.
|
| 28 |
+
"""
|
| 29 |
+
service = get_calendar_service()
|
| 30 |
+
if not service:
|
| 31 |
+
return "Google Calendar servisine bağlanılamadı."
|
| 32 |
+
|
| 33 |
+
try:
|
| 34 |
+
# Tarih formatını esnek bir şekilde işlemeye çalış
|
| 35 |
+
formats_to_try = ["%Y-%m-%d", "%d-%m-%Y", "%d/%m/%Y"]
|
| 36 |
+
event_date = None
|
| 37 |
+
for fmt in formats_to_try:
|
| 38 |
+
try:
|
| 39 |
+
event_date = datetime.datetime.strptime(date_str, fmt).date()
|
| 40 |
+
break
|
| 41 |
+
except ValueError:
|
| 42 |
+
continue
|
| 43 |
+
|
| 44 |
+
if not event_date:
|
| 45 |
+
return "Geçersiz tarih formatı. Lütfen YYYY-MM-DD, DD-MM-YYYY veya DD/MM/YYYY formatlarından birini kullanın."
|
| 46 |
+
|
| 47 |
+
start_time_str = f"{event_date.isoformat()}T{time}:00"
|
| 48 |
+
end_time_str = (datetime.datetime.fromisoformat(start_time_str) + timedelta(hours=1)).isoformat()
|
| 49 |
+
|
| 50 |
+
event = {
|
| 51 |
+
'summary': description,
|
| 52 |
+
'start': {
|
| 53 |
+
'dateTime': start_time_str,
|
| 54 |
+
'timeZone': 'Europe/Istanbul',
|
| 55 |
+
},
|
| 56 |
+
'end': {
|
| 57 |
+
'dateTime': end_time_str,
|
| 58 |
+
'timeZone': 'Europe/Istanbul',
|
| 59 |
+
},
|
| 60 |
+
}
|
| 61 |
+
|
| 62 |
+
created_event = service.events().insert(calendarId='primary', body=event).execute()
|
| 63 |
+
return f"'{description}' etkinliği {event_date.strftime('%d-%m-%Y')} saat {time}'e eklendi. Etkinlik bağlantısı: {created_event.get('htmlLink')}"
|
| 64 |
+
except ValueError:
|
| 65 |
+
return "Geçersiz saat formatı. Lütfen HH:MM formatında girin."
|
| 66 |
+
except HttpError as error:
|
| 67 |
+
return f'Google Calendar hatası: {error}'
|
| 68 |
+
|
| 69 |
+
if __name__ == '__main__':
|
| 70 |
+
# Bu bölüm sadece bu dosyanın doğrudan çalıştırılması durumunda devreye girer.
|
| 71 |
+
# Agent bağlamında kullanılmayacak.
|
| 72 |
+
print("Bu dosya bir araç modülüdür ve doğrudan çalıştırılmamalıdır.")
|
tools/delete_event.py
ADDED
|
@@ -0,0 +1,73 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import os
|
| 2 |
+
import datetime
|
| 3 |
+
from google.oauth2.credentials import Credentials
|
| 4 |
+
from googleapiclient.discovery import build
|
| 5 |
+
from googleapiclient.errors import HttpError
|
| 6 |
+
from smolagents import tool
|
| 7 |
+
|
| 8 |
+
# Google Calendar API servisini oluştur
|
| 9 |
+
def get_calendar_service():
|
| 10 |
+
creds = Credentials.from_authorized_user_file(os.path.join(os.getcwd(), 'data', 'token.json'), ['https://www.googleapis.com/auth/calendar'])
|
| 11 |
+
service = build('calendar', 'v3', credentials=creds)
|
| 12 |
+
return service
|
| 13 |
+
|
| 14 |
+
@tool
|
| 15 |
+
def delete_calendar_event(date_str: str, event_title: str) -> str:
|
| 16 |
+
"""
|
| 17 |
+
Google Calendar'dan belirtilen tarih ve başlığa sahip etkinlikleri siler.
|
| 18 |
+
|
| 19 |
+
Args:
|
| 20 |
+
date_str (str): Etkinliğin silineceği tarih (YYYY-MM-DD, DD-MM-YYYY veya DD/MM/YYYY formatında olabilir).
|
| 21 |
+
event_title (str): Silinecek etkinliğin başlığı (tam veya bir kısmı).
|
| 22 |
+
|
| 23 |
+
Returns:
|
| 24 |
+
str: Etkinliklerin silinme durumuna dair bir mesaj.
|
| 25 |
+
"""
|
| 26 |
+
service = get_calendar_service()
|
| 27 |
+
if not service:
|
| 28 |
+
return "Google Calendar servisine bağlanılamadı."
|
| 29 |
+
|
| 30 |
+
try:
|
| 31 |
+
# Tarih formatını esnek bir şekilde işlemeye çalış
|
| 32 |
+
formats_to_try = ["%Y-%m-%d", "%d-%m-%Y", "%d/%m/%Y"]
|
| 33 |
+
target_date = None
|
| 34 |
+
for fmt in formats_to_try:
|
| 35 |
+
try:
|
| 36 |
+
target_date = datetime.datetime.strptime(date_str, fmt).date()
|
| 37 |
+
break
|
| 38 |
+
except ValueError:
|
| 39 |
+
continue
|
| 40 |
+
|
| 41 |
+
if not target_date:
|
| 42 |
+
return "Geçersiz tarih formatı. Lütfen፦MM-DD, DD-MM-YYYY veya DD/MM/YYYY formatlarından birini kullanın."
|
| 43 |
+
|
| 44 |
+
start_of_day = datetime.datetime(target_date.year, target_date.month, target_date.day, 0, 0, 0, tzinfo=datetime.timezone.utc).isoformat() + 'Z'
|
| 45 |
+
end_of_day = datetime.datetime(target_date.year, target_date.month, target_date.day, 23, 59, 59, 999999, tzinfo=datetime.timezone.utc).isoformat() + 'Z'
|
| 46 |
+
|
| 47 |
+
events_result = service.events().list(calendarId='primary',
|
| 48 |
+
timeMin=start_of_day,
|
| 49 |
+
timeMax=end_of_day,
|
| 50 |
+
singleEvents=True,
|
| 51 |
+
q=event_title).execute()
|
| 52 |
+
events = events_result.get('items', [])
|
| 53 |
+
|
| 54 |
+
deleted_count = 0
|
| 55 |
+
for event in events:
|
| 56 |
+
start = event.get('start', {}).get('dateTime')
|
| 57 |
+
if start and datetime.datetime.fromisoformat(start[:-1]).date() == target_date:
|
| 58 |
+
try:
|
| 59 |
+
service.events().delete(calendarId='primary', eventId=event['id']).execute()
|
| 60 |
+
deleted_count += 1
|
| 61 |
+
except HttpError as error:
|
| 62 |
+
return f"Etkinlik silinirken bir hata oluştu: {error}"
|
| 63 |
+
|
| 64 |
+
if deleted_count > 0:
|
| 65 |
+
return f"{target_date.strftime('%d-%m-%Y')} tarihinde başlığı '{event_title}' olan {deleted_count} etkinlik silindi."
|
| 66 |
+
else:
|
| 67 |
+
return f"{target_date.strftime('%d-%m-%Y')} tarihinde başlığı '{event_title}' olan bir etkinlik bulunamadı."
|
| 68 |
+
|
| 69 |
+
except HttpError as error:
|
| 70 |
+
return f'Google Calendar hatası: {error}'
|
| 71 |
+
|
| 72 |
+
if __name__ == '__main__':
|
| 73 |
+
print("Bu dosya bir araç modülüdür ve doğrudan çalıştırılmamalıdır.")
|
tools/get_events.py
ADDED
|
@@ -0,0 +1,93 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import os
|
| 2 |
+
import datetime
|
| 3 |
+
import pytz
|
| 4 |
+
from google.oauth2.credentials import Credentials
|
| 5 |
+
from googleapiclient.discovery import build
|
| 6 |
+
from googleapiclient.errors import HttpError
|
| 7 |
+
from smolagents import tool
|
| 8 |
+
|
| 9 |
+
# Google Calendar API servisini oluştur
|
| 10 |
+
def get_calendar_service():
|
| 11 |
+
creds = Credentials.from_authorized_user_file(os.path.join(os.getcwd(), 'data', 'token.json'), ['https://www.googleapis.com/auth/calendar'])
|
| 12 |
+
service = build('calendar', 'v3', credentials=creds)
|
| 13 |
+
return service
|
| 14 |
+
|
| 15 |
+
def parse_date_string(date_str: str = None) -> datetime.date or None:
|
| 16 |
+
"""Tarih stringini datetime.date nesnesine çevirir."""
|
| 17 |
+
if not date_str:
|
| 18 |
+
return datetime.date.today()
|
| 19 |
+
date_str = date_str.lower()
|
| 20 |
+
if date_str == "bugün":
|
| 21 |
+
return datetime.date.today()
|
| 22 |
+
elif date_str == "yarın":
|
| 23 |
+
return datetime.date.today() + datetime.timedelta(days=1)
|
| 24 |
+
formats_to_try = ["%Y-%m-%d", "%d-%m-%Y", "%d/%m/%Y"]
|
| 25 |
+
for fmt in formats_to_try:
|
| 26 |
+
try:
|
| 27 |
+
return datetime.datetime.strptime(date_str, fmt).date()
|
| 28 |
+
except ValueError:
|
| 29 |
+
continue
|
| 30 |
+
return None
|
| 31 |
+
|
| 32 |
+
@tool
|
| 33 |
+
def get_calendar_events(date_str: str = None) -> list[str]:
|
| 34 |
+
"""
|
| 35 |
+
Google Calendar'dan belirtilen tarihteki etkinlikleri getirir.
|
| 36 |
+
|
| 37 |
+
Args:
|
| 38 |
+
date_str (str, optional): Etkinliklerin getirileceği tarih (örn: "bugün", "yarın", "15-05-2025").
|
| 39 |
+
Belirtilmezse bugünün etkinliklerini getirir.
|
| 40 |
+
|
| 41 |
+
Returns:
|
| 42 |
+
list[str]: Belirtilen tarihteki etkinliklerin açıklamalarının bir listesi.
|
| 43 |
+
"""
|
| 44 |
+
service = get_calendar_service()
|
| 45 |
+
if not service:
|
| 46 |
+
return "Google Calendar servisine bağlanılamadı."
|
| 47 |
+
|
| 48 |
+
try:
|
| 49 |
+
target_date = parse_date_string(date_str)
|
| 50 |
+
if not target_date:
|
| 51 |
+
return "Geçersiz tarih formatı. Lütfen 'bugün', 'yarın' veya GG-AA-YYYY gibi bir format kullanın."
|
| 52 |
+
|
| 53 |
+
# Mersin saat dilimini kullan
|
| 54 |
+
mersin_tz = pytz.timezone("Europe/Istanbul")
|
| 55 |
+
start_of_day = datetime.datetime(target_date.year, target_date.month, target_date.day, 0, 0, 0, tzinfo=mersin_tz)
|
| 56 |
+
end_of_day = datetime.datetime(target_date.year, target_date.month, target_date.day, 23, 59, 59, 999999, tzinfo=mersin_tz)
|
| 57 |
+
|
| 58 |
+
# ISO formatına dönüştürürken UTC'ye çevirme ("Z" sonekiyle)
|
| 59 |
+
time_min = start_of_day.isoformat()
|
| 60 |
+
time_max = end_of_day.isoformat()
|
| 61 |
+
|
| 62 |
+
events_result = service.events().list(
|
| 63 |
+
calendarId='primary',
|
| 64 |
+
timeMin=time_min,
|
| 65 |
+
timeMax=time_max,
|
| 66 |
+
singleEvents=True,
|
| 67 |
+
orderBy='startTime'
|
| 68 |
+
).execute()
|
| 69 |
+
|
| 70 |
+
events = events_result.get('items', [])
|
| 71 |
+
formatted_events = []
|
| 72 |
+
|
| 73 |
+
for event in events:
|
| 74 |
+
summary = event.get('summary', 'İsimsiz Etkinlik')
|
| 75 |
+
start = event.get('start', {}).get('dateTime')
|
| 76 |
+
end = event.get('end', {}).get('dateTime')
|
| 77 |
+
if not start or not end:
|
| 78 |
+
continue
|
| 79 |
+
start_dt = datetime.datetime.fromisoformat(start)
|
| 80 |
+
end_dt = datetime.datetime.fromisoformat(end)
|
| 81 |
+
formatted = f"{summary}. ({start_dt.strftime('%H:%M')} - {end_dt.strftime('%H:%M')} / {start_dt.strftime('%d-%m-%Y')})"
|
| 82 |
+
formatted_events.append(formatted)
|
| 83 |
+
|
| 84 |
+
if not formatted_events:
|
| 85 |
+
return f"{target_date.strftime('%d-%m-%Y')} tarihinde herhangi bir etkinlik bulunamadı."
|
| 86 |
+
|
| 87 |
+
return formatted_events
|
| 88 |
+
|
| 89 |
+
except HttpError as error:
|
| 90 |
+
return f'Google Calendar hatası: {error}'
|
| 91 |
+
|
| 92 |
+
if __name__ == '__main__':
|
| 93 |
+
print("Bu dosya bir araç modülüdür ve doğrudan çalıştırılmamalıdır.")
|
tools/mail_sender.py
ADDED
|
@@ -0,0 +1,57 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import smtplib
|
| 2 |
+
from email.mime.text import MIMEText
|
| 3 |
+
from email.mime.multipart import MIMEMultipart
|
| 4 |
+
from smolagents import tool
|
| 5 |
+
import os
|
| 6 |
+
from tools.get_events import get_calendar_events # Takvim etkinliklerini almak için
|
| 7 |
+
|
| 8 |
+
@tool
|
| 9 |
+
def send_calendar_via_email(to_email: str, date_str: str) -> str:
|
| 10 |
+
"""
|
| 11 |
+
Belirtilen e-posta adresine, belirtilen tarihteki takvim programını mail olarak gönderir.
|
| 12 |
+
|
| 13 |
+
Args:
|
| 14 |
+
to_email (str): Takvimin gönderileceği e-posta adresi.
|
| 15 |
+
date_str (str): Takviminin alınacağı tarih (örn: "bugün", "yarın", "15-05-2025").
|
| 16 |
+
|
| 17 |
+
Returns:
|
| 18 |
+
str: E-postanın gönderilme durumuna dair bir mesaj. BAŞARILI ifadesi içeriyorsa agent durdurulabilir.
|
| 19 |
+
"""
|
| 20 |
+
from_email = os.environ.get("MAIL_USERNAME")
|
| 21 |
+
password = os.environ.get("MAIL_PASSWORD")
|
| 22 |
+
|
| 23 |
+
if not from_email or not password:
|
| 24 |
+
return "E-posta gönderme bilgileri (.env dosyasında MAIL_USERNAME ve MAIL_PASSWORD tanımlı olmalı) eksik."
|
| 25 |
+
|
| 26 |
+
events = get_calendar_events(date_str=date_str)
|
| 27 |
+
|
| 28 |
+
if isinstance(events, str): # Hata mesajı geldiyse
|
| 29 |
+
return f"Takvim bilgileri alınamadı: {events}"
|
| 30 |
+
|
| 31 |
+
if not events:
|
| 32 |
+
body = f"{date_str} tarihinde herhangi bir etkinliğiniz bulunmamaktadır."
|
| 33 |
+
else:
|
| 34 |
+
body = f"{date_str} tarihli takviminiz aşağıdaki gibidir:\n\n"
|
| 35 |
+
for event in events:
|
| 36 |
+
body += f"- {event}\n"
|
| 37 |
+
|
| 38 |
+
subject = f"{date_str} Takviminiz"
|
| 39 |
+
|
| 40 |
+
msg = MIMEMultipart()
|
| 41 |
+
msg["From"] = from_email
|
| 42 |
+
msg["To"] = to_email
|
| 43 |
+
msg["Subject"] = subject
|
| 44 |
+
msg.attach(MIMEText(body, "plain"))
|
| 45 |
+
|
| 46 |
+
try:
|
| 47 |
+
server = smtplib.SMTP("smtp.gmail.com", 587)
|
| 48 |
+
server.starttls()
|
| 49 |
+
server.login(from_email, password)
|
| 50 |
+
server.send_message(msg)
|
| 51 |
+
server.quit()
|
| 52 |
+
return f"✅ {to_email} adresine {date_str} takviminiz başarıyla gönderildi. BAŞARILI"
|
| 53 |
+
except Exception as e:
|
| 54 |
+
return f"❌ Mail gönderilemedi: {e}"
|
| 55 |
+
|
| 56 |
+
if __name__ == '__main__':
|
| 57 |
+
print("Bu dosya bir araç modülüdür ve doğrudan çalıştırılmamalıdır.")
|
tools/search_events.py
ADDED
|
@@ -0,0 +1,67 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import os
|
| 2 |
+
import datetime
|
| 3 |
+
import pytz
|
| 4 |
+
from google.oauth2.credentials import Credentials
|
| 5 |
+
from googleapiclient.discovery import build
|
| 6 |
+
from googleapiclient.errors import HttpError
|
| 7 |
+
from smolagents import tool
|
| 8 |
+
|
| 9 |
+
# Google Calendar API servisini oluştur
|
| 10 |
+
def get_calendar_service():
|
| 11 |
+
creds = Credentials.from_authorized_user_file(os.path.join(os.getcwd(), 'data', 'token.json'), ['https://www.googleapis.com/auth/calendar'])
|
| 12 |
+
service = build('calendar', 'v3', credentials=creds)
|
| 13 |
+
return service
|
| 14 |
+
|
| 15 |
+
@tool
|
| 16 |
+
def search_calendar_events(event_title: str) -> str:
|
| 17 |
+
"""
|
| 18 |
+
Google Calendar'da belirtilen başlığa sahip etkinlikleri arar ve ilk bulunanın tarihini döndürür.
|
| 19 |
+
|
| 20 |
+
Args:
|
| 21 |
+
event_title (str): Aranacak etkinliğin başlığı (tam veya bir kısmı).
|
| 22 |
+
|
| 23 |
+
Returns:
|
| 24 |
+
str: Bulunan ilk etkinliğin tarihi ve saati hakkında bilgi veya etkinlik bulunamazsa bir mesaj.
|
| 25 |
+
"""
|
| 26 |
+
service = get_calendar_service()
|
| 27 |
+
if not service:
|
| 28 |
+
return "Google Calendar servisine bağlanılamadı."
|
| 29 |
+
|
| 30 |
+
try:
|
| 31 |
+
# Şu anki zamanı UTC olarak al
|
| 32 |
+
now_utc = datetime.datetime.utcnow().isoformat() + 'Z'
|
| 33 |
+
|
| 34 |
+
events_result = service.events().list(calendarId='primary',
|
| 35 |
+
timeMin=now_utc,
|
| 36 |
+
q=event_title,
|
| 37 |
+
singleEvents=True,
|
| 38 |
+
orderBy='startTime').execute()
|
| 39 |
+
events = events_result.get('items', [])
|
| 40 |
+
|
| 41 |
+
if not events:
|
| 42 |
+
return f"'{event_title}' başlıklı herhangi bir etkinlik bulunamadı."
|
| 43 |
+
|
| 44 |
+
# İlk bulunan etkinliğin tarih ve saat bilgisini al
|
| 45 |
+
first_event = events[0]
|
| 46 |
+
start = first_event['start'].get('dateTime')
|
| 47 |
+
if start:
|
| 48 |
+
# Google Calendar'dan gelen zaman bilgisini doğrudan kullan (UTC)
|
| 49 |
+
start_dt_utc = datetime.datetime.fromisoformat(start.replace('Z', '+00:00'))
|
| 50 |
+
# Yerel saat dilimine dönüştür
|
| 51 |
+
local_tz = pytz.timezone("Europe/Istanbul")
|
| 52 |
+
start_dt_local = start_dt_utc.astimezone(local_tz)
|
| 53 |
+
return f"'{event_title}' etkinliği {start_dt_local.strftime('%d %B %Y')} tarihinde saat {start_dt_local.strftime('%H:%M')} itibarıyla planlanmıştır."
|
| 54 |
+
else:
|
| 55 |
+
# Tüm günlük etkinlikler için sadece tarihi döndür
|
| 56 |
+
start_date = first_event['start'].get('date')
|
| 57 |
+
if start_date:
|
| 58 |
+
start_dt = datetime.datetime.strptime(start_date, '%Y-%m-%d').date()
|
| 59 |
+
return f"'{event_title}' etkinliği {start_dt.strftime('%d %B %Y')} tarihinde tüm gün sürecektir."
|
| 60 |
+
else:
|
| 61 |
+
return f"'{event_title}' etkinliğinin başlangıç tarihi bilgisi bulunamadı."
|
| 62 |
+
|
| 63 |
+
except HttpError as error:
|
| 64 |
+
return f'Google Calendar hatası: {error}'
|
| 65 |
+
|
| 66 |
+
if __name__ == '__main__':
|
| 67 |
+
print("Bu dosya bir araç modülüdür ve doğrudan çalıştırılmamalıdır.")
|