SDKs overview

AI For Thai provides official SDKs to facilitate interaction with its suite of Thai language processing APIs. These SDKs abstract the underlying HTTP requests and API authentication, allowing developers to integrate services such as Word Segmentation, Part-of-Speech Tagging, and Sentiment Analysis into their applications with reduced boilerplate code. The primary supported languages for official SDKs are Python and JavaScript, catering to common backend and frontend development environments.

The SDKs are designed to simplify tasks like sending requests, handling responses, and managing API keys, as detailed in the AI For Thai developer documentation. Utilizing an SDK can streamline development workflow compared to direct API calls, particularly for developers who prefer to work within their chosen language ecosystem. For instance, the Python SDK integrates seamlessly with Python development practices for data handling and function calls.

In addition to the official offerings, the open-source nature of many development communities often leads to the creation of third-party libraries. While these community-contributed tools can offer alternative approaches or extend functionality, developers should verify their maintenance status and compatibility with the official AI For Thai API specifications before deployment. Adhering to the official SDKs ensures direct support and adherence to the API's intended usage patterns.

Official SDKs by language

AI For Thai maintains official SDKs for Python and JavaScript, providing structured access to its API endpoints. These SDKs encapsulate API calls, authentication, and error handling, allowing developers to focus on application logic. The official SDKs are regularly updated to reflect new API features and improvements, ensuring compatibility and optimal performance.

The following table summarizes the key details of the official SDKs:

Language Package Name Install Command Maturity
Python aiforthai pip install aiforthai Stable
JavaScript aiforthai npm install aiforthai or yarn add aiforthai Stable

These SDKs are designed to provide a consistent interface across different services offered by AI For Thai, including text processing, speech recognition, and machine translation. Developers can refer to the official AI For Thai documentation portal for detailed API specifications and usage guidelines tailored to each SDK.

Installation

Installing the AI For Thai SDKs involves using standard package managers for Python and JavaScript environments. Before installation, developers should ensure their development environment meets the necessary prerequisites, such as having Python 3.6+ or Node.js 12+ installed.

Python SDK

The Python SDK for AI For Thai is available via PyPI, the Python Package Index. Installation is performed using pip, Python's package installer.

pip install aiforthai

After installation, the package can be imported into Python scripts to access AI For Thai functionalities. It is recommended to install SDKs within a Python virtual environment to manage dependencies and avoid conflicts with other projects.

JavaScript SDK

The JavaScript SDK is distributed through npm (Node Package Manager) and can be installed using either npm or yarn.

# Using npm
npm install aiforthai

# Using yarn
yarn add aiforthai

Once installed, the SDK can be imported into Node.js applications or bundled for browser-side use with tools like Webpack or Rollup. The JavaScript module system allows for selective imports of specific functions or the entire library.

Quickstart example

This section provides basic code examples demonstrating how to use the official AI For Thai SDKs to perform a common task, such as word segmentation (tokenization), which is one of the core products offered by AI For Thai.

Python Quickstart: Word Segmentation

To use the Python SDK, first initialize the client with your API key. Replace YOUR_API_KEY with your actual key obtained from the AI For Thai dashboard. This example performs word segmentation on a Thai sentence.

from aiforthai.feats import segment

# Replace with your actual AI For Thai API key
api_key = "YOUR_API_KEY"

text_to_segment = "สวัสดีประเทศไทย"

try:
    # Call the segment API
    result = segment(text_to_segment, apikey=api_key)
    print(f"Original text: {text_to_segment}")
    print(f"Segmented words: {result.get('words')}")
except Exception as e:
    print(f"An error occurred: {e}")

This snippet imports the segment function from the aiforthai.feats module, passes the text and API key, and then prints the segmented words. Error handling is included to catch potential issues during the API call.

JavaScript Quickstart: Word Segmentation

The JavaScript SDK follows a similar pattern. Initialize the client and then call the desired API function. This example is suitable for Node.js environments.

const aiforthai = require('aiforthai');

// Replace with your actual AI For Thai API key
const apiKey = "YOUR_API_KEY";

const textToSegment = "สวัสดีประเทศไทย";

async function performSegmentation() {
  try {
    // Initialize the client with the API key
    const client = new aiforthai.Client(apiKey);

    // Call the segment API
    const result = await client.segment(textToSegment);

    console.log(`Original text: ${textToSegment}`);
    console.log(`Segmented words: ${result.words}`);
  } catch (error) {
    console.error(`An error occurred: ${error.message}`);
  }
}

performSegmentation();

This JavaScript example uses async/await for handling the asynchronous API call, which is a common pattern in modern JavaScript development. The aiforthai.Client is instantiated with the API key, and then the segment method is called.

Community libraries

While AI For Thai provides official SDKs, the broader developer community may also contribute third-party libraries or wrappers. These community-driven projects can sometimes offer additional features, alternative interfaces, or support for languages not officially covered. For example, developers might create extensions that integrate AI For Thai services with specific frameworks or tools.

When considering community libraries, developers should evaluate several factors:

  • Maintenance Status: Check if the library is actively maintained and updated to reflect changes in the AI For Thai API.
  • Documentation: Assess the quality and completeness of the library's documentation.
  • Community Support: Look for an active community (e.g., GitHub issues, forums) that can provide assistance.
  • License: Understand the licensing terms of the library, especially for commercial projects.
  • Security: Verify the library's security practices, particularly if it handles sensitive data or API keys.

Examples of common platforms where such libraries might be found include GitHub, PyPI (for Python), and npm (for JavaScript). Searching for aiforthai alongside the desired programming language or framework can reveal community contributions. For instance, developers often look for Google Cloud Natural Language client libraries or AWS SDKs for comparison in terms of community tool availability. While community libraries can be valuable, official SDKs are generally recommended for stability, support, and direct compatibility with the API's current version.