@fnet/io
v0.1.37
Published
## Introduction
Downloads
30
Readme
@fnet/io
Introduction
@fnet/io
is a tool designed to facilitate the automation of generating JSON schemas based on source code analysis. It integrates with OpenAI's API to process and interpret source code, specifically focusing on the default exports and their argument structures. The project focuses on creating a YAML-only schema format without additional commentary or explanations. This can be useful for software developers looking to easily generate schemas from their existing codebase.
How It Works
The project operates by taking source code as input and processing it through a series of steps to generate a YAML schema. It utilizes OpenAI's API for analyzing the default export functions or classes within the code. The workflow involves loading configuration, preparing a prompt for OpenAI, executing this prompt, and finally writing the schema to a file.
Key Features
- Source Code Analysis: Analyzes JavaScript code to focus on the default export and its arguments.
- OpenAI Integration: Utilizes OpenAI's capabilities to automate the schema creation process.
- YAML Output: Produces YAML-only JSON schemas for ease of use in various development operations.
- File Handling: Manages the reading and writing of necessary files during the process.
- Workflow Automation: Implements a structured workflow to streamline the coding-to-schema transformation.
Conclusion
@fnet/io
modestly aids developers by automating the intricate process of schema generation from source code. Its straightforward approach to analyzing code and producing YAML schemas can simplify workflow for developers requiring schema documents without manual intervention.
Developer Guide for @fnet/io
Overview
The @fnet/io
library is designed to facilitate workflow automation through orchestration of various tasks primarily involving the OpenAI API. The library provides an engine with a structured workflow for tasks such as reading source files, preparing prompts, executing them via OpenAI's API, and handling the results. Developers can leverage this library to automate complex workflows involving AI prompts and responses.
Installation
To install the @fnet/io
library, run one of the following commands in your project directory:
Using npm:
npm install @fnet/io
Using yarn:
yarn add @fnet/io
Usage
The primary usage of the @fnet/io
library revolves around its Engine
class, which orchestrates a sequence of tasks. Here's a basic usage scenario:
- Initialize the
Engine
. - Run the workflow with parameters defined in the context.
Basic Example
import FnetEngine from '@fnet/io';
async function runWorkflow() {
const engine = new FnetEngine();
const params = {
file: 'path/to/source/file.js',
title: 'My Document Title'
};
try {
await engine.run(params);
} catch (error) {
console.error('An error occurred:', error);
}
}
runWorkflow();
Examples
Running a Workflow
This example demonstrates how to create and run a workflow using the engine:
import FnetEngine from '@fnet/io';
const params = {
file: 'myfile.js', // The source file to be read
title: 'Example Title' // Optional title parameter
};
async function execute() {
const engine = new FnetEngine();
try {
const result = await engine.run(params);
console.log('Workflow result:', result);
} catch (e) {
console.error('Error during workflow execution:', e);
}
}
execute();
Handling Workflow Transitions
Given that the engine processes tasks in a sequence, you can handle transitions between different blocks or steps in the workflow:
import FnetEngine from '@fnet/io';
async function runWithTransitionHandling() {
const engine = new FnetEngine();
const params = { file: 'script.js', title: 'Example Script' };
const result = await engine.run(params);
// Process the resulting value if needed
if (result) {
console.log('Processed result:', result);
}
}
runWithTransitionHandling();
Acknowledgement
This library makes use of OpenAI's API for certain tasks. Ensure you have valid API credentials set in your environment variables to use the library effectively.
Input Schema
$schema: https://json-schema.org/draft/2020-12/schema
type: object
properties:
file:
type: string
description: The source file path to be set in the workflow.
title:
type: string
description: The title to be set in the workflow.