SDKs overview
Machinetutors provides Software Development Kits (SDKs) to facilitate the integration of its AI capabilities into developer workflows and applications. These SDKs abstract the underlying RESTful API, offering language-specific interfaces and helper functions for common tasks such as code generation, explanation, and debugging. The official SDKs are designed to enhance developer experience by simplifying API calls and managing authentication, consistent with best practices for API client libraries Google's API design guide on client libraries.
The primary advantage of using an SDK over direct API calls is the reduction of boilerplate code and the provision of an idiomatic interface for the chosen programming language. This includes type hints, error handling mechanisms, and streamlined request/response models. Machinetutors maintains official SDKs for popular languages, with a focus on developer productivity.
Official SDKs by language
Machinetutors offers official SDKs for Python and Node.js, enabling developers to integrate AI assistance directly into their applications or development environments. These SDKs are maintained by Machinetutors and provide a consistent way to interact with the Machinetutors API. The table below outlines the key details for each official SDK.
| Language | Package Name | Installation Command | Maturity |
|---|---|---|---|
| Python | machinetutors-sdk |
pip install machinetutors-sdk |
Stable |
| Node.js | @machinetutors/sdk |
npm install @machinetutors/sdk or yarn add @machinetutors/sdk |
Stable |
Installation
Installing the Machinetutors SDKs is performed using standard package managers for each respective language. Prior to installation, ensure that you have the appropriate runtime environment set up (Python 3.8+ for the Python SDK, Node.js 14+ for the Node.js SDK).
Python SDK Installation
To install the Machinetutors Python SDK, use pip:
pip install machinetutors-sdk
This command downloads and installs the latest version of the machinetutors-sdk package from the Python Package Index (PyPI).
Node.js SDK Installation
For Node.js projects, the Machinetutors SDK can be installed via npm or yarn:
npm install @machinetutors/sdk
Or alternatively, with yarn:
yarn add @machinetutors/sdk
These commands add the @machinetutors/sdk package to your project's dependencies.
Quickstart example
The following examples demonstrate how to use the Machinetutors SDKs to generate Python code for a simple function. Before running these examples, ensure you have set your Machinetutors API key as an environment variable (MACHINETUTORS_API_KEY) or pass it directly during client initialization.
Python Quickstart
This Python example uses the machinetutors-sdk to request a code snippet for calculating the factorial of a number.
import os
from machinetutors_sdk import MachinetutorsClient
# Initialize the client with your API key from environment variable
# Alternatively, pass it directly: client = MachinetutorsClient(api_key="YOUR_API_KEY")
client = MachinetutorsClient()
def generate_factorial_function():
try:
prompt = "Write a Python function to calculate the factorial of a non-negative integer."
response = client.code.generate(
prompt=prompt,
language="python",
max_tokens=150
)
print("Generated Python Code:")
print(response.code)
except Exception as e:
print(f"An error occurred: {e}")
if __name__ == "__main__":
generate_factorial_function()
Node.js Quickstart
This Node.js example uses the @machinetutors/sdk to generate a JavaScript function for string reversal.
require('dotenv').config(); // For loading API key from .env file
const { MachinetutorsClient } = require('@machinetutors/sdk');
// Initialize the client with your API key from environment variable
// Alternatively, pass it directly: const client = new MachinetutorsClient({ apiKey: "YOUR_API_KEY" });
const client = new MachinetutorsClient();
async function generateStringReverseFunction() {
try {
const prompt = "Write a JavaScript function to reverse a given string.";
const response = await client.code.generate({
prompt: prompt,
language: "javascript",
maxTokens: 100
});
console.log("Generated JavaScript Code:");
console.log(response.code);
} catch (error) {
console.error(`An error occurred: ${error.message}`);
}
}
generateStringReverseFunction();
Community libraries
While Machinetutors provides official SDKs for Python and Node.js, the open nature of APIs often encourages the development of community-contributed libraries and integrations. These community efforts can extend functionality, provide bindings for other programming languages, or offer specialized tooling that complements the official offerings.
Community libraries are developed and maintained independently by developers. Their quality, features, and ongoing support can vary. Developers considering community libraries should review their source code, check for active maintenance, and consult community forums or repositories for feedback and bug reports. For instance, many API providers, including those in the cloud computing sector, see a wide array of community-driven tools emerge for different use cases AWS provides a range of SDKs, alongside community tooling.
As of the current date, Machinetutors' official documentation primarily focuses on its first-party SDKs. Developers interested in contributing to or finding community-developed libraries are encouraged to explore platforms like GitHub, PyPI (for Python), and npm (for Node.js) by searching for machinetutors or related terms. These platforms serve as central repositories for open-source projects and developer tools, facilitating discovery and collaboration within the developer community Machinetutors documentation portal.
Common types of community contributions might include:
- Client Libraries for Other Languages: Implementations for languages not officially supported, such as Go, Ruby, Java, or C#.
- Editor Plugins: Integrations with code editors like VS Code, IntelliJ IDEA, or Sublime Text, providing in-editor access to Machinetutors' features.
- CLI Tools: Command-line interfaces that allow developers to interact with the Machinetutors API without writing full scripts.
- Framework Integrations: Adaptations for specific web frameworks (e.g., Django, Flask, Express) to streamline usage within those ecosystems.
- Specialized Utilities: Tools for specific tasks like prompt engineering experimentation, API response parsing, or advanced error logging.
Developers are advised to always verify the security and reliability of any third-party library before incorporating it into production environments. The Machinetutors developer community forums, if available, or the official documentation's support section, would be the most appropriate places to look for officially recognized or recommended community-contributed tools.