Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -109,4 +109,4 @@ mypy_path = "."

[build-system]
requires = ["poetry-core"]
build-backend = "poetry.core.masonry.api"
build-backend = "poetry.core.masonry.api"
11 changes: 11 additions & 0 deletions setup.py
Original file line number Diff line number Diff line change
@@ -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',
],
)
1 change: 1 addition & 0 deletions skills/weatherwise/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
from .weatherwise_skill import WeatherWise
15 changes: 15 additions & 0 deletions skills/weatherwise/base.py
Original file line number Diff line number Diff line change
@@ -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))
50 changes: 50 additions & 0 deletions skills/weatherwise/schema.json
Original file line number Diff line number Diff line change
@@ -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
}
43 changes: 43 additions & 0 deletions skills/weatherwise/weatherwise_skill.py
Original file line number Diff line number Diff line change
@@ -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!"
)