@celljs/ai-pi 4.6.0 → 4.7.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.en.md +68 -0
- package/package.json +3 -3
package/README.en.md
ADDED
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
# Cell - AI pi Component
|
|
2
|
+
|
|
3
|
+
Integrates [pi-ai](https://www.npmjs.com/package/@earendil-works/pi-ai) into Cell. Pi-ai unifies calls to 20+ model service providers (Anthropic, OpenAI, Google, DeepSeek, xAI, OpenRouter, Bedrock, Ollama, and other OpenAI-compatible services, etc.), model catalogs, credentials, and usage statistics. This component provides:
|
|
4
|
+
|
|
5
|
+
- `PiModelsProvider`: application-level pi-ai `Models` collection, configured via `ai.pi`;
|
|
6
|
+
- `PiChatModel`: an implementation of `ChatModel` from @celljs/ai-core that calls pi-ai via `ProxyChatModel` using `pi:<provider>/<model id>`;
|
|
7
|
+
- [@celljs/ai-agent](../ai-agent) agents use it to get models.
|
|
8
|
+
|
|
9
|
+
Pi-ai is an ES module package that the component loads via dynamic `import()`. It is loaded only when a model is first used. Node.js >= 22.19 or Bun is required.
|
|
10
|
+
|
|
11
|
+
## Configuration
|
|
12
|
+
|
|
13
|
+
```yaml
|
|
14
|
+
ai:
|
|
15
|
+
pi:
|
|
16
|
+
providers: [anthropic, deepseek] # default all: register all built-in providers from pi-ai
|
|
17
|
+
apiKeys: # kept only in memory; providers also read ANTHROPIC_API_KEY etc from environment
|
|
18
|
+
deepseek: "${ env.MY_DEEPSEEK_KEY }"
|
|
19
|
+
```
|
|
20
|
+
|
|
21
|
+
### Compatible Endpoints
|
|
22
|
+
|
|
23
|
+
The `endpoints` option registers OpenAI or Anthropic-compatible services as providers. The model name is `<endpoint id>/<model id>`:
|
|
24
|
+
|
|
25
|
+
```yaml
|
|
26
|
+
ai:
|
|
27
|
+
pi:
|
|
28
|
+
endpoints:
|
|
29
|
+
local: # model is local/qwen3
|
|
30
|
+
baseUrl: http://localhost:11434/v1 # Ollama; vLLM, LM Studio, custom gateway likewise
|
|
31
|
+
models: [qwen3, { id: deepseek-r1, reasoning: true, contextWindow: 64000 }]
|
|
32
|
+
gateway:
|
|
33
|
+
baseUrl: https://llm.example.com/v1
|
|
34
|
+
api: anthropic-messages # default openai-completions; also supports openai-responses
|
|
35
|
+
apiKey: "${ env.GATEWAY_KEY }"
|
|
36
|
+
models: [claude-sonnet-4-5]
|
|
37
|
+
```
|
|
38
|
+
|
|
39
|
+
Endpoints without a key receive a placeholder key `no-key`. Items in `apiKeys` with the same name take precedence over `apiKey`.
|
|
40
|
+
|
|
41
|
+
## Usage
|
|
42
|
+
|
|
43
|
+
```typescript
|
|
44
|
+
import { type ChatModel, PromptTemplate, ProxyChatModel } from '@celljs/ai-core';
|
|
45
|
+
import { Autowired, Component } from '@celljs/core';
|
|
46
|
+
|
|
47
|
+
@Component()
|
|
48
|
+
export class Assistant {
|
|
49
|
+
@Autowired(ProxyChatModel)
|
|
50
|
+
protected readonly chatModel: ChatModel;
|
|
51
|
+
|
|
52
|
+
@Autowired(PromptTemplate)
|
|
53
|
+
protected readonly promptTemplate: PromptTemplate;
|
|
54
|
+
|
|
55
|
+
async ask(question: string): Promise<string> {
|
|
56
|
+
const prompt = await this.promptTemplate.create(question, { chatOptions: { model: 'pi:anthropic/claude-sonnet-4-5' } });
|
|
57
|
+
return (await this.chatModel.call(prompt)).result.output.content;
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
```
|
|
61
|
+
|
|
62
|
+
`PiChatOptions` supports `reasoning` (reasoning level) and `tools` (tools with JSON Schema parameters; model invocations appear in `AssistantMessage.toolCalls`) beyond @celljs/ai-core's `ChatOptions`. The `stream()` method sends a response for each text increment; the last response includes the complete message, the stop reason (pi-ai's stop reason: `stop`, `toolUse`, `length`), and usage information. When the model returns an error, it throws `PiModelError`. When the model name is incorrect, it throws `PiModelNotFoundError` and lists available models.
|
|
63
|
+
|
|
64
|
+
To register a custom provider (for example, a custom OpenAI-compatible gateway), implement `PiModelsContribution` and call `models.setProvider(...)` in the `configure(models)` method (see pi-ai documentation on Custom Providers).
|
|
65
|
+
|
|
66
|
+
## Testing
|
|
67
|
+
|
|
68
|
+
`createPiTestContainer()` and `FauxPiModels` from `@celljs/ai-pi/lib/node/test` are based on pi-ai's faux provider: they provide scripted responses, record request context on each call, and do not require internet access.
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@celljs/ai-pi",
|
|
3
|
-
"version": "4.
|
|
3
|
+
"version": "4.7.0",
|
|
4
4
|
"description": "pi-ai models (20+ providers) as Cell chat models",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"cell-component"
|
|
@@ -33,8 +33,8 @@
|
|
|
33
33
|
"watch": "tsc -b -w --preserveWatchOutput"
|
|
34
34
|
},
|
|
35
35
|
"dependencies": {
|
|
36
|
-
"@celljs/ai-core": "4.
|
|
37
|
-
"@celljs/core": "4.
|
|
36
|
+
"@celljs/ai-core": "4.7.0",
|
|
37
|
+
"@celljs/core": "4.7.0",
|
|
38
38
|
"@earendil-works/pi-ai": "^1.5.0",
|
|
39
39
|
"rxjs": "^6.6.0"
|
|
40
40
|
},
|