Provider-agnostic chat, tool-calling, structured output, and SSE delta parser across Gemini, Anthropic Messages, OpenAI, and Ollama.
Unified multi-provider Large Language Model client, wire protocol translator, Server-Sent Events (SSE) stream assembler, and deterministic multi-turn agent loop for Veko (Gemini, Anthropic, OpenAI, and Ollama).
veko pkg add ai_llm@1.0.0Import in any Veko module:
use [llm = ai_llm]Message), and JSON-Schema tool definitions (ToolDef) once, then switch between .gemini, .anthropic, .openai, and .ollama with a single enum symbol..gemini: Translates systemInstruction, contents (user / model), functionDeclarations, functionCall, and functionResponse on /v1beta/models/{model}:generateContent..anthropic: Translates top-level system, input_schema, assistant tool_use content blocks, and user tool_result blocks on /v1/messages..openai & .ollama: Translates system/user/assistant/tool messages, JSON-encoded function.arguments, and Bearer headers on /v1/chat/completions.llm/parse-sse-events and llm/assemble-sse-response parse raw data: ... SSE streams (ignoring keepalive comments and handling [DONE]) while stitching incremental arguments / partial_json fragments back into typed ToolCall structs.llm/run-tool-loop decouples tool execution from transport I/O by accepting any sender closure (llm/send-chat in production or deterministic mock functions in unit tests).Provider — .gemini, .anthropic, .openai, .ollamaToolCall — { id str, name str, arguments map }Message — { role str, content str, tool_calls block, tool_call_id str, name str }ToolDef — { name str, description str, parameters map }ChatRequest — { provider enum, model str, system str, messages block, tools block, temperature f64, max_tokens i64 }ChatResponse — { provider enum, model str, content str, tool_calls block, finish_reason str, usage map }SseDelta — { event str, text_delta str, tool_deltas block, finish_reason str, done bool }AgentTool — { def ToolDef, handler any }AgentLoopResult — { response ChatResponse, messages block, turns i64, tool_log block }llm/valid-provider? p -> boolllm/default-base-url provider -> strllm/user-msg content / llm/assistant-msg content / llm/assistant-tool-msg content tool_calls / llm/tool-result-msg tool_call_id name content -> Messagellm/tool-def name description parameters -> ToolDefllm/agent-tool def handler -> AgentToolllm/build-provider-request req [/base-url url] [/api-key key] -> mapllm/parse-provider-response provider raw -> ChatResponsellm/parse-sse-events provider raw_sse -> block[SseDelta]llm/assemble-sse-response provider events -> ChatResponsellm/send-chat req [/base-url url] [/api-key key] [/timeout dur] -> ChatResponsellm/run-tool-loop initial_req tools sender [/max-turns n] -> AgentLoopResultuse [llm = ai_llm]
lookup_def = llm/tool-def 'lookup_port' 'Return default TCP port for a protocol' {
type = 'object'
properties = { proto = { type = 'string' } }
required = ['proto']
}
tools = [
(llm/agent-tool lookup_def fn [args map] any [
p = str/lower (str/append '' (map/get args 'proto'))
if p == 'https' [ { port = 443 } ] else [ { port = 80 } ]
])
]
req = llm/ChatRequest {
provider = .gemini
model = 'gemini-2.5-flash'
system = 'Answer concisely using tools.'
messages = [(llm/user-msg 'What port does HTTPS use?')]
}
api_key = os/getenv/or 'GEMINI_API_KEY' [ '' ]
if api_key != '' [
res = llm/run-tool-loop req tools fn [r llm/ChatRequest] any [
llm/send-chat/api-key r api_key
]
println res.response.content
]https://veko-lang.org/pkg/ai_llm/1.0.0.vkpdcfa4ec863563f8a35c8fe3c45a673bc4893f830c024dc9ab27ddd59266090e918eee8be2343930696d3e21fb414f3fb0012e3a214968df7610dec818120de78ed25519:27406074d8681da1d4e6420f5d887cac15c313334c249ac047ba9d4e2df72b70{"name":"ai_llm","version":"1.0.0","tier":3.0,"tier_label":"Tier 3: AI, Vector RAG & DataFrames","category":"Unified Multi-Provider LLM SDK","description":"Provider-agnostic chat, tool-calling, structured output, and SSE delta parser across Gemini, Anthropic Messages, OpenAI, and Ollama.","modules":["ai_llm"],"homepage":"https://veko-lang.org/packages/ai_llm"}| Bundle Entry Path | Size | Leaf SHA-256 Digest |
|---|---|---|
| README.md | 3 KB | bc0a199461c91fb871af73604ff005a7ce68ab8643458feec62193a86f2cfa44 |
| examples/demo.vk | 9 KB | ec8d40a057543185d9f716519259896d07a7793849647fe3e98ea0d07f8ca719 |
| mod.vk | 25 KB | e599616ad35ab509dec8f5c347f68176ffb2afef55909b7dcdb8c18aa2907dc4 |