Legacy binding examples
Legacy binding examples
Section titled “Legacy binding examples”These examples preserve additional target-specific usage patterns alongside the fixture-generated reference matrix.
csharp usage local llm.md
Section titled “csharp usage local llm.md”using LiterLlm;
using var client = LiterLlmLib.CreateClient( apiKey: "", baseUrl: "http://localhost:11434/v1", timeoutSecs: null, maxRetries: null, modelHint: "ollama/qwen2:0.5b");
var response = await client.ChatAsync(new ChatCompletionRequest{ Model = "ollama/qwen2:0.5b", Messages = new[] { new Message { Role = MessageRoleEnum.User, Content = "Hello!" } }});
Console.WriteLine(response.Choices[0].Message.Content);curl server audio speech.md
Section titled “curl server audio speech.md”curl http://localhost:4000/v1/audio/speech \ -H "Authorization: Bearer $LITER_LLM_MASTER_KEY" \ -H "Content-Type: application/json" \ --output speech.mp3 \ -d '{ "model": "tts-1", "voice": "alloy", "input": "Backoff with jitter prevents synchronised retries." }'curl server batches create.md
Section titled “curl server batches create.md”curl http://localhost:4000/v1/batches \ -H "Authorization: Bearer $LITER_LLM_MASTER_KEY" \ -H "Content-Type: application/json" \ -d '{ "input_file_id": "file_abc123", "endpoint": "/v1/chat/completions", "completion_window": "24h" }'curl server embeddings.md
Section titled “curl server embeddings.md”curl http://localhost:4000/v1/embeddings \ -H "Authorization: Bearer $LITER_LLM_MASTER_KEY" \ -H "Content-Type: application/json" \ -d '{ "model": "text-embedding-3-small", "input": ["the quick brown fox", "the lazy dog"] }'curl server files upload.md
Section titled “curl server files upload.md”curl http://localhost:4000/v1/files \ -H "Authorization: Bearer $LITER_LLM_MASTER_KEY" \ -F purpose=batch \ -F file=@requests.jsonlcurl server health.md
Section titled “curl server health.md”# Liveness probe: returns 200 as long as the process is running.curl -fsS http://localhost:4000/health/liveness
# Readiness probe: returns 200 once service pool and file store are initialised.curl -fsS http://localhost:4000/health/readiness
# Full status: includes configured model list.curl -fsS http://localhost:4000/healthcurl server images.md
Section titled “curl server images.md”curl http://localhost:4000/v1/images/generations \ -H "Authorization: Bearer $LITER_LLM_MASTER_KEY" \ -H "Content-Type: application/json" \ -d '{ "model": "dall-e-3", "prompt": "A cross-section diagram of a Rust async runtime", "size": "1024x1024", "n": 1 }'curl server responses create.md
Section titled “curl server responses create.md”curl http://localhost:4000/v1/responses \ -H "Authorization: Bearer $LITER_LLM_MASTER_KEY" \ -H "Content-Type: application/json" \ -d '{ "model": "gpt-4o", "input": "Explain eventual consistency to a backend engineer." }'dart getting started basic chat.md
Section titled “dart getting started basic chat.md”import 'package:liter_llm/liter_llm.dart';import 'dart:io';
void main() async { final client = await LiterLlmBridge.createClient( apiKey: Platform.environment['OPENAI_API_KEY'] ?? '', ); final request = ChatCompletionRequest( model: 'openai/gpt-4o', messages: [Message.user(UserMessage(content: UserContent.of('Hello!')))], ); final response = await client.chat(request); print(response.choices[0].message.content);}dart getting started streaming.md
Section titled “dart getting started streaming.md”import 'package:liter_llm/liter_llm.dart';
void main() async { // Example snippet}dart getting started tool calling.md
Section titled “dart getting started tool calling.md”import 'package:liter_llm/liter_llm.dart';
void main() async { // Example snippet}dart guides chat multiturn.md
Section titled “dart guides chat multiturn.md”import 'package:liter_llm/liter_llm.dart';
void main() async { // Example snippet}dart guides configuration.md
Section titled “dart guides configuration.md”import 'package:liter_llm/liter_llm.dart';
void main() async { // Example snippet}dart guides embeddings.md
Section titled “dart guides embeddings.md”import 'package:liter_llm/liter_llm.dart';
void main() async { // Example snippet}dart guides error handling.md
Section titled “dart guides error handling.md”import 'package:liter_llm/liter_llm.dart';
void main() async { // Example snippet}dart guides stream collect.md
Section titled “dart guides stream collect.md”import 'package:liter_llm/liter_llm.dart';
void main() async { // Example snippet}dart usage create batch.md
Section titled “dart usage create batch.md”import 'package:liter_llm/liter_llm.dart';
void main() async { // Example snippet}dart usage create file.md
Section titled “dart usage create file.md”import 'package:liter_llm/liter_llm.dart';
void main() async { // Example snippet}dart usage create response.md
Section titled “dart usage create response.md”import 'package:liter_llm/liter_llm.dart';
void main() async { // Example snippet}dart usage image generate.md
Section titled “dart usage image generate.md”import 'package:liter_llm/liter_llm.dart';
void main() async { // Example snippet}dart usage local llm.md
Section titled “dart usage local llm.md”import 'package:liter_llm/liter_llm.dart';
void main() async { final client = await LiterLlmBridge.createClient( apiKey: '', baseUrl: 'http://localhost:11434/v1', ); final request = ChatCompletionRequest( model: 'ollama/qwen2:0.5b', messages: [Message.user(UserMessage(content: UserContent.of('Hello!')))], ); final response = await client.chat(request); print(response.choices[0].message.content);}dart usage moderate.md
Section titled “dart usage moderate.md”import 'package:liter_llm/liter_llm.dart';
void main() async { // Example snippet}dart usage ocr.md
Section titled “dart usage ocr.md”import 'package:liter_llm/liter_llm.dart';
void main() async { // Example snippet}dart usage rerank.md
Section titled “dart usage rerank.md”import 'package:liter_llm/liter_llm.dart';
void main() async { // Example snippet}dart usage search.md
Section titled “dart usage search.md”import 'package:liter_llm/liter_llm.dart';
void main() async { // Example snippet}dart usage speech.md
Section titled “dart usage speech.md”import 'package:liter_llm/liter_llm.dart';
void main() async { // Example snippet}dart usage transcribe.md
Section titled “dart usage transcribe.md”import 'package:liter_llm/liter_llm.dart';
void main() async { // Example snippet}elixir usage local llm.md
Section titled “elixir usage local llm.md”{:ok, client} = LiterLlm.create_client("")
request = Jason.encode!(%{ "model" => "ollama/qwen2:0.5b", "messages" => [ %{ "role" => "user", "content" => "Hello!" } ] })
{:ok, response} = LiterLlm.defaultclient_chat(client, request, "http://localhost:11434/v1")IO.puts(Enum.at(response.choices, 0).message.content)go usage multimodal.md
Section titled “go usage multimodal.md”package main
import ( "context" "encoding/json" "fmt" "log" "os"
ll "github.com/xberg-io/liter-llm/packages/go")
func main() { ctx := context.Background()
// Create client with OpenAI API key client, err := ll.CreateClient(os.Getenv("OPENAI_API_KEY"), "", 0, 0, "") if err != nil { log.Fatalf("failed to create client: %v", err) }
// Build a multimodal user message with text and image imageURL := ll.ImageURL{ URL: "https://upload.wikimedia.org/wikipedia/commons/thumb/d/dd/Gfp-wisconsin-madison-the-nature-boardwalk.jpg/2560px-Gfp-wisconsin-madison-the-nature-boardwalk.jpg", Detail: ll.Ptr(ll.ImageDetailLow), }
userMessage := ll.Message{ Role: "user", User: &ll.UserMessage{ Content: ll.UserContent(json.RawMessage(`[ {"type":"text","text":"Describe this image in one sentence."}, {"type":"image_url","image_url":{"url":"https://upload.wikimedia.org/wikipedia/commons/thumb/d/dd/Gfp-wisconsin-madison-the-nature-boardwalk.jpg/2560px-Gfp-wisconsin-madison-the-nature-boardwalk.jpg","detail":"Low"}} ]`)), Name: nil, }, }
// Create chat request with JSON schema response format schema := ll.JSONSchemaFormat{ Name: "ImageDescription", Description: ll.Ptr("A single-sentence description of an image"), Schema: json.RawMessage(`{ "type": "object", "properties": { "description": {"type": "string"} }, "required": ["description"] }`), Strict: ll.Ptr(true), }
request := ll.ChatCompletionRequest{ Model: "openai/gpt-4o", Messages: []ll.Message{userMessage}, ResponseFormat: ll.ResponseFormatJSONSchema{ JSONSchema: schema, }, Modalities: []ll.Modality{ll.ModalityText}, }
// Send request and get response response, err := client.Chat(ctx, request) if err != nil { log.Fatalf("failed to call chat: %v", err) }
// Extract response text if len(response.Choices) > 0 { choice := response.Choices[0] if choice.Message.Content != nil { fmt.Printf("Response: %s\n", string(*choice.Message.Content)) } }
// Example: Request multimodal output (image + text) requestWithImage := ll.ChatCompletionRequest{ Model: "openai/gpt-4o", Messages: []ll.Message{userMessage}, Modalities: []ll.Modality{ll.ModalityText, ll.ModalityImage}, }
responseWithImage, err := client.Chat(ctx, requestWithImage) if err != nil { log.Fatalf("failed to call chat with image output: %v", err) }
// Extract output images using helper method if len(responseWithImage.Choices) > 0 { choice := responseWithImage.Choices[0] outputImages, err := choice.Message.OutputImages() if err == nil { for i, img := range outputImages { fmt.Printf("Output image %d: %s\n", i, img.URL) } } }
// Example: Stream multimodal response stream, err := client.ChatStream(ctx, requestWithImage) if err != nil { log.Fatalf("failed to start stream: %v", err) } defer stream.Close()
for { chunk, err := stream.Next() if err != nil { log.Fatalf("stream error: %v", err) } if chunk == nil { break } if len(chunk.Choices) > 0 && chunk.Choices[0].Delta.Content != nil { fmt.Printf("Streamed: %s", string(*chunk.Choices[0].Delta.Content)) } }}java usage local llm.md
Section titled “java usage local llm.md”import io.xberg.literllm.*;import java.util.List;
public class LocalLlm { public static void main(String[] args) throws Exception { // No API key needed for local providers try (var client = LiterLlm.createClient("", "http://localhost:11434/v1")) { var request = ChatCompletionRequest.builder() .withModel("ollama/qwen2:0.5b") .withMessages(List.of( new Message.User(new UserMessage(UserContent.of("Hello!"), null)) )) .build(); var response = client.chat(request); System.out.println(response.choices().getFirst().message().content()); } }}kotlin getting started basic chat.md
Section titled “kotlin getting started basic chat.md”import io.xberg.literllm.android.*import kotlinx.coroutines.runBlocking
fun main() = runBlocking { val client = LiterLlm.createClient(System.getenv("OPENAI_API_KEY") ?: "") val request = ChatCompletionRequest( model = "openai/gpt-4o", messages = listOf(Message.User(UserMessage(content = UserContent.of("Hello!")))) ) val response = client.chat(request) println(response.choices[0].message.content)}kotlin getting started streaming.md
Section titled “kotlin getting started streaming.md”import io.xberg.literllm.android.*
suspend fun main() { // Example snippet}kotlin getting started tool calling.md
Section titled “kotlin getting started tool calling.md”import io.xberg.literllm.android.*
suspend fun main() { // Example snippet}kotlin guides chat multiturn.md
Section titled “kotlin guides chat multiturn.md”import io.xberg.literllm.android.*
suspend fun main() { // Example snippet}kotlin guides configuration.md
Section titled “kotlin guides configuration.md”import io.xberg.literllm.android.*
suspend fun main() { // Example snippet}kotlin guides embeddings.md
Section titled “kotlin guides embeddings.md”import io.xberg.literllm.android.*
suspend fun main() { // Example snippet}kotlin guides error handling.md
Section titled “kotlin guides error handling.md”import io.xberg.literllm.android.*
suspend fun main() { // Example snippet}kotlin guides stream collect.md
Section titled “kotlin guides stream collect.md”import io.xberg.literllm.android.*
suspend fun main() { // Example snippet}kotlin usage create batch.md
Section titled “kotlin usage create batch.md”import io.xberg.literllm.android.*
suspend fun main() { // Example snippet}kotlin usage create file.md
Section titled “kotlin usage create file.md”import io.xberg.literllm.android.*
suspend fun main() { // Example snippet}kotlin usage create response.md
Section titled “kotlin usage create response.md”import io.xberg.literllm.android.*
suspend fun main() { // Example snippet}kotlin usage image generate.md
Section titled “kotlin usage image generate.md”import io.xberg.literllm.android.*
suspend fun main() { // Example snippet}kotlin usage local llm.md
Section titled “kotlin usage local llm.md”import io.xberg.literllm.android.*import kotlinx.coroutines.runBlocking
fun main() = runBlocking { val client = LiterLlm.createClient(apiKey = "", baseUrl = "http://localhost:11434/v1") val request = ChatCompletionRequest( model = "ollama/qwen2:0.5b", messages = listOf(Message.User(UserMessage(content = UserContent.of("Hello!")))) ) val response = client.chat(request) println(response.choices[0].message.content)}kotlin usage moderate.md
Section titled “kotlin usage moderate.md”import io.xberg.literllm.android.*
suspend fun main() { // Example snippet}kotlin usage ocr.md
Section titled “kotlin usage ocr.md”import io.xberg.literllm.android.*
suspend fun main() { // Example snippet}kotlin usage rerank.md
Section titled “kotlin usage rerank.md”import io.xberg.literllm.android.*
suspend fun main() { // Example snippet}kotlin usage search.md
Section titled “kotlin usage search.md”import io.xberg.literllm.android.*
suspend fun main() { // Example snippet}kotlin usage speech.md
Section titled “kotlin usage speech.md”import io.xberg.literllm.android.*
suspend fun main() { // Example snippet}kotlin usage transcribe.md
Section titled “kotlin usage transcribe.md”import io.xberg.literllm.android.*
suspend fun main() { // Example snippet}php usage local llm.md
Section titled “php usage local llm.md”<?php
declare(strict_types=1);
use Liter\Llm\LiterLlm;use Liter\Llm\ChatCompletionRequest;use Liter\Llm\Message;use Liter\Llm\UserMessage;use Liter\Llm\UserContent;
// No API key needed for local providers$client = LiterLlm::createClient( apiKey: "", baseUrl: "http://localhost:11434/v1");
$request = new ChatCompletionRequest( model: "ollama/qwen2:0.5b", messages: [ new Message( role: "user", content: "Hello!", name: null ) ]);
$response = $client->chat($request);echo $response->choices[0]->message->content . PHP_EOL;php usage multimodal.md
Section titled “php usage multimodal.md”<?php
declare(strict_types=1);
use Liter\Llm\LiterLlm;use Liter\Llm\Message;use Liter\Llm\ContentPart;use Liter\Llm\Image;use Liter\Llm\ImageDetail;use Liter\Llm\ChatCompletionRequest;
$client = LiterLlm::createClient(getenv('OPENAI_API_KEY') ?: '');
// Vision: Send an image and ask the model to analyze it$response = $client->chat( ChatCompletionRequest::from_json(json_encode([ 'model' => 'gpt-4o', 'messages' => [ Message::userWithParts([ ContentPart::text('What is in this image?'), ContentPart::imageUrl( 'https://upload.wikimedia.org/wikipedia/commons/thumb/e/ea/Van_Gogh_-_Starry_Night_-_Google_Art_Project.jpg/1280px-Van_Gogh_-_Starry_Night_-_Google_Art_Project.jpg', ImageDetail::High ), ])->toArray(), ], ])));
echo "Analysis: " . $response->choices[0]->message->text() . PHP_EOL;
// Multimodal with base64 image$imageBytes = file_get_contents('path/to/image.png');$response = $client->chat( ChatCompletionRequest::from_json(json_encode([ 'model' => 'gpt-4o', 'messages' => [ Message::userWithParts([ ContentPart::text('Describe what you see'), ContentPart::imagePng($imageBytes), ])->toArray(), ], ])));
echo $response->choices[0]->message->text() . PHP_EOL;
// Audio input (if supported by model)$audioBytes = file_get_contents('path/to/audio.wav');$audioBase64 = base64_encode($audioBytes);
$response = $client->chat( ChatCompletionRequest::from_json(json_encode([ 'model' => 'gpt-4o-audio-preview', 'messages' => [ Message::userWithParts([ ContentPart::text('Transcribe this audio'), ContentPart::audio($audioBase64, 'wav'), ])->toArray(), ], ])));
echo "Transcription: " . $response->choices[0]->message->text() . PHP_EOL;
// Structured output with JSON schema$response = $client->chat( ChatCompletionRequest::from_json(json_encode([ 'model' => 'gpt-4o', 'messages' => [ Message::user('Extract the person name and age from: "John Doe is 30 years old"'), ], 'response_format' => [ 'type' => 'json_schema', 'json_schema' => [ 'name' => 'person', 'schema' => json_encode([ 'type' => 'object', 'properties' => [ 'name' => ['type' => 'string'], 'age' => ['type' => 'integer'], ], 'required' => ['name', 'age'], ]), 'strict' => true, ], ], ])));
$structured = json_decode($response->choices[0]->message->text(), true);echo "Extracted: {$structured['name']}, age {$structured['age']}" . PHP_EOL;python multimodal.md
Section titled “python multimodal.md”Multimodal I/O in Python
Process images, documents, and audio alongside text using liter-llm’s multimodal message API.
Text with Images
Combine text and image references in a single user message:
import asyncioimport liter_llmfrom liter_llm import ChatCompletionRequest, UserMessage, ImageUrl
async def describe_image(): client = liter_llm.create_client(api_key="your-api-key")
req = ChatCompletionRequest( model="gpt-4o-mini", # Vision-capable model messages=[ UserMessage(content=[ "What's the main subject in this image?", ImageUrl(url="https://example.com/photo.jpg", detail="high") ]) ] )
resp = await liter_llm.chat(client, req) print(resp.choices[0].message.text())
asyncio.run(describe_image())Image Data URLs
Embed image bytes inline using base64 data URLs:
from pathlib import Pathimport liter_llmfrom liter_llm import ChatCompletionRequest, UserMessage, ImageUrl
async def analyze_local_image(): client = liter_llm.create_client(api_key="your-api-key")
# Read image file image_bytes = Path("diagram.png").read_bytes()
# Encode as data URL data_url = liter_llm.encode_data_url(image_bytes, mime="image/png")
# Use in message req = ChatCompletionRequest( model="gpt-4o-mini", messages=[ UserMessage(content=[ "Analyze this diagram:", ImageUrl(url=data_url, detail="high") ]) ] )
resp = await liter_llm.chat(client, req) print(resp.choices[0].message.text())
asyncio.run(analyze_local_image())Structured Output (JSON Schema)
Enforce JSON schema conformance for model outputs:
import jsonimport asyncioimport liter_llmfrom liter_llm import ( ChatCompletionRequest, UserMessage, JsonSchemaFormat)
async def extract_structured_data(): client = liter_llm.create_client(api_key="your-api-key")
# Define output schema schema = { "type": "object", "properties": { "person_name": {"type": "string"}, "company": {"type": "string"}, "role": {"type": "string"} }, "required": ["person_name", "company", "role"] }
req = ChatCompletionRequest( model="gpt-4o-mini", messages=[ UserMessage(content="Extract from: John Doe works at TechCorp as Senior Engineer") ], response_format=JsonSchemaFormat( name="person_info", schema=json.dumps(schema), strict=True, description="Extract person, company, and role" ) )
resp = await liter_llm.chat(client, req) result_text = resp.choices[0].message.text()
# Parse structured output extracted = json.loads(result_text) print(f"Name: {extracted['person_name']}") print(f"Company: {extracted['company']}") print(f"Role: {extracted['role']}")
asyncio.run(extract_structured_data())Multimodal Output
Request multimodal responses (text, images, audio) from capable models:
import asyncioimport liter_llmfrom liter_llm import ChatCompletionRequest, UserMessage, Modality
async def multimodal_response(): client = liter_llm.create_client(api_key="your-api-key")
req = ChatCompletionRequest( model="gpt-4o-mini", messages=[ UserMessage(content="Write a short poem and generate accompanying audio") ], modalities=[Modality.TEXT, Modality.AUDIO] # Request text + audio )
resp = await liter_llm.chat(client, req)
# Extract output msg = resp.choices[0].message text_output = msg.text() audio_outputs = msg.output_audio()
print(f"Text: {text_output}") print(f"Audio parts: {len(audio_outputs)}")
asyncio.run(multimodal_response())Documents and PDFs
Send documents to vision-capable models:
import asyncioimport liter_llmfrom liter_llm import ( ChatCompletionRequest, UserMessage, DocumentContent)
async def analyze_document(): client = liter_llm.create_client(api_key="your-api-key")
# Read PDF and encode pdf_bytes = open("report.pdf", "rb").read() import base64 b64_pdf = base64.b64encode(pdf_bytes).decode()
req = ChatCompletionRequest( model="gpt-4o-mini", messages=[ UserMessage(content=[ "Summarize the key findings:", DocumentContent(data=b64_pdf, media_type="application/pdf") ]) ] )
resp = await liter_llm.chat(client, req) print(resp.choices[0].message.text())
asyncio.run(analyze_document())Audio Input
Transcribe or process audio with speech-capable models:
import asyncioimport liter_llmfrom liter_llm import ( ChatCompletionRequest, UserMessage, AudioContent)
async def process_audio(): client = liter_llm.create_client(api_key="your-api-key")
# Read audio and encode audio_bytes = open("recording.mp3", "rb").read() import base64 b64_audio = base64.b64encode(audio_bytes).decode()
req = ChatCompletionRequest( model="gpt-4o-mini", messages=[ UserMessage(content=[ "Transcribe and summarize:", AudioContent(data=b64_audio, format="mp3") ]) ] )
resp = await liter_llm.chat(client, req) print(resp.choices[0].message.text())
asyncio.run(process_audio())Decoding Data URLs
Extract bytes from data URLs:
import liter_llm
# Encodeencoded = liter_llm.encode_data_url(b"image data", mime="image/jpeg")
# Decodedecoded = liter_llm.decode_data_url(encoded)if decoded: print(f"MIME: {decoded.mime}") print(f"Size: {len(decoded.data)} bytes")ruby usage local llm.md
Section titled “ruby usage local llm.md”# frozen_string_literal: true
require 'liter_llm'
# No API key needed for local providersclient = LiterLlm.create_client("", "http://localhost:11434/v1")
request = LiterLlm::ChatCompletionRequest.new( model: "ollama/qwen2:0.5b", messages: [ LiterLlm::Message::User.new( LiterLlm::UserMessage.new( content: LiterLlm::UserContent::Text.new("Hello!"), name: nil ) ) ])
response = client.chat_async(request)puts response.choices[0].message.contentswift getting started basic chat.md
Section titled “swift getting started basic chat.md”import Foundationimport LiterLlm
let client = try await LiterLlm.createClient(apiKey: ProcessInfo.processInfo.environment["OPENAI_API_KEY"] ?? "")let request = ChatCompletionRequest( model: "openai/gpt-4o", messages: [.user(.init(content: .of("Hello!")))], temperature: nil, topP: nil, maxTokens: nil, toolChoice: nil, tools: nil, responseFormat: nil)let response = try await client.chat(request)print(response.choices[0].message.content ?? "")swift getting started streaming.md
Section titled “swift getting started streaming.md”import Foundationimport LiterLlm
// Example snippetswift getting started tool calling.md
Section titled “swift getting started tool calling.md”import Foundationimport LiterLlm
// Example snippetswift guides chat multiturn.md
Section titled “swift guides chat multiturn.md”import Foundationimport LiterLlm
// Example snippetswift guides configuration.md
Section titled “swift guides configuration.md”import Foundationimport LiterLlm
// Example snippetswift guides embeddings.md
Section titled “swift guides embeddings.md”import Foundationimport LiterLlm
// Example snippetswift guides error handling.md
Section titled “swift guides error handling.md”import Foundationimport LiterLlm
// Example snippetswift guides stream collect.md
Section titled “swift guides stream collect.md”import Foundationimport LiterLlm
// Example snippetswift usage create batch.md
Section titled “swift usage create batch.md”import Foundationimport LiterLlm
// Example snippetswift usage create file.md
Section titled “swift usage create file.md”import Foundationimport LiterLlm
// Example snippetswift usage create response.md
Section titled “swift usage create response.md”import Foundationimport LiterLlm
// Example snippetswift usage image generate.md
Section titled “swift usage image generate.md”import Foundationimport LiterLlm
// Example snippetswift usage local llm.md
Section titled “swift usage local llm.md”import Foundationimport LiterLlm
let client = try await LiterLlm.createClient( apiKey: "", baseUrl: "http://localhost:11434/v1")let request = ChatCompletionRequest( model: "ollama/qwen2:0.5b", messages: [.user(.init(content: .of("Hello!")))], temperature: nil, topP: nil, maxTokens: nil, toolChoice: nil, tools: nil, responseFormat: nil)let response = try await client.chat(request)print(response.choices[0].message.content ?? "")swift usage moderate.md
Section titled “swift usage moderate.md”import Foundationimport LiterLlm
// Example snippetswift usage ocr.md
Section titled “swift usage ocr.md”import Foundationimport LiterLlm
// Example snippetswift usage rerank.md
Section titled “swift usage rerank.md”import Foundationimport LiterLlm
// Example snippetswift usage search.md
Section titled “swift usage search.md”import Foundationimport LiterLlm
// Example snippetswift usage speech.md
Section titled “swift usage speech.md”import Foundationimport LiterLlm
// Example snippetswift usage transcribe.md
Section titled “swift usage transcribe.md”import Foundationimport LiterLlm
// Example snippetwasm usage local llm.md
Section titled “wasm usage local llm.md”import init, { createClient, WasmChatCompletionRequest, WasmMessage, WasmUserContent,} from "@xberg-io/liter-llm-wasm";
await init();
// No API key needed for local providersconst client = createClient("", "http://localhost:11434/v1");
const request = WasmChatCompletionRequest.default();request.model = "ollama/qwen2:0.5b";
const message = WasmMessage.User(new WasmUserContent.Text("Hello!"));request.messages = [message];
const response = await client.chat(request);console.log(response.choices[0].message.content);zig getting started basic chat.md
Section titled “zig getting started basic chat.md”const liter_llm = @import("liter_llm");const std = @import("std");
pub fn main() !void { const api_key = "sk-..."; var client = try liter_llm.create_client(api_key, null, null, null, null); defer client.close(); const req = "{\"model\":\"openai/gpt-4o\",\"messages\":[{\"role\":\"user\",\"content\":\"Hello!\"}]}"; const response = try client.chat(req); defer liter_llm._free_string(response); std.debug.print("Response: {s}\n", .{response});}zig getting started streaming.md
Section titled “zig getting started streaming.md”// Placeholderzig getting started tool calling.md
Section titled “zig getting started tool calling.md”// Placeholderzig guides chat multiturn.md
Section titled “zig guides chat multiturn.md”// Placeholderzig guides configuration.md
Section titled “zig guides configuration.md”// Placeholderzig guides embeddings.md
Section titled “zig guides embeddings.md”// Placeholderzig guides error handling.md
Section titled “zig guides error handling.md”// Placeholderzig guides stream collect.md
Section titled “zig guides stream collect.md”// Placeholderzig usage create batch.md
Section titled “zig usage create batch.md”// Placeholderzig usage create file.md
Section titled “zig usage create file.md”// Placeholderzig usage create response.md
Section titled “zig usage create response.md”// Placeholderzig usage image generate.md
Section titled “zig usage image generate.md”// Placeholderzig usage local llm.md
Section titled “zig usage local llm.md”const liter_llm = @import("liter_llm");const std = @import("std");
pub fn main() !void { const base_url = "http://localhost:11434/v1"; var client = try liter_llm.create_client("", base_url, null, null, null); defer client.close(); const req = "{\"model\":\"ollama/qwen2:0.5b\",\"messages\":[{\"role\":\"user\",\"content\":\"Hello!\"}]}"; const response = try client.chat(req); defer liter_llm._free_string(response); std.debug.print("Response: {s}\n", .{response});}zig usage moderate.md
Section titled “zig usage moderate.md”// Placeholderzig usage ocr.md
Section titled “zig usage ocr.md”// Placeholderzig usage rerank.md
Section titled “zig usage rerank.md”// Placeholderzig usage search.md
Section titled “zig usage search.md”// Placeholderzig usage speech.md
Section titled “zig usage speech.md”// Placeholderzig usage transcribe.md
Section titled “zig usage transcribe.md”// Placeholder