package main
import (
"fmt"
"net/url"
"strings"
"github.com/hypermodeinc/modus/sdk/go/pkg/http"
"github.com/hypermodeinc/modus/sdk/go/pkg/models"
"github.com/hypermodeinc/modus/sdk/go/pkg/models/openai"
)
type WeatherIntel struct {
City string `json:"city"`
Temperature float64 `json:"temperature"`
Conditions string `json:"conditions"`
Analysis string `json:"analysis"`
}
const modelName = "text-generator"
// Function: Gather weather data and provide tactical analysis
func GatherWeatherIntelligence(city string) (*WeatherIntel, error) {
city = url.QueryEscape(city)
// Fetch weather data from OpenWeatherMap API
url := fmt.Sprintf(
"https://api.openweathermap.org/data/2.5/weather?q=%s&units=metric",
city,
)
response, err := http.Fetch(url)
if err != nil {
return nil, err
}
if !response.Ok() {
return nil, fmt.Errorf(
"weather data retrieval failed: %d %s",
response.Status,
response.StatusText,
)
}
// Parse weather data
var weatherData struct {
Name string `json:"name"`
Main struct {
Temp float64 `json:"temp"`
} `json:"main"`
Weather []struct {
Description string `json:"description"`
} `json:"weather"`
}
response.JSON(&weatherData)
conditions := "unknown"
if len(weatherData.Weather) > 0 {
conditions = weatherData.Weather[0].Description
}
// Generate tactical analysis
analysis, err := analyzeTacticalConditions(
weatherData.Name,
weatherData.Main.Temp,
conditions,
)
if err != nil {
fmt.Printf("Analysis failed for %s: %v\n", weatherData.Name, err)
analysis = "Analysis unavailable - proceed with standard protocols"
}
return &WeatherIntel{
City: weatherData.Name,
Temperature: weatherData.Main.Temp,
Conditions: conditions,
Analysis: analysis,
}, nil
}
// Analyze weather conditions for tactical implications
func analyzeTacticalConditions(city string, temp float64, conditions string) (string, error) {
model, err := models.GetModel[openai.ChatModel](modelName)
if err != nil {
return "", err
}
prompt := `You are a tactical analyst evaluating weather conditions for field operations.
Provide a brief tactical assessment of how these weather conditions might impact
outdoor activities, visibility, and operational considerations in 1-2 sentences.`
content := fmt.Sprintf(
"Location: %s, Temperature: %.1f°C, Conditions: %s",
city,
temp,
conditions,
)
input, err := model.CreateInput(
openai.NewSystemMessage(prompt),
openai.NewUserMessage(content),
)
if err != nil {
return "", err
}
input.Temperature = 0.7
output, err := model.Invoke(input)
if err != nil {
return "", err
}
return strings.TrimSpace(output.Choices[0].Message.Content), nil
}