Telnyx AI Inference를 사용하여 엣지(Edge)에서 URL 요약기 구축하기
요약
Telnyx Edge Compute와 AI Inference를 활용하여 엣지 환경에서 URL 요약기를 구축하는 방법을 소개합니다. 별도의 데이터베이스 없이 Stateful Actor를 사용하여 요약 결과를 캐싱함으로써 효율적인 인프라 운영 패턴을 보여줍니다.
핵심 포인트
- Telnyx Edge Compute를 이용한 엣지 기반 URL 요약 구현
- Stateful Actor를 활용한 데이터베이스 없는 캐싱 메커니즘
- AI Inference 모델(GLM-5.2)을 통한 구조화된 JSON 응답 생성
- Node.js 및 TypeScript 기반의 실전 개발 가이드 제공
저는 소규모 AI 도구에 유용하다고 느껴지는 패턴을 실험해 왔습니다:
- 요청 수락
- AI 모델 호출
- 요청이 실행되는 위치와 가까운 곳에 결과 캐싱 (Cache)
- 실제로 필요할 때까지 추가 인프라 구축을 피함
이 예제는 Telnyx Edge Compute Stateful Actors를 사용하여 URL 요약에 해당 패턴을 적용합니다.
코드: https://github.com/team-telnyx/telnyx-code-examples/tree/main/edge-url-summarizer
구축 내용
이 앱은 Node.js / TypeScript Edge Compute 예제입니다.
URL을 전송하면 다음과 같이 작동합니다:
curl -X POST https://edge-url-summarizer-<id>.telnyxcompute.com/summarize \
-H "Content-Type: application/json" \
-d '{"url":"https://telnyx.com/blog"}'
첫 번째 요청 시 다음 과정을 수행합니다:
- 페이지 가져오기 (Fetch)
- HTML에서 텍스트 추출
- 텍스트를 Telnyx AI Inference로 전송
- 정확히 세 개의 불렛 포인트 (Bullet points) 요청
- 결과를 Stateful Actor 저장소에 저장
동일한 URL에 대한 반복 요청 시에는 캐싱된 요약본을 반환합니다.
API 라우트 (API routes)
예제에는 다음이 포함되어 있습니다:
POST /summarize- URL 요약GET /summarize/cached?url=...- 캐싱된 요약 읽기POST /summarize/refresh- 캐싱된 URL 무효화GET /stats- 캐시 히트/미스 (Cache hit/miss) 통계 보기GET /cached- 캐싱된 URL 목록 나열GET /health/liveness- 활성 상태 체크 (Liveness check)GET /health/readiness- 준비 상태 체크 (Readiness check)
응답 예시
{
"url": "https://example.com/article",
"title": "Example Article",
...
동일한 URL을 다시 호출하면 다음과 같은 응답이 돌아옵니다:
{
"cached": true
}
Telnyx AI 호출
앱은 다음을 호출합니다:
POST /v2/ai/chat/completions
현재 샘플은 다음을 사용합니다:
zai-org/GLM-5.2
모델은 JSON만 반환하도록 프롬프트(Prompt)가 설정되어 있습니다:
{
"bullets": ["point 1", "point 2", "point 3"]
}
이를 통해 대시보드, 워크플로(Workflow) 또는 내부 도구에서 앱 응답을 쉽게 소비할 수 있습니다.
Stateful Actor 부분
캐시는 Telnyx Stateful Actor 내에 저장됩니다.
Actor는 다음 항목들을 저장합니다:
- URL별 요약 (summaries by URL)
- 캐시 히트 (cache hits)
- 캐시 미스 (cache misses)
- 총 요청 수 (total requests)
- 고유 URL 수 (unique URL count)
즉, 이 데모를 위해 Redis나 별도의 데이터베이스를 추가하지 않고도 앱이 이전 요약 내용을 기억할 수 있음을 의미합니다.
실행하기 (Run it)
리포지토리(repo)를 클론합니다:
git clone https://github.com/team-telnyx/telnyx-code-examples.git
cd telnyx-code-examples/edge-url-summarizer
Telnyx API 키를 설정합니다:
telnyx-edge auth api-key set <YOUR_API_KEY>
telnyx-edge secrets add TELNYX_API_KEY "KEY0123..."
설치 및 배포합니다:
npm install
telnyx-edge ship
배포를 테스트합니다:
curl -sS --retry 30 --retry-delay 5 \
https://edge-url-summarizer-<id>.telnyxcompute.com/health/liveness
페이지를 요약합니다:
curl -X POST https://edge-url-summarizer-<id>.telnyxcompute.com/summarize \
-H "Content-Type: application/json" \
-d '{"url":"https://telnyx.com/blog"}'
캐시 통계를 확인합니다:
curl https://edge-url-summarizer-<id>.telnyxcompute.com/stats
프로덕션 적용 전 추가하고 싶은 사항들
프로덕션(production) 버전을 위해서는 다음 사항들을 추가하겠습니다:
- 인증 (authentication)
- 속도 제한 (rate limiting)
- URL 허용 목록 (allowlists) 또는 SSRF 방지 (SSRF protections)
- URL 정규화 (URL normalization)
- TTL 기반 캐시 만료 (TTL-based cache expiration)
- 더 나은 HTML 추출 (HTML extraction)
- 재시도 및 관찰 가능성 (retries and observability)
하지만 실행 가능한 예제로서, 이는 Edge Compute, Stateful Actors, 그리고 Telnyx AI Inference가 함께 작동하는 모습을 볼 수 있는 깔끔한 방법입니다.
Resources:
자료(Resources):
- Code: https://github.com/team-telnyx/telnyx-code-examples/tree/main/edge-url-summarizer
- Stateful Actors Quick Start: https://developers.telnyx.com/docs/edge-compute/stateful-actors/quick-start
- Telnyx AI Inference docs: https://developers.telnyx.com/docs/inference
- Chat Completions API: https://developers.telnyx.com/api/inference/chat-completions
- Telnyx AI skills and toolkits: https://github.com/team-telnyx/ai
AI 자동 생성 콘텐츠
본 콘텐츠는 Dev.to AI tag의 원문을 AI가 자동으로 요약·번역·분석한 것입니다. 원 저작권은 원저작자에게 있으며, 정확한 내용은 반드시 원문을 확인해 주세요.
원문 바로가기