galileo-typescript-sdk
Compare original and translation side by side
🇺🇸
Original
English🇨🇳
Translation
ChineseGalileo TypeScript SDK
Galileo TypeScript SDK
The Galileo TypeScript SDK () provides evaluation and observability workflows for GenAI applications in Node.js and TypeScript. It supports logging LLM calls, retriever operations, tool invocations, and multi-step workflows with built-in scoring.
@rungalileo/galileoAdditional references:
- Framework Integrations — Vercel AI SDK, Mastra, LangGraph (JS), and more
- Guardrail Metrics Reference — Scoring metrics available for evaluation workflows
- Advanced Evaluation Patterns — Complex workflow evaluation and experiment design
Galileo TypeScript SDK()为Node.js和TypeScript环境中的GenAI应用提供评估和可观测性工作流能力。它支持记录LLM调用、检索器操作、工具调用以及内置评分的多步骤工作流。
@rungalileo/galileo额外参考:
- 框架集成 — Vercel AI SDK、Mastra、LangGraph (JS) 等
- 防护规则指标参考 — 评估工作流可用的评分指标
- 高级评估模式 — 复杂工作流评估和实验设计
Installation
安装
bash
npm install @rungalileo/galileoOr with yarn/pnpm:
bash
yarn add @rungalileo/galileo
pnpm add @rungalileo/galileobash
npm install @rungalileo/galileo或者使用yarn/pnpm安装:
bash
yarn add @rungalileo/galileo
pnpm add @rungalileo/galileoQuick Start
快速开始
typescript
import { GalileoObserveWorkflow } from "@rungalileo/galileo";
const workflow = new GalileoObserveWorkflow("my-observe-project");
await workflow.init();
workflow.addWorkflow({ input: "What is quantum computing?" });
workflow.addLlmStep({
input: "What is quantum computing?",
output: "Quantum computing uses quantum bits...",
durationNs: 1500000000,
model: "gpt-4o",
});
workflow.concludeWorkflow("Quantum computing uses quantum bits...");
await workflow.uploadWorkflows();typescript
import { GalileoObserveWorkflow } from "@rungalileo/galileo";
const workflow = new GalileoObserveWorkflow("my-observe-project");
await workflow.init();
workflow.addWorkflow({ input: "What is quantum computing?" });
workflow.addLlmStep({
input: "What is quantum computing?",
output: "Quantum computing uses quantum bits...",
durationNs: 1500000000,
model: "gpt-4o",
});
workflow.concludeWorkflow("Quantum computing uses quantum bits...");
await workflow.uploadWorkflows();Authentication
认证
Set the following environment variables in your file or shell:
.envbash
GALILEO_API_KEY="your-api-key" # Required — from Galileo console
GALILEO_CONSOLE_URL="https://app.galileo.ai" # Console URL (or self-hosted)Alternative authentication via username/password:
bash
GALILEO_USERNAME="your-username"
GALILEO_PASSWORD="your-password"在你的文件或shell中设置以下环境变量:
.envbash
GALILEO_API_KEY="your-api-key" # 必填 — 从Galileo控制台获取
GALILEO_CONSOLE_URL="https://app.galileo.ai" # 控制台地址(或自托管地址)另一种用户名/密码认证方式:
bash
GALILEO_USERNAME="your-username"
GALILEO_PASSWORD="your-password"Observability with GalileoObserveWorkflow
使用GalileoObserveWorkflow实现可观测性
Basic Workflow Logging
基础工作流日志记录
typescript
import { GalileoObserveWorkflow } from "@rungalileo/galileo";
const workflow = new GalileoObserveWorkflow("my-project");
await workflow.init();
workflow.addWorkflow({ input: "User question here" });
workflow.addLlmStep({
input: "User question here",
output: "LLM response text",
durationNs: 1200000000,
model: "gpt-4o",
});
workflow.concludeWorkflow("LLM response text");
await workflow.uploadWorkflows();typescript
import { GalileoObserveWorkflow } from "@rungalileo/galileo";
const workflow = new GalileoObserveWorkflow("my-project");
await workflow.init();
workflow.addWorkflow({ input: "User question here" });
workflow.addLlmStep({
input: "User question here",
output: "LLM response text",
durationNs: 1200000000,
model: "gpt-4o",
});
workflow.concludeWorkflow("LLM response text");
await workflow.uploadWorkflows();Logging Retriever Steps
记录检索器步骤
typescript
workflow.addWorkflow({ input: "What are the benefits of RAG?" });
workflow.addRetrieverStep({
input: "What are the benefits of RAG?",
output: ["Document 1 content", "Document 2 content"],
});
workflow.addLlmStep({
input: "Based on the context, explain RAG benefits.",
output: "RAG provides improved accuracy by...",
durationNs: 2000000000,
model: "gpt-4o",
});
workflow.concludeWorkflow("RAG provides improved accuracy by...");typescript
workflow.addWorkflow({ input: "What are the benefits of RAG?" });
workflow.addRetrieverStep({
input: "What are the benefits of RAG?",
output: ["Document 1 content", "Document 2 content"],
});
workflow.addLlmStep({
input: "Based on the context, explain RAG benefits.",
output: "RAG provides improved accuracy by...",
durationNs: 2000000000,
model: "gpt-4o",
});
workflow.concludeWorkflow("RAG provides improved accuracy by...");Logging Tool Steps
记录工具步骤
typescript
workflow.addWorkflow({ input: "Calculate 15 * 42" });
workflow.addToolStep({
input: "15 * 42",
output: "630",
durationNs: 50000000,
});
workflow.addLlmStep({
input: "The calculator returned 630. Respond to the user.",
output: "15 multiplied by 42 equals 630.",
durationNs: 800000000,
model: "gpt-4o",
});
workflow.concludeWorkflow("15 multiplied by 42 equals 630.");typescript
workflow.addWorkflow({ input: "Calculate 15 * 42" });
workflow.addToolStep({
input: "15 * 42",
output: "630",
durationNs: 50000000,
});
workflow.addLlmStep({
input: "The calculator returned 630. Respond to the user.",
output: "15 multiplied by 42 equals 630.",
durationNs: 800000000,
model: "gpt-4o",
});
workflow.concludeWorkflow("15 multiplied by 42 equals 630.");Evaluation with GalileoEvaluateWorkflow
使用GalileoEvaluateWorkflow实现评估
Running an Evaluation
运行评估
typescript
import { GalileoEvaluateWorkflow } from "@rungalileo/galileo";
const evaluateWorkflow = new GalileoEvaluateWorkflow("eval-project");
await evaluateWorkflow.init();
const testCases = [
{ input: "What is ML?", expected: "Machine learning is..." },
{ input: "Explain AI", expected: "Artificial intelligence is..." },
];
for (const testCase of testCases) {
evaluateWorkflow.addWorkflow({ input: testCase.input });
const response = await callYourLLM(testCase.input);
evaluateWorkflow.addLlmStep({
input: testCase.input,
output: response,
durationNs: 1000000000,
model: "gpt-4o",
});
evaluateWorkflow.concludeWorkflow(response);
}
await evaluateWorkflow.uploadWorkflows({
context_adherence: true,
completeness: true,
toxicity: true,
});typescript
import { GalileoEvaluateWorkflow } from "@rungalileo/galileo";
const evaluateWorkflow = new GalileoEvaluateWorkflow("eval-project");
await evaluateWorkflow.init();
const testCases = [
{ input: "What is ML?", expected: "Machine learning is..." },
{ input: "Explain AI", expected: "Artificial intelligence is..." },
];
for (const testCase of testCases) {
evaluateWorkflow.addWorkflow({ input: testCase.input });
const response = await callYourLLM(testCase.input);
evaluateWorkflow.addLlmStep({
input: testCase.input,
output: response,
durationNs: 1000000000,
model: "gpt-4o",
});
evaluateWorkflow.concludeWorkflow(response);
}
await evaluateWorkflow.uploadWorkflows({
context_adherence: true,
completeness: true,
toxicity: true,
});Evaluation with RAG Steps
含RAG步骤的评估
typescript
const evaluateWorkflow = new GalileoEvaluateWorkflow("rag-eval");
await evaluateWorkflow.init();
evaluateWorkflow.addWorkflow({ input: "How does photosynthesis work?" });
evaluateWorkflow.addRetrieverStep({
input: "How does photosynthesis work?",
output: ["Photosynthesis is the process by which plants..."],
});
evaluateWorkflow.addLlmStep({
input: "Using the context, explain photosynthesis.",
output: "Photosynthesis is a process used by plants...",
durationNs: 1500000000,
model: "gpt-4o",
});
evaluateWorkflow.concludeWorkflow("Photosynthesis is a process used by plants...");
await evaluateWorkflow.uploadWorkflows({
context_adherence: true,
chunk_attribution: true,
});typescript
const evaluateWorkflow = new GalileoEvaluateWorkflow("rag-eval");
await evaluateWorkflow.init();
evaluateWorkflow.addWorkflow({ input: "How does photosynthesis work?" });
evaluateWorkflow.addRetrieverStep({
input: "How does photosynthesis work?",
output: ["Photosynthesis is the process by which plants..."],
});
evaluateWorkflow.addLlmStep({
input: "Using the context, explain photosynthesis.",
output: "Photosynthesis is a process used by plants...",
durationNs: 1500000000,
model: "gpt-4o",
});
evaluateWorkflow.concludeWorkflow("Photosynthesis is a process used by plants...");
await evaluateWorkflow.uploadWorkflows({
context_adherence: true,
chunk_attribution: true,
});Common Patterns
常见模式
Multiple Workflows in a Single Upload
单次上传多个工作流
typescript
const workflow = new GalileoObserveWorkflow("batch-project");
await workflow.init();
const queries = ["Question 1", "Question 2", "Question 3"];
for (const query of queries) {
workflow.addWorkflow({ input: query });
const response = await callYourLLM(query);
workflow.addLlmStep({
input: query,
output: response,
durationNs: 1000000000,
model: "gpt-4o",
});
workflow.concludeWorkflow(response);
}
await workflow.uploadWorkflows();typescript
const workflow = new GalileoObserveWorkflow("batch-project");
await workflow.init();
const queries = ["Question 1", "Question 2", "Question 3"];
for (const query of queries) {
workflow.addWorkflow({ input: query });
const response = await callYourLLM(query);
workflow.addLlmStep({
input: query,
output: response,
durationNs: 1000000000,
model: "gpt-4o",
});
workflow.concludeWorkflow(response);
}
await workflow.uploadWorkflows();Nested Agent Workflows
嵌套Agent工作流
typescript
const workflow = new GalileoObserveWorkflow("agent-project");
await workflow.init();
workflow.addWorkflow({ input: "Research and summarize quantum computing" });
workflow.addToolStep({
input: "search: quantum computing overview",
output: "Search results...",
durationNs: 200000000,
});
workflow.addRetrieverStep({
input: "quantum computing",
output: ["Doc1: Quantum bits...", "Doc2: Superposition..."],
});
workflow.addLlmStep({
input: "Summarize the following research on quantum computing...",
output: "Quantum computing leverages quantum mechanical phenomena...",
durationNs: 2500000000,
model: "gpt-4o",
});
workflow.concludeWorkflow(
"Quantum computing leverages quantum mechanical phenomena..."
);
await workflow.uploadWorkflows();typescript
const workflow = new GalileoObserveWorkflow("agent-project");
await workflow.init();
workflow.addWorkflow({ input: "Research and summarize quantum computing" });
workflow.addToolStep({
input: "search: quantum computing overview",
output: "Search results...",
durationNs: 200000000,
});
workflow.addRetrieverStep({
input: "quantum computing",
output: ["Doc1: Quantum bits...", "Doc2: Superposition..."],
});
workflow.addLlmStep({
input: "Summarize the following research on quantum computing...",
output: "Quantum computing leverages quantum mechanical phenomena...",
durationNs: 2500000000,
model: "gpt-4o",
});
workflow.concludeWorkflow(
"Quantum computing leverages quantum mechanical phenomena..."
);
await workflow.uploadWorkflows();Best Practices
最佳实践
- Always call before adding workflows — it authenticates and sets up the project.
init() - Always call with the final output before starting the next workflow or uploading.
concludeWorkflow() - Always call at the end to send data to Galileo.
uploadWorkflows() - Use accurate values — measure actual LLM call duration in nanoseconds for meaningful latency tracking.
durationNs - Set environment variables in files rather than hardcoding API keys.
.env - Use for test/eval runs and
GalileoEvaluateWorkflowfor production monitoring.GalileoObserveWorkflow - Pass scorer configuration to in evaluate mode to get metric scores computed.
uploadWorkflows()
- 始终先调用再添加工作流 — 它会完成认证并完成项目初始化。
init() - 始终调用传入最终输出,再开始下一个工作流或执行上传操作。
concludeWorkflow() - 始终在最后调用将数据发送到Galileo。
uploadWorkflows() - 使用准确的值 — 实际测量LLM调用的纳秒级时长,以获得有意义的延迟追踪数据。
durationNs - 在文件中设置环境变量 而非硬编码API密钥。
.env - 测试/评估运行使用,生产环境监控使用**
GalileoEvaluateWorkflow**。GalileoObserveWorkflow - 在评估模式下向传入评分器配置 以计算得到指标分数。
uploadWorkflows()
Resources
资源
- Documentation: https://docs.galileo.ai
- TypeScript SDK repo: https://github.com/rungalileo/galileo-js
- SDK examples: https://github.com/rungalileo/sdk-examples
- npm: https://www.npmjs.com/package/@rungalileo/galileo
- Galileo console: https://app.galileo.ai
- 文档: https://docs.galileo.ai
- TypeScript SDK仓库: https://github.com/rungalileo/galileo-js
- SDK示例: https://github.com/rungalileo/sdk-examples
- npm地址: https://www.npmjs.com/package/@rungalileo/galileo
- Galileo控制台: https://app.galileo.ai