@tinyweb_dev/agent-framework-llm
v0.4.0
Published
LLM core: schemas, **OpenAI Chat protocol**, route architecture, tool runtime, and provider profiles.
Readme
@tinyweb-agent-framework/llm
LLM core: schemas, OpenAI Chat protocol, route architecture, tool runtime, and provider profiles.
Adapted from opencode's @opencode-ai/llm package, slimmed to OpenAI Chat only.
Surface
import {
LLM, // request/generate/stream/helpers facade
LLMClient, // Service + layer + prepare/stream/generate
Tool, // Tool.make typed-tool builder
Route, // Route.make / Route.model
OpenAI, // canonical OpenAI provider
OpenAICompatible, // deepseek/together/groq/cerebras/fireworks/deepinfra/openrouter/xai/ollama/lmstudio
Auth, AuthOptions, // bearer / header / config / fromModelApiKey
ProviderShared, // joinText, parseToolInput, validateWith, …
} from "@tinyweb-agent-framework/llm"Models
import { OpenAI, OpenAICompatible } from "@tinyweb-agent-framework/llm"
// OpenAI
const m1 = OpenAI.chat("gpt-4o-mini", { apiKey: process.env.OPENAI_API_KEY })
// Any OpenAI-compatible profile (DeepSeek, Together, Groq, Ollama, …)
const m2 = OpenAICompatible.deepseek("deepseek-chat", { apiKey: process.env.DEEPSEEK_API_KEY })
const m3 = OpenAICompatible.ollama("llama3", { apiKey: "ollama" })Tools
import { Tool, ToolFailure } from "@tinyweb-agent-framework/llm"
import { Effect, Schema } from "effect"
const search = Tool.make({
description: "Search the web",
parameters: Schema.Struct({ query: Schema.String, limit: Schema.optional(Schema.Number) }),
success: Schema.Struct({ results: Schema.Array(Schema.String) }),
execute: ({ query }) =>
Effect.tryPromise({
try: () => fetch(`https://example.com/api?q=${query}`).then((r) => r.json()),
catch: (e) => new ToolFailure({ message: String(e) }),
}),
})Architecture
Four-axis decomposition: Protocol (body & stream schema), Endpoint, Auth, Framing — composed via Route.make({ id, protocol, transport, defaults }). See src/route/ and src/protocols/openai-chat.ts.
License
MIT
