SDK AI Module
Use @hostfunc/sdk/ai to call workspace AI providers for text generation and embeddings.
SDK API Reference
askAi
await askAi(prompt: string | AiMessage[], options?: AiOptions): Promise<AiResponse>Request a non-streamed completion from the configured workspace AI model.
Returns
AiResponse with text, model, token usage, and finish reason.
streamAi
for await (const chunk of streamAi(prompt, options)) { ... }Async generator for streaming model output chunks. Current implementation emits delta + done chunks.
Returns
AsyncGenerator<{ type: 'delta' | 'done'; text?: string; done?: boolean }>
createEmbedding
await createEmbedding(text: string, options?: { model?: string }): Promise<EmbeddingResult>Generate an embedding vector suitable for vector upsert/query workflows.
Returns
EmbeddingResult containing numeric embedding array and usage metadata.
SDK Code Examples
Prompt + structured options
Use explicit model controls for deterministic summaries.
typescript
import { askAi } from "@hostfunc/sdk/ai";const result = await askAi( [ { role: "system", content: "You summarize execution logs." }, { role: "user", content: "Summarize this run in 3 bullets." }, ], { model: "gpt-4o", temperature: 0.2, maxTokens: 300 },);Best Practices
- Set low temperature for operational summaries and deterministic outputs.
- Generate embeddings once and cache them for repeated vector queries.
- Set workspace defaults first, then use per-function overrides only when a function needs isolation.