Azion AI Client module

The Azion AI Client library provides a simple interface to interact with the Azion AI API. This specialized AI has contextual knowledge about all Azion products, services, and technologies, allowing for precise and relevant responses about Azion Edge Computing Platform.

Go to Azion Libraries Overview

You can interact with the API using a client or calling the methods directly from the library. When making direct calls, you can use the environment variables to configure the client without passing the token and debug parameters directly.

This is an example of how a .env file with your environment variables may look like:

Terminal window
AZION_TOKEN=your-api-token
AZION_DEBUG=true
VariableDescription
AZION_TOKENYour Azion API token.
AZION_DEBUGEnable debug mode (true/false).

Usage

createClient

Creates an Azion AI client with methods to interact with AI services.

import { createClient, AzionAIClient } from '@azion/ai';
const client: AzionAIClient = createClient({
token: 'your-token-here', // Replace with your actual token
options: {
// Add any additional options here
}
});

Parameters:

ParameterTypeDescription
configPartial<{ token: string; options?: AzionClientOptions }>Optional configuration for the client.

Returns:

Return TypeDescription
AzionAIClientA client object with methods to interact with AI services.

chat

Sends a chat request to the Azion AI service.

TypeScript example:

import { chat } from 'azion/ai';
import type { AzionAIRequest, AzionAIResponse, AzionAIResult } from '@azion/ai';
const request: AzionAIRequest = {
messages: [{ role: 'user', content: 'Explain what Azion Edge Computing is.' }]
};
const { data: response, error }: AzionAIResult<AzionAIResponse> = await chat(request, { debug: true });
if (response) {
console.log('AI response:', response.choices[0].message.content);
} else {
console.error('Chat failed', error);
}

Parameters:

ParameterTypeDescription
request: AzionAIRequestPartial<{ token: string; options?: OptionsParams }>Request object containing chat parameters.
options AzionClientOptionsPartial<{ token: string; options?: OptionsParams }>Additional client options.

Returns:

Return TypeDescription
Promise<AzionAIResult<AzionAIResponse>>A promise that resolves to the chat result or an error.

streamChat

Sends a streaming chat request to the Azion AI service.

TypeScript example:

import { streamChat } from 'azion/ai';
import type { AzionAIRequest, AzionAIStreamResponse, AzionAIResult } from '@azion/ai';
const request: AzionAIRequest = {
messages: [{ role: 'user', content: 'List 5 use cases for Azion Edge Functions.' }]
};
const stream = streamChat(request, { debug: true });
for await (const chunk: AzionAIResult<AzionAIStreamResponse> of stream) {
if (chunk.data) {
process.stdout.write(chunk.data.choices[0].delta.content || '');
} else {
console.error('Error:', chunk.error);
}
}

Parameters:

ParameterTypeDescription
request: AzionAIRequestPartial<{ token: string; options?: OptionsParams }>Request object containing chat parameters.
options AzionClientOptionsPartial<{ token: string; options?: OptionsParams }>Additional client options.

Returns:

Return TypeDescription
AsyncGenerator<AzionAIResult<AzionAIStreamResponse>>An async generator that produces partial chat results.


Contributors