### Simple General.AI Quick Start Source: https://github.com/nixaut-codelabs/general.ai/blob/main/README.md This snippet demonstrates how to initialize GeneralAI with an OpenAI client and generate a simple response using the agent. It shows basic setup and a common use case for generating text. ```typescript import OpenAI from "openai"; import { GeneralAI } from "@lightining/general.ai"; const openai = new OpenAI({ apiKey: process.env.OPENAI_API_KEY, }); const generalAI = new GeneralAI({ openai }); const result = await generalAI.agent.generate({ endpoint: "chat_completions", model: "gpt-5.4-mini", messages: [ { role: "user", content: "Say hello briefly in Turkish." }, ], }); console.log(result.cleaned); ``` -------------------------------- ### Install General.AI with Bun Source: https://github.com/nixaut-codelabs/general.ai/blob/main/README.md Install the General.AI package and the 'openai' package using Bun. This is the recommended installation method for Bun environments. ```bash bun add @lightining/general.ai openai ``` -------------------------------- ### Install General.AI with npm Source: https://github.com/nixaut-codelabs/general.ai/blob/main/README.md Install the General.AI package and the 'openai' package using npm. This is the standard installation method for Node.js environments. ```bash npm install @lightining/general.ai openai ``` -------------------------------- ### Install Beta Version of General.AI with Bun Source: https://github.com/nixaut-codelabs/general.ai/blob/main/README.md Install the beta version of the General.AI package using Bun to access the latest runtime features and capabilities. This is for users who want to test the newest developments in a Bun environment. ```bash bun add @lightining/general.ai@beta openai ``` -------------------------------- ### Install Beta Version of General.AI with npm Source: https://github.com/nixaut-codelabs/general.ai/blob/main/README.md Install the beta version of the General.AI package using npm to access the latest runtime features and capabilities. This is for users who want to test the newest developments. ```bash npm install @lightining/general.ai@beta openai ``` -------------------------------- ### Render Prompts with Task Context Override Source: https://github.com/nixaut-codelabs/general.ai/blob/main/README.md Example of rendering prompts using the General.AI SDK, specifically overriding the task section with block content. ```typescript const prompt = await generalAI.agent.renderPrompts({ endpoint: "responses", model: "gpt-5.4-mini", messages: [{ role: "user", content: "Hello" }], prompts: { sections: { task: "Task override.\n{block:task_context}", }, }, }); ``` -------------------------------- ### Advanced Agent Generation with Tools and Subagents Source: https://github.com/nixaut-codelabs/general.ai/blob/main/README.md Demonstrates an advanced agent generation call that utilizes tools, subagents, and context management. This example showcases General.AI's orchestration capabilities. ```typescript const result = await generalAI.agent.generate({ endpoint: "chat_completions", model: "gpt-5.4-mini", messages: [ { role: "user", content: "Use tools if needed, delegate arithmetic to a subagent if useful, and give me a short final answer.", }, ], compatibility: { profile: "classic_v2", }, tools: { registry: [weatherTool, calculatorTool], }, subagents: { registry: [mathHelper], }, context: { mode: "auto", strategy: "hybrid", }, }); console.log(result.cleaned); console.log(result.meta.contextOperations); console.log(result.meta.warnings); ``` -------------------------------- ### Initialize OpenAI Client with General.AI Source: https://github.com/nixaut-codelabs/general.ai/blob/main/README.md Demonstrates how to initialize the GeneralAI client using an existing OpenAI client. Ensure your OPENAI_API_KEY is set in the environment. ```typescript import OpenAI from "openai"; import { GeneralAI } from "@lightining/general.ai"; const openai = new OpenAI({ apiKey: process.env.OPENAI_API_KEY, }); const generalAI = new GeneralAI({ openai }); const result = await generalAI.agent.generate({ endpoint: "chat_completions", model: "gpt-5.4-mini", preset: "classic_safe", intelligence: "high", messages: [ { role: "user", content: "Say hello briefly in Turkish." }, ], }); console.log(result.cleaned); console.log(result.meta.warnings); console.log(result.meta.performance.speed); console.log(result.meta.configuration); ``` -------------------------------- ### Initialize General.AI with Provider Configuration Source: https://github.com/nixaut-codelabs/general.ai/blob/main/README.md Shows how to initialize GeneralAI by directly configuring the provider, including API keys, rotation strategies, and queue settings. Ensure NVIDIA_KEY_A and NVIDIA_KEY_B are set in the environment. ```typescript import { GeneralAI } from "@lightining/general.ai"; const generalAI = new GeneralAI({ provider: { baseURL: "https://integrate.api.nvidia.com/v1", apiKeys: [ process.env.NVIDIA_KEY_A!, process.env.NVIDIA_KEY_B!, ], rotation: { strategy: "round_robin", onRateLimit: "next_key", maxRateLimitHandoffs: 2, }, queue: { maxConcurrentRequests: 3, }, }, }); ``` -------------------------------- ### Run Manual Test Script Source: https://github.com/nixaut-codelabs/general.ai/blob/main/README.md Execute the manual test script using bun. This script can also exercise optional live provider checks. ```bash bun run test.js ``` -------------------------------- ### Configure Provider Pool and Queue Source: https://github.com/nixaut-codelabs/general.ai/blob/main/README.md Initialize GeneralAI with a provider configuration, including API keys, rotation strategy, and queue management. Ensure environment variables for API keys are set. ```typescript const generalAI = new GeneralAI({ provider: { name: "nvidia", baseURL: "https://integrate.api.nvidia.com/v1", apiKeys: [ { key: process.env.NVIDIA_KEY_A!, label: "nvidia-a" }, { key: process.env.NVIDIA_KEY_B!, label: "nvidia-b" }, { key: process.env.NVIDIA_KEY_C!, label: "nvidia-c" }, ], rotation: { strategy: "round_robin", onRateLimit: "next_key", maxRateLimitHandoffs: 3, revisitKeysInSameRequest: false, }, queue: { enabled: true, maxConcurrentRequests: 3, maxQueuedRequests: 100, strategy: "fifo", }, }, }); ``` -------------------------------- ### Apply Raw Prompt Overrides Source: https://github.com/nixaut-codelabs/general.ai/blob/main/README.md Demonstrates how to apply raw prompt overrides by prepending, appending, or replacing the entire rendered prompt content. ```typescript prompts: { raw: { prepend: "Extra preamble", append: "Extra appendix", replace: "Replace the entire rendered prompt", }, } ``` -------------------------------- ### Run Default Tests Source: https://github.com/nixaut-codelabs/general.ai/blob/main/README.md Execute deterministic tests using npm. This command runs the standard test suite for the project. ```bash npm test ``` -------------------------------- ### Native SDK: Create Response Source: https://github.com/nixaut-codelabs/general.ai/blob/main/README.md Uses the native General.AI interface to create a response, mimicking OpenAI SDK behavior. This is suitable when exact OpenAI compatibility is required. ```typescript const response = await generalAI.native.responses.create({ model: "gpt-5.4-mini", input: "Give a one-sentence explanation of prompt caching.", }); ``` -------------------------------- ### Set Environment Variables for Live Provider Checks Source: https://github.com/nixaut-codelabs/general.ai/blob/main/README.md Configure environment variables to enable live provider checks in manual test scripts. Set API key, base URL, and model, or skip live checks. ```bash GENERAL_AI_API_KEY=... GENERAL_AI_BASE_URL=... GENERAL_AI_MODEL=... GENERAL_AI_SKIP_LIVE=1 ``` -------------------------------- ### Set Compatibility Profile Source: https://github.com/nixaut-codelabs/general.ai/blob/main/README.md Configure the compatibility profile for OpenAI-compatible providers. Use 'classic_v2' for stricter gateways. ```typescript compatibility: { profile: "classic_v2", } ``` -------------------------------- ### Define a Simple Echo Tool Source: https://github.com/nixaut-codelabs/general.ai/blob/main/README.md Define a runtime tool using 'defineTool' for testing purposes. The input schema specifies the expected arguments for the tool's execution. ```typescript import { defineTool } from "@lightining/general.ai"; const echoTool = defineTool({ name: "echo", description: "Echo text back for runtime testing.", inputSchema: { type: "object", additionalProperties: false, properties: { text: { type: "string" }, }, required: ["text"], }, async execute(args) { return { echoed: args.text }; }, }); ``` -------------------------------- ### Native SDK: Create Chat Completion Source: https://github.com/nixaut-codelabs/general.ai/blob/main/README.md Uses the native General.AI interface to create a chat completion, mirroring OpenAI's chat completions API. This is useful for direct OpenAI SDK compatibility. ```typescript const completion = await generalAI.native.chat.completions.create({ model: "gpt-5.4-mini", messages: [{"role": "user", "content": "Say hello in one sentence." }], }); ``` -------------------------------- ### Run Cross-Runtime Smoke Tests Source: https://github.com/nixaut-codelabs/general.ai/blob/main/README.md Execute smoke tests across different runtimes using npm. This verifies basic functionality in various environments. ```bash npm run smoke ``` -------------------------------- ### Configure Context Management Source: https://github.com/nixaut-codelabs/general.ai/blob/main/README.md Enable context management and specify the mode and strategy for handling conversational context. Supports various strategies like summarization and dropping old messages. ```typescript context: { enabled: true, mode: "auto", strategy: "hybrid", trigger: { contextRatio: 0.9, }, } ``` -------------------------------- ### Configure Thinking Parameters Source: https://github.com/nixaut-codelabs/general.ai/blob/main/README.md Configure the thinking parameters for agent execution, including mode, strategy, and effort. Ensure 'enabled' is set to true to activate thinking features. ```typescript thinking: { enabled: true, mode: "hybrid", strategy: "checkpointed", checkpointFormat: "structured", effort: "high", } ``` -------------------------------- ### Generate with Preset and Intelligence Source: https://github.com/nixaut-codelabs/general.ai/blob/main/README.md Generate content using specific presets and intelligence levels for runtime posture and prompt guidance. Ensure the 'messages' array is correctly formatted. ```typescript const result = await generalAI.agent.generate({ endpoint: "chat_completions", model: "gpt-5.4-mini", preset: "agentic", intelligence: "high", messages: [{ role: "user", content: "Solve this carefully." }], }); ``` -------------------------------- ### Define a Root-Only Tool Source: https://github.com/nixaut-codelabs/general.ai/blob/main/README.md Define a tool that is only accessible from the root agent by setting 'subagents: false' in the access configuration. ```typescript const rootOnlyTool = defineTool({ name: "root_only", description: "Only callable from the root agent.", access: { subagents: false, }, async execute() { return { ok: true }; }, }); ``` -------------------------------- ### Configure Safety Settings Source: https://github.com/nixaut-codelabs/general.ai/blob/main/README.md Enable or disable safety features and set modes for input and output moderation within the agent protocol. ```typescript safety: { enabled: true, mode: "balanced", input: { enabled: true, }, output: { enabled: true, }, } ``` -------------------------------- ### Stream Agent Events Source: https://github.com/nixaut-codelabs/general.ai/blob/main/README.md Initiate an agent stream to receive parsed runtime events and cleaned writing deltas. Process events like 'writing_delta' for real-time output. ```typescript const stream = generalAI.agent.stream({ endpoint: "responses", model: "gpt-5.4-mini", messages: [{ role: "user", content: "Say hello." }], }); for await (const event of stream) { if (event.type === "writing_delta") { process.stdout.write(event.text); } } ``` -------------------------------- ### Define a Subagent Source: https://github.com/nixaut-codelabs/general.ai/blob/main/README.md Define a subagent with its own configuration, including model, instructions, and request parameters. Subagents can override many root-level configurations. ```typescript import { defineSubagent } from "@lightining/general.ai"; const mathHelper = defineSubagent({ name: "math_helper", description: "A precise arithmetic specialist.", instructions: "Solve delegated arithmetic carefully and return a concise answer.", model: "gpt-5.4-mini", request: { chat_completions: { temperature: 0.1, }, }, }); ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.