What AI Algorithms Are Implemented in AiToEarn?

AiToEarn integrates GPT-4, DALL-E, Sora, Claude, and Gemini through a modular LangChain architecture, with all providers isolated in distinct service classes under the core/ai/ directory.

The yikart/AiToEarn repository implements a comprehensive AI orchestration layer that unifies multiple generative models behind a consistent TypeScript interface. Rather than training proprietary networks, the platform leverages enterprise-grade APIs from OpenAI, Anthropic, and Google, abstracting vendor-specific implementations into injectable services. This architecture allows the application to route content generation tasks to the optimal AI algorithms implemented in AiToEarn based on task type, cost, or quality requirements.

OpenAI GPT Models for Chat and Text Completion

The primary large language model integration resides in project/aitoearn-backend/apps/aitoearn-ai/src/core/ai/libs/openai/openai.service.ts. This service instantiates ChatOpenAI from the @langchain/openai package, configuring it with models such as gpt-3.5-turbo and gpt-4.

For low-level SDK access, the Electron backend uses project/aitoearn-electron/server/src/modules/tools/ai.service.ts, which directly imports the openai npm package. Both implementations expose createChatCompletion for synchronous responses and createChatCompletionStream for Server-Sent Events (SSE) streaming, ultimately calling OpenAI’s /v1/chat/completions endpoint.

// From openai.service.ts (LangChain wrapper)
const chat = new ChatOpenAI({
  apiKey: this.config.apiKey,
  model: options.model ?? 'gpt-4',
  temperature: options.temperature ?? 0.7,
});
const response = await chat.call(messages);

OpenAI DALL-E for Image Generation

Image synthesis is handled within the same openai.service.ts file through the createImageGeneration method. This function wraps the OpenAI SDK’s images.generate endpoint, supporting both dall-e-2 and dall-e-3 models.

The service constructs an ImageGenerateParams payload containing the prompt, size (e.g., 1024x1024), and generation count. Results return as hosted URLs or base64 data, depending on the API configuration.

const result = await this.openai.images.generate({
  prompt: 'A futuristic city skyline at sunset',
  model: 'dall-e-3',
  size: '1024x1024',
});
return result.data[0].url;

OpenAI Sora for Video Generation

Video creation leverages the Sora family of models in project/aitoearn-backend/apps/aitoearn-ai/src/core/ai/video/openai/openai.service.ts. The service supports sora-2, sora-2-pro, and sora-2-character variants through the OpenAI SDK’s videos namespace.

The implementation follows an asynchronous polling pattern: createVideo initiates the task, returning a task ID that the service monitors via retrieve until the generation status indicates completion. Character-specific generation uses the sora-2-character model to produce consistent avatars for animation sequences.

const task = await this.openai.videos.create({
  model: 'sora-2',
  prompt: 'A cat walking on a beach at sunrise',
});
const videoUrl = await this.pollTaskUntilReady(task.id);

Anthropic Claude for Conversational AI

Claude integration resides in project/aitoearn-backend/apps/aitoearn-ai/src/core/ai/chat/chat.service.ts, utilizing the raw @anthropic-ai/sdk without LangChain abstraction. The service supports claude-2.1 and claude-3-sonnet models.

For real-time interactions, the service implements anthropic.messages.stream, consuming RawMessageStreamEvent objects and forwarding them as SSE chunks to the frontend. Synchronous completions use anthropic.completions.create for standard request-response cycles.

const claude = new Anthropic({ apiKey: process.env.ANTHROPIC_API_KEY });
const stream = await claude.messages.stream({
  model: 'claude-3-sonnet-20240229',
  max_tokens: 1024,
  messages: [{ role: 'user', content: 'Explain quantum computing' }],
});
for await (const chunk of stream) {
  yield chunk.delta?.text;
}

Google Gemini for Content Adaptation

Google’s Generative AI is integrated via @langchain/google-genai in two primary locations: project/aitoearn-backend/apps/aitoearn-ai/src/core/material-adaptation/material-adaptation.service.ts and draft-generation.service.ts. These services instantiate ChatGoogleGenerativeAI with models like gemini-1.5-pro and gemini-1.0-flash.

The material adaptation service constructs specific prompts using LangChain’s HumanMessage and SystemMessage patterns, asking Gemini to rewrite or optimize existing content for different platforms. Draft generation uses similar patterns to create initial content outlines from minimal input.

const gemini = new ChatGoogleGenerativeAI({
  apiKey: config.ai.google.apiKey,
  model: 'gemini-1.5-pro',
});
const result = await gemini.call([
  new HumanMessage('Rewrite this for TikTok: ' + originalText)
]);

LangChain Orchestration and Provider Abstraction

Across all implementations, LangChain core message types (BaseMessage, AIMessage, HumanMessage) standardize prompt construction. The OpenAI service in openai.service.ts includes utility methods to convert between API-specific message formats and LangChain’s internal representations.

This abstraction layer ensures that higher-level business logic in material-adaptation.service.ts or chat.service.ts remains provider-agnostic, calling generic call() or stream() methods without managing vendor-specific payload structures.

Summary

The AI algorithms implemented in AiToEarn consist exclusively of managed API integrations rather than custom model training:

  • OpenAI GPT-4/3.5: Chat and completion via ChatOpenAI in openai.service.ts
  • OpenAI DALL-E: Image generation via createImageGeneration in openai.service.ts
  • OpenAI Sora: Video synthesis via videos.create in video/openai/openai.service.ts
  • Anthropic Claude: Streaming chat via @anthropic-ai/sdk in chat.service.ts
  • Google Gemini: Content adaptation via ChatGoogleGenerativeAI in material and draft services
  • LangChain: Message standardization and streaming utilities across all providers

Frequently Asked Questions

Does AiToEarn train its own AI models?

No. According to the source code analysis, AiToEarn does not implement custom neural network training. The platform functions as an orchestration layer that routes requests to commercial APIs including OpenAI, Anthropic, and Google, wrapping their responses in a unified service architecture.

Which file contains the GPT-4 integration?

The primary GPT-4 integration using LangChain resides in project/aitoearn-backend/apps/aitoearn-ai/src/core/ai/libs/openai/openai.service.ts. A lower-level OpenAI SDK implementation for the Electron backend exists in project/aitoearn-electron/server/src/modules/tools/ai.service.ts.

How does AiToEarn handle video generation?

Video generation uses OpenAI’s Sora models (sora-2, sora-2-pro) implemented in project/aitoearn-backend/apps/aitoearn-ai/src/core/ai/video/openai/openai.service.ts. The service initiates asynchronous jobs and polls the API until the video asset is ready for delivery.

Can developers add new AI providers to AiToEarn?

Yes. The codebase follows a modular service pattern where each provider (OpenAI, Anthropic, Google) is encapsulated in its own injectable class. Adding a new provider requires creating a similar service file under core/ai/ that implements the same interface methods (e.g., createChatCompletion, stream), allowing immediate integration with the existing LangChain message abstractions.

Have a question about this repo?

These articles cover the highlights, but your codebase questions are specific. Give your agent direct access to the source. Share this with your agent to get started:

Share the following with your agent to get started:
curl -s "https://instagit.com/install.md"

Works with
Claude Codex Cursor VS Code OpenClaw Any MCP Client

Maintain an open-source project? Get it listed too →