Skip to content

Open-source platform for 3D AI agents. Turn text or a photo into a rigged, animated GLB avatar, give it an LLM brain, memory and a wallet, and embed it anywhere with one web component. Remote MCP server, x402 payments, Three.js, browser-native.

980 B
Raw Blame
// POST /api/v1/sentiment — classify text sentiment.
//
// Unified-API surface over the same deterministic lexicon scorer that backs
// /api/sentiment and /api/social/sentiment (src/social/sentiment.js), so the
// classification is identical no matter which door a caller comes through.

import { defineEndpoint, fail } from '../_lib/gateway.js';
import { scoreSentiment } from '../../src/social/sentiment.js';

export default defineEndpoint({
	name: 'v1.sentiment',
	method: 'POST',
	auth: 'public',
	handler: ({ body }) => {
		const text = typeof body?.text === 'string' ? body.text.trim() : '';
		if (!text) fail(400, 'validation_error', '"text" must be a non-empty string');

		const r = scoreSentiment([{ text }]);
		let sentiment = 'Neutral';
		if (r.posPct > 0 && r.posPct >= r.negPct) sentiment = 'Positive';
		else if (r.negPct > 0) sentiment = 'Negative';

		return {
			sentiment,
			score: r.score,
			positive_pct: r.posPct,
			negative_pct: r.negPct,
		};
	},
});