diff --git a/pyproject.toml b/pyproject.toml index 25420f5b..e6945ce0 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -109,4 +109,4 @@ mypy_path = "." [build-system] requires = ["poetry-core"] -build-backend = "poetry.core.masonry.api" +build-backend = "poetry.core.masonry.api" \ No newline at end of file diff --git a/setup.py b/setup.py new file mode 100644 index 00000000..2716e59b --- /dev/null +++ b/setup.py @@ -0,0 +1,11 @@ +from setuptools import setup, find_packages + +setup( + name='intentkit', + version='0.1', + packages=find_packages(), + install_requires=[ + # Misalnya, jika ada dependensi lain seperti: + # 'pydantic', + ], +) diff --git a/skills/weatherwise/__init__.py b/skills/weatherwise/__init__.py new file mode 100644 index 00000000..38da7f0f --- /dev/null +++ b/skills/weatherwise/__init__.py @@ -0,0 +1 @@ +from .weatherwise_skill import WeatherWise diff --git a/skills/weatherwise/base.py b/skills/weatherwise/base.py new file mode 100644 index 00000000..859fda00 --- /dev/null +++ b/skills/weatherwise/base.py @@ -0,0 +1,15 @@ +from intentkit.agent.skills.base import BaseSkill +from .weatherpulse_skill import FetchWeatherForecast, FetchWeatherAlerts + + +class WeatherPulseSkill(BaseSkill): + """ + WeatherPulseSkill adalah kumpulan fungsi untuk mendapatkan prakiraan cuaca dan peringatan cuaca + dari sumber API eksternal. + """ + + def __init__(self, config): + super().__init__(config=config) + + self.add_state("fetch_weather_forecast", FetchWeatherForecast(config)) + self.add_state("fetch_weather_alerts", FetchWeatherAlerts(config)) diff --git a/skills/weatherwise/schema.json b/skills/weatherwise/schema.json new file mode 100644 index 00000000..9caebd69 --- /dev/null +++ b/skills/weatherwise/schema.json @@ -0,0 +1,50 @@ +{ + "$schema": "http://json-schema.org/draft-07/schema#", + "type": "object", + "title": "WeatherWise Skill", + "description": "Analyze current weather conditions based on location input.", + "x-icon": "https://ai.service.crestal.dev/skills/weatherwise/weatherwise.png", + "x-tags": ["Data", "Weather"], + "x-api-key": "required", + "properties": { + "enabled": { + "type": "boolean", + "title": "Enabled", + "description": "Whether this skill is enabled", + "default": false + }, + "states": { + "type": "object", + "properties": { + "analyze_weather": { + "type": "string", + "title": "Analyze Weather", + "enum": ["disabled", "public", "private"], + "x-enum-title": ["Disabled", "Agent Owner + All Users", "Agent Owner Only"], + "default": "disabled", + "description": "Fetches and interprets current weather conditions." + } + }, + "description": "States for each WeatherWise skill (disabled, public, or private)" + }, + "api_key": { + "type": "string", + "title": "OpenWeather API Key", + "x-link": "[Get your API key](https://openweathermap.org/api)", + "x-sensitive": true, + "description": "API key for accessing OpenWeather API" + } + }, + "required": ["enabled", "states"], + "if": { + "properties": { + "enabled": { + "const": true + } + } + }, + "then": { + "required": ["api_key"] + }, + "additionalProperties": true +} diff --git a/skills/weatherwise/weatherwise_skill.py b/skills/weatherwise/weatherwise_skill.py new file mode 100644 index 00000000..d6a2cfab --- /dev/null +++ b/skills/weatherwise/weatherwise_skill.py @@ -0,0 +1,43 @@ +from pydantic import BaseModel, Field +from langchain_core.runnables import RunnableConfig +import requests + +from intentkit.core.tool import IntentKitTool +from intentkit.core.skill_config import SkillConfig +from intentkit.core.skill_states import SkillStates + +class Config(SkillConfig): + states: SkillStates + api_key: str + +class WeatherWiseInput(BaseModel): + location: str = Field(description="Location (city name or city,country_code) to fetch weather for.") + +class WeatherWise(IntentKitTool): + name = "analyze_weather" + description = "Get and analyze current weather conditions for a given location." + input_schema = WeatherWiseInput + + def __init__(self, config: Config): + self.api_key = config.api_key + super().__init__() + + async def _arun(self, config: RunnableConfig, location: str) -> str: + context = self.context_from_config(config) + url = f"http://api.openweathermap.org/data/2.5/weather?q={location}&appid={self.api_key}&units=metric" + response = requests.get(url) + if response.status_code != 200: + return f"Failed to fetch weather for {location}. Please check the location and try again." + + data = response.json() + desc = data["weather"][0]["description"] + temp = data["main"]["temp"] + humidity = data["main"]["humidity"] + + return ( + f"Current weather in {location}:\n" + f"- Condition: {desc}\n" + f"- Temperature: {temp}°C\n" + f"- Humidity: {humidity}%\n" + f"This information may help you plan your day better!" + )