Skip to main content

Implementing Connector Output

Overview

This guide will walk you through the process of implementing the output from a connector. This process involves understanding the connector's responses, handling both success and error cases, managing the output, and mapping the response from the connector to your application.

Key Steps

Prerequisites

Prior to starting this tutorial, it's crucial to have a basic understanding of creating and integrating a connector. If you're not familiar with these processes, we recommend going through our previous tutorials to gain the necessary background knowledge.

Understanding the Official Model Documentation

Learning and understanding the official documentation regarding your model is a vital step in this process. This knowledge will help you understand the various responses you can receive from the connector. It's also important to familiarize yourself with potential errors and limitations that may occur during the process.

Handling Successful and Error Cases

Implementing output from your connector necessitates careful handling of both successful and erroneous scenarios. This is a critical aspect of the implementation, as it ensures your application can effectively respond to all possible outcomes of the connector's operation.

In the case of a successful operation, your application can proceed with the next step in its process. Conversely, should an error occur, your application can trigger a suitable error handling mechanism. This balanced approach ensures the smooth operation of your application, irrespective of the result of the connector's execution.

Here's an illustrative example of how to handle errors:

const mapErrorToCompletion = (error: any, model: string): ErrorCompletion => {
const errorMessage = error.message || JSON.stringify(error);

return {
choices: [],
error: errorMessage,
model,
usage: undefined,
};
};

Managing Output

A practical way to manage this output is via the method of response mapping. This process involves translating the data received from the connector into a format that your application can readily use.

Here's an example of how to manage response mapping:

interface ConnectorResponse {
Completions: { Content: T | ErrorCompletion; TokenUsage: number }[];
ModelType: string;
}

const mapToResponse = (
outputs: Array<T | ErrorCompletion>,
model: string
): ConnectorResponse => {};

In the above code, T can either be your custom type or simply the response from the API model.

By implementing a robust strategy for managing your connector's output, you can ensure your application operates optimally, effectively handling the data it receives and using it to deliver the desired results.

Testing Your Connector

Once you've successfully implemented the output from the connector, it's crucial to thoroughly test it under various scenarios to ensure it operates optimally. This will help you identify any issues or bugs that may disrupt its functionality.