weather

package
v1.45.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jul 7, 2026 License: Apache-2.0 Imports: 16 Imported by: 0

Documentation

Index

Constants

View Source
const (
	Hostname    = weatherapi.Hostname
	Version     = weatherapi.Version
	Description = weatherapi.Description
)

Variables

This section is empty.

Functions

This section is empty.

Types

type Intermediate

type Intermediate struct {
	*connector.Connector
	ToDo
}

Intermediate extends and customizes the generic base connector.

func NewIntermediate

func NewIntermediate(impl ToDo) *Intermediate

NewIntermediate creates a new instance of the intermediate.

type Mock

type Mock struct {
	*Intermediate
	// contains filtered or unexported fields
}

Mock is a mockable version of the microservice, allowing functions, event sinks and web handlers to be mocked.

func NewMock

func NewMock() *Mock

NewMock creates a new mockable version of the microservice.

func (*Mock) Answer

func (svc *Mock) Answer(ctx context.Context, flow *workflow.Flow, question string) (answer string, err error)

Answer executes the mock handler.

func (*Mock) Ask

func (svc *Mock) Ask(ctx context.Context, q string) (answer string, err error)

Ask executes the mock handler.

func (*Mock) AskAgent

func (svc *Mock) AskAgent(ctx context.Context) (graph *workflow.Graph, err error)

AskAgent returns the workflow graph, or a mocked graph if MockAskAgent was called.

func (*Mock) Forecast

func (svc *Mock) Forecast(ctx context.Context, lat float64, lng float64) (summary string, temperatureC float64, precipitationChance int, err error)

Forecast executes the mock handler.

func (*Mock) LatLng

func (svc *Mock) LatLng(ctx context.Context, location string) (lat float64, lng float64, err error)

LatLng executes the mock handler.

func (*Mock) MockAnswer

func (svc *Mock) MockAnswer(handler func(ctx context.Context, flow *workflow.Flow, question string) (answer string, err error)) *Mock

MockAnswer sets up a mock handler for Answer.

func (*Mock) MockAsk

func (svc *Mock) MockAsk(handler func(ctx context.Context, q string) (answer string, err error)) *Mock

MockAsk sets up a mock handler for Ask.

func (*Mock) MockAskAgent

func (svc *Mock) MockAskAgent(handler func(ctx context.Context, flow *workflow.Flow, question string) (answer string, err error)) *Mock

MockAskAgent sets up a mock handler for the AskAgent workflow. The handler receives typed inputs from the workflow's state and returns typed outputs. A nil handler clears the mock.

func (*Mock) MockForecast

func (svc *Mock) MockForecast(handler func(ctx context.Context, lat float64, lng float64) (summary string, temperatureC float64, precipitationChance int, err error)) *Mock

MockForecast sets up a mock handler for Forecast.

func (*Mock) MockLatLng

func (svc *Mock) MockLatLng(handler func(ctx context.Context, location string) (lat float64, lng float64, err error)) *Mock

MockLatLng sets up a mock handler for LatLng.

func (*Mock) OnShutdown

func (svc *Mock) OnShutdown(ctx context.Context) (err error)

OnShutdown is called when the microservice is shut down.

func (*Mock) OnStartup

func (svc *Mock) OnStartup(ctx context.Context) (err error)

OnStartup is called when the microservice is started up.

type Service

type Service struct {
	*Intermediate // IMPORTANT: Do not remove

}

Service implements the weather.example agent, which answers natural-language weather questions. It geocodes a location to coordinates and fetches that location's forecast, exposing both as LLM tools and letting the model chain them to answer a question.

func NewService

func NewService() *Service

NewService creates a new instance of the microservice.

func (*Service) Answer

func (svc *Service) Answer(ctx context.Context, flow *workflow.Flow, question string) (answer string, err error)

Answer runs the LLM tool-calling loop for a weather question, chaining the LatLng and Forecast tools, and returns the agent's reply.

func (*Service) Ask

func (svc *Service) Ask(ctx context.Context, q string) (answer string, err error)

Ask runs the weather agent synchronously for a natural-language question and returns its answer. It executes the same tool-calling loop as the AskAgent workflow, but in-process via a single llm.core Chat call rather than as a durable workflow, giving the tour one browser-clickable endpoint.

func (*Service) AskAgent

func (svc *Service) AskAgent(ctx context.Context) (graph *workflow.Graph, err error)

AskAgent answers a natural-language weather question. It runs the LLM tool-calling loop as a durable workflow, letting the model geocode a location with LatLng and fetch its forecast with Forecast before composing a reply.

func (*Service) Forecast

func (svc *Service) Forecast(ctx context.Context, lat float64, lng float64) (summary string, temperatureC float64, precipitationChance int, err error)

Forecast returns the current weather forecast for a latitude/longitude coordinate.

func (*Service) Init

func (svc *Service) Init(initializer func(svc *Service) (err error)) *Service

Init enables a single-statement pattern for initializing the microservice.

func (*Service) LatLng

func (svc *Service) LatLng(ctx context.Context, location string) (lat float64, lng float64, err error)

LatLng geocodes a location name into its latitude and longitude coordinates.

func (*Service) OnShutdown

func (svc *Service) OnShutdown(ctx context.Context) (err error)

OnShutdown is called when the microservice is shut down.

func (*Service) OnStartup

func (svc *Service) OnStartup(ctx context.Context) (err error)

OnStartup is called when the microservice is started up.

type ToDo

type ToDo interface {
	OnStartup(ctx context.Context) (err error)
	OnShutdown(ctx context.Context) (err error)
	LatLng(ctx context.Context, location string) (lat float64, lng float64, err error)                                                 // MARKER: LatLng
	Forecast(ctx context.Context, lat float64, lng float64) (summary string, temperatureC float64, precipitationChance int, err error) // MARKER: Forecast
	Ask(ctx context.Context, q string) (answer string, err error)                                                                      // MARKER: Ask
	Answer(ctx context.Context, flow *workflow.Flow, question string) (answer string, err error)                                       // MARKER: Answer
	AskAgent(ctx context.Context) (graph *workflow.Graph, err error)                                                                   // MARKER: AskAgent
}

ToDo is implemented by the service or mock. The intermediate delegates handling to this interface.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL