Telnyx AI Inference를 사용하여 엣지 작물 자문 API 구축하기
요약
Telnyx AI Inference를 활용하여 엣지 환경에서 작동하는 작물 자문 API 구축 방법을 소개합니다. 현장의 비정형 데이터를 분석하여 구조화된 JSON으로 변환하고, 심각도에 따른 에스컬레이션 기능을 제공하는 실무적인 AI 워크플로우를 다룹니다.
핵심 포인트
- 엣지 컴퓨팅 기반의 AI 워크플로우 구현 방식 제시
- 비정형 텍스트 및 URL 입력을 구조화된 JSON 데이터로 변환
- Stateful Actor를 활용한 자문 이력 및 통계 관리
- 심각도 분류를 통한 전문가 개입(Escalation) 경로 구축
저는 이것을 Edge URL Summarizer 예제의 다음 단계로 구축했습니다. URL Summarizer는 간단한 패턴을 보여주었습니다: 엣지(edge)에서 AI 워크플로우를 실행하고, 필요할 때 외부 콘텐츠를 가져와 요약하며, 유용한 상태(state)를 요청 근처에 유지하는 것입니다. 이 작물 자문(crop advisory) 예제는 동일한 패턴을 보다 실제적인 워크플로우로 확장합니다.
단순히 페이지를 요약하는 대신, 이 앱은 농부의 현장 노트나 농업 자문 URL을 수락하여, 작물 문제를 분류하고, 구조화된 JSON을 반환하며, 자문 내용을 Stateful Actor에 저장하고, 문제/심각도 통계를 추적하며, 에스컬레이션(escalation)이 필요한 심각한 사례를 표시합니다.
따라서 목표는 진공 상태에서 "AI가 농업 조언을 제공하는 것"이 아닙니다. 목표는 엣지에 호스팅된 AI 앱이 어떻게 무질서한 현장 입력을 운영 가능한 것(triage, 이력, 통계, 그리고 인간 전문가의 개입이 필요한 경우 명확한 인계 경로)으로 전환할 수 있는지 보여주는 것입니다.
Code: https://github.com/team-telnyx/telnyx-code-examples/tree/main/edge-agri-crop-advisory
기능
앱에 작물 문제 설명을 보냅니다:
curl -X POST https://edge-agri-crop-advisory-<id>.telnyxcompute.com/advisory \
-H "Content-Type: application/json" \
-d '{"description":"Tomato leaves have holes all over them. I can see green caterpillars on the underside of the leaves."}'
그러면 구조화된 자문을 반환합니다:
{
"id": "adv-msf1zxyc-0",
"farmer_description": "Tomato leaves have holes...",
...
사례가 심각한 경우, 다음과 같이 표시됩니다:
{
"severity": "critical",
"escalate": true,
...
라우트 (Routes)
이 예제에는 다음이 포함됩니다:
POST /advisory- 자문 생성GET /advisories- 최근 자문 목록 조회GET /advisories/<id>- 특정 자문 조회GET /stats- 문제/심각도/에스컬레이션 통계 확인GET /health/liveness- liveness 체크GET /health/readiness- readiness 체크
POST /advisory는 다음 중 하나를 수락합니다:
description(설명)url(URL)
URL을 전달하면, 앱이 해당 페이지를 가져와 HTML을 제거한 후 그 텍스트를 입력값으로 사용합니다.
AI 호출 (The AI call)
앱은 다음을 호출합니다:
POST /v2/ai/chat/completions
현재 코드 경로는 다음을 사용합니다:
zai-org/GLM-5.2
프롬프트(Prompt)는 모델에게 다음 항목만을 포함하는 JSON을 반환하도록 요청합니다:
crop_type(작물 유형)issue_type(문제 유형)severity(심각도)confidence(신뢰도)recommendation(권장 사항)
문제 유형(Issue types)은 다음으로 제한됩니다:
disease | pest | nutrient | water | weather | unknown
심각도(Severity)는 다음으로 제한됩니다:
low | medium | high | critical
이러한 구조는 응답을 저장, 표시, 라우팅(Route) 및 검토하기를 더 쉽게 만듭니다.
Stateful Actor 부분
앱은 CropAdvisory Stateful Actor를 사용합니다.
다음 항목을 저장합니다:
- ID별 자문(Advisories)
- 총 자문 횟수
- 문제 유형별 횟수
- 심각도별 횟수
- 에스컬레이션(Escalation) 횟수
- 최근 작물 유형
따라서 몇 번의 요청을 보낸 후에는 축적된 통계를 확인할 수 있습니다:
curl https://edge-agri-crop-advisory-<id>.telnyxcompute.com/stats
실행하기 (Run it)
저장소(Repo)를 클론(Clone)합니다:
git clone https://github.com/team-telnyx/telnyx-code-examples.git
cd telnyx-code-examples/edge-agri-crop-advisory
Telnyx API 키를 설정합니다:
telnyx-edge auth api-key set <YOUR_API_KEY>
telnyx-edge secrets add TELNYX_API_KEY "KEY0123..."
설치 및 배포:
npm install
telnyx-edge ship
헬스 체크 (Health check):
curl -sS --retry 30 --retry-delay 5 \
https://edge-agri-crop-advisory-<id>.telnyxcompute.com/health/liveness
자문 생성하기:
curl -X POST https://edge-agri-crop-advisory-<id>.telnyxcompute.com/advisory \
-H "Content-Type: application/json" \
-d '{"description":"My corn has yellow streaks on bottom leaves with dark brown spots. About 30% of plants affected."}'
프로덕션 참고 사항 (Production notes)
이것은 분류(Triage)를 위한 예시이며, 농학자(Agronomist)를 대체하는 것이 아닙니다.
이 패턴을 프로덕션 환경에서 사용하기 전에, 저는 다음과 같은 사항을 추가하겠습니다:
- 인증 (authentication)
- 농부/계정 신원 (farmer/account identity)
- 지역 및 작물 단계 (region and crop stage)
- 사진 입력 (photo input)
- 날씨 데이터 (weather data)
- 높음 및 심각한 사례에 대한 인간 검토 (human review for high and critical cases)
- 현지화된 처방 가이드 (localized treatment guidance)
- 안전 경고 (safety warnings)
- SMS 또는 웹훅 에스컬레이션 (SMS or webhook escalation)
그럼에도 불구하고, 이 패턴은 유용합니다: 입력을 위한 엣지 함수 (edge function), 구조화된 분류를 위한 AI 모델 (AI model), 자문 이력 및 통계를 위한 상태 유지 액터 (Stateful Actor).
리소스:
- 코드: https://github.com/team-telnyx/telnyx-code-examples/tree/main/edge-agri-crop-advisory
- Stateful Actors 퀵 스타트: https://developers.telnyx.com/docs/edge-compute/stateful-actors/quick-start
- Telnyx AI Inference 문서: https://developers.telnyx.com/docs/inference
- Chat Completions API: https://developers.telnyx.com/api/inference/chat-completions
- Telnyx AI 기술 및 툴킷: https://github.com/team-telnyx/ai
AI 자동 생성 콘텐츠
본 콘텐츠는 Dev.to AI tag의 원문을 AI가 자동으로 요약·번역·분석한 것입니다. 원 저작권은 원저작자에게 있으며, 정확한 내용은 반드시 원문을 확인해 주세요.
원문 바로가기