How to use the thingtalk.version function in thingtalk

To help you get started, we’ve selected a few thingtalk examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github stanford-oval / almond-cloud / tests / nlp / parserclient.js View on Github external
sendUtterance(utterance, expecting, choices) {
        const store = 'no';
        const data = {
            q: utterance,
            store: store,
            thingtalk_version: ThingTalk.version,
        };
        if (expecting)
            data.expect = String(expecting);

        let url = `${this._baseUrl}/query?${qs.stringify(data)}`;

        // we need to do this one by hand because of the peculiar encoding
        // of the keys (we must not escape [ and ])
        if (choices) {
            choices.forEach((c, i) => {
                if (c)
                    url += `&choices[${i}]=${encodeURIComponent(c.title)}`;
            });
        }

        return Tp.Helpers.Http.get(url).then((data) => {
github stanford-oval / almond-cloud / browser / deps / thingpediaclient.js View on Github external
getSchemas(kinds, withMetadata) {
        var to = THINGPEDIA_URL + '/api/v3/schema/' + kinds.join(',');
        to += '?locale=' + this.locale;
        to += '&thingtalk_version=' + ThingTalk.version;
        if (withMetadata)
            to += '&meta=1';
        if (this.developerKey)
            to += '&developer_key=' + this.developerKey;
        return this._simpleRequest(to, true);
    }
github stanford-oval / almond-cloud / browser / deps / parserclient.js View on Github external
onlineLearn(utterance, code, store = 'automatic', user = null) {
        if (Array.isArray(code))
            code = code.join(' ');
        if (typeof code !== 'string')
            throw new TypeError('Invalid code parameter to onlineLearn');
        return Promise.resolve($.ajax(this._baseUrl + '/learn', {
            method: 'POST',
            data: {
                q: utterance,
                target: code,
                store,
                owner: user,
                thingtalk_version: ThingTalk.version,
                developer_key: this._developerKey
            }
        })).catch((e) => {
            if ('responseJSON' in e && 'error' in e.responseJSON) {
                if (e.responseJSON.error === 'Missing owner for commandpedia command')
                    throw new Error('You need to log in to add new command.');
                throw new Error('Failed to store the new sentence: ' + e.responseJSON.error);
            } else {
                throw e;
            }

        });
    }
github stanford-oval / genie-toolkit / tool / lib / parserclient.js View on Github external
async sendUtterance(utterance, tokenized, contextCode, contextEntities) {
        const data = {
            q: utterance,
            store: 'no',
            thingtalk_version: ThingTalk.version,
        };

        let response;
        if (contextCode !== undefined) {
            data.context = contextCode.join(' ');
            data.entities = contextEntities;
            data.tokenized = tokenized;
            data.skip_typechecking = true;

            response = await Tp.Helpers.Http.post(`${this._baseUrl}/query`, JSON.stringify(data), {
                dataContentType: 'application/json'
            });
        } else {
            data.tokenized = tokenized ? '1' : '';
            data.skip_typechecking = '1';
github stanford-oval / almond-cloud / nlp / learn.js View on Github external
"use strict";

const express = require('express');
const ThingTalk = require('thingtalk');
const Tp = require('thingpedia');

const router = express.Router();

const db = require('../util/db');
const iv = require('../util/input_validation');
const I18n = require('../util/i18n');
const userModel = require('../model/user');
const exampleModel = require('../model/example');
const Config = require('../config');

const LATEST_THINGTALK_VERSION = ThingTalk.version;

async function learn(req, res) {
    let store = req.body.store;
    if (['no', 'automatic', 'online', 'commandpedia'].indexOf(store) < 0) {
        res.status(400).json({ error: 'Invalid store parameter' });
        return;
    }
    const owner = req.body.owner;
    if (store === 'commandpedia' && !owner) {
        res.status(400).json({ error: 'Missing owner for commandpedia command' });
        return;
    }

    if (!I18n.get(req.params.locale, false)) {
        res.status(404).json({ error: 'Unsupported language' });
        return;
github stanford-oval / almond-dialog-agent / lib / parserclient.js View on Github external
async sendUtterance(utterance, context, expecting, choices) {
        const store = this._prefs.get('sabrina-store-log') || 'no';
        const data = {
            q: utterance,
            store: store,
            thingtalk_version: ThingTalk.version,
        };
        if (this._platform)
            data.developer_key = this._platform.getDeveloperKey();
        if (expecting)
            data.expect = String(expecting);
        if (choices)
            data.choices = choices.map((c) => c.title);

        if (this._prefs.get('experimental-contextual-model')) {
            const now = new Date;
            if (context.timeout > now) {
                data.context = context.code;
                data.entities = context.entities;
            } else {
                data.context = 'null';
                data.entities = {};