Skip to content

Commit c2bd31b

Browse files
committed
refactor: change granite-io block syntax
Signed-off-by: Louis Mandel <[email protected]>
1 parent dba3cab commit c2bd31b

File tree

12 files changed

+234
-153
lines changed

12 files changed

+234
-153
lines changed

examples/granite-io/granite_io_hallucinations.pdl

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,8 +39,9 @@ defs:
3939

4040
text:
4141
- Did Faith Hill take a break from recording after releasing her second album, It Matters to Me?
42-
- model: "granite3.2:2b"
43-
backend: openai
42+
- processor:
43+
model: "granite3.2:2b"
44+
backend: openai
4445
parameters:
4546
documents:
4647
- ${ doc }
Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
text:
22
- "Hello!\n"
3-
- model: "granite3.2:2b"
4-
backend: openai
3+
- processor:
4+
model: "granite3.2:2b"
5+
backend: openai
Lines changed: 14 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,16 @@
11
text:
2+
- Find the fastest way for a seller to visit all the cities in their region
3+
- defs:
4+
response:
5+
processor:
6+
model: "granite3.2:2b"
7+
backend: openai
8+
parameters:
9+
thinking: true
10+
modelResponse: outputs
211
- |
3-
Find the fastest way for a seller to visit all the cities in their region
4-
>> Response:
5-
- model: "granite3.2:2b"
6-
backend: openai
7-
parameters:
8-
thinking: true
9-
modelResponse: outputs
10-
- "\n"
11-
- |
12-
>> Thoughts:
13-
${ outputs.results[0].next_message.reasoning_content }
12+
13+
>> Thoughts:
14+
${ outputs.results[0].next_message.reasoning_content }
15+
>> Response:
16+
${ response }
Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
text:
22
- "Hello!\n"
3-
- model: ibm-granite/granite-3.2-2b-instruct
4-
backend:
5-
transformers: cpu
6-
processor: granite3.2
3+
- processor:
4+
type: granite3.2
5+
model: ibm-granite/granite-3.2-2b-instruct
6+
backend:
7+
transformers: cpu

pdl-live-react/src/pdl_ast.d.ts

Lines changed: 7 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -2354,11 +2354,6 @@ export type PdlContext17 =
23542354
export type PdlId17 = string | null
23552355
export type PdlIsLeaf17 = true
23562356
export type Kind17 = "model"
2357-
/**
2358-
* Model name used by the backend.
2359-
*
2360-
*/
2361-
export type Model = LocalizedExpression | string
23622357
/**
23632358
* Messages to send to the model.
23642359
*
@@ -2502,11 +2497,6 @@ export type PdlContext18 =
25022497
export type PdlId18 = string | null
25032498
export type PdlIsLeaf18 = true
25042499
export type Kind18 = "model"
2505-
/**
2506-
* Name of the model following the LiteLLM convention.
2507-
*
2508-
*/
2509-
export type Model1 = LocalizedExpression | string
25102500
/**
25112501
* Messages to send to the model.
25122502
*
@@ -2552,6 +2542,11 @@ export type PdlModelInput1 =
25522542
*
25532543
*/
25542544
export type Platform1 = "litellm"
2545+
/**
2546+
* Name of the model following the LiteLLM convention.
2547+
*
2548+
*/
2549+
export type Model1 = LocalizedExpression | string
25552550
/**
25562551
* Parameters to send to the model.
25572552
*
@@ -3113,7 +3108,6 @@ export interface LitellmModelBlock {
31133108
pdl__timing?: PdlTiming | null
31143109
pdl__is_leaf?: PdlIsLeaf18
31153110
kind?: Kind18
3116-
model: Model1
31173111
input?: Input1
31183112
modelResponse?: Modelresponse1
31193113
/**
@@ -3123,6 +3117,7 @@ export interface LitellmModelBlock {
31233117
pdl__usage?: PdlUsage | null
31243118
pdl__model_input?: PdlModelInput1
31253119
platform?: Platform1
3120+
model: Model1
31263121
parameters?: Parameters1
31273122
}
31283123
/**
@@ -3200,7 +3195,6 @@ export interface GraniteioModelBlock {
32003195
pdl__timing?: PdlTiming | null
32013196
pdl__is_leaf?: PdlIsLeaf17
32023197
kind?: Kind17
3203-
model: Model
32043198
input?: Input
32053199
modelResponse?: Modelresponse
32063200
/**
@@ -3210,8 +3204,7 @@ export interface GraniteioModelBlock {
32103204
pdl__usage?: PdlUsage | null
32113205
pdl__model_input?: PdlModelInput
32123206
platform?: Platform
3213-
backend: unknown
3214-
processor?: unknown
3207+
processor: unknown
32153208
parameters?: Parameters
32163209
}
32173210
/**

pdl-live-react/src/pdl_ast_utils.ts

Lines changed: 22 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -62,25 +62,38 @@ export function map_block_children(
6262
{
6363
kind: "model",
6464
platform: "granite-io",
65-
backend: P.nonNullable,
6665
processor: P._,
6766
},
6867
(block) => {
69-
const model = f_expr(block.model)
68+
const processor = match(block.processor)
69+
.with(
70+
{
71+
type: P.union(P._, P.nullish),
72+
model: P.union(P._, P.nullish),
73+
backend: P.nonNullable,
74+
},
75+
(proc) => {
76+
const type = proc.type ? f_expr(proc.type) : undefined
77+
const model = proc.model ? f_expr(proc.model) : undefined
78+
const backend = f_expr(proc.backend)
79+
return {
80+
...proc,
81+
type,
82+
model,
83+
backend,
84+
}
85+
},
86+
)
87+
.otherwise((proc) => f_expr(proc))
7088
const input = block.input ? f_block(block.input) : undefined
71-
// @ts-expect-error: f_expr does not preserve the type of the expression
72-
const parameters: Parameters = block.parameters
89+
const parameters = block.parameters
7390
? f_expr(block.parameters)
7491
: undefined
75-
const backend = f_expr(block.backend)
76-
const processor = block.processor ? f_expr(block.processor) : undefined
7792
return {
7893
...block,
79-
model,
94+
processor,
8095
input,
8196
parameters,
82-
backend,
83-
processor,
8497
}
8598
},
8699
)

src/pdl/pdl-schema.json

Lines changed: 66 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -4456,18 +4456,6 @@
44564456
"title": "Kind",
44574457
"type": "string"
44584458
},
4459-
"model": {
4460-
"anyOf": [
4461-
{
4462-
"$ref": "#/$defs/LocalizedExpression_TypeVar_"
4463-
},
4464-
{
4465-
"type": "string"
4466-
}
4467-
],
4468-
"description": "Model name used by the backend.\n ",
4469-
"title": "Model"
4470-
},
44714459
"input": {
44724460
"anyOf": [
44734461
{
@@ -4601,49 +4589,71 @@
46014589
"title": "Platform",
46024590
"type": "string"
46034591
},
4604-
"backend": {
4592+
"processor": {
46054593
"anyOf": [
4594+
{
4595+
"$ref": "#/$defs/GraniteioProcessor"
4596+
},
46064597
{
46074598
"$ref": "#/$defs/LocalizedExpression_TypeVar_"
46084599
},
4600+
{},
46094601
{
46104602
"type": "string"
4603+
}
4604+
],
4605+
"description": "IO Processor configuration or object.\n ",
4606+
"title": "Processor"
4607+
},
4608+
"parameters": {
4609+
"anyOf": [
4610+
{
4611+
"$ref": "#/$defs/LocalizedExpression_TypeVar_"
46114612
},
46124613
{
46134614
"additionalProperties": true,
46144615
"type": "object"
46154616
},
4616-
{}
4617+
{
4618+
"type": "string"
4619+
},
4620+
{
4621+
"type": "null"
4622+
}
46174623
],
4618-
"description": "Backend name and configuration.\n ",
4619-
"title": "Backend"
4620-
},
4621-
"processor": {
4624+
"default": null,
4625+
"description": "Parameters sent to the model.\n ",
4626+
"title": "Parameters"
4627+
}
4628+
},
4629+
"required": [
4630+
"processor"
4631+
],
4632+
"title": "GraniteioModelBlock",
4633+
"type": "object"
4634+
},
4635+
"GraniteioProcessor": {
4636+
"properties": {
4637+
"type": {
46224638
"anyOf": [
46234639
{
46244640
"$ref": "#/$defs/LocalizedExpression_TypeVar_"
46254641
},
46264642
{
46274643
"type": "string"
46284644
},
4629-
{},
46304645
{
46314646
"type": "null"
46324647
}
46334648
],
46344649
"default": null,
4635-
"description": "IO Processor name.\n ",
4636-
"title": "Processor"
4650+
"title": "Type"
46374651
},
4638-
"parameters": {
4652+
"model": {
46394653
"anyOf": [
46404654
{
46414655
"$ref": "#/$defs/LocalizedExpression_TypeVar_"
46424656
},
4643-
{
4644-
"additionalProperties": true,
4645-
"type": "object"
4646-
},
46474657
{
46484658
"type": "string"
46494659
},
@@ -4652,15 +4662,29 @@
46524662
}
46534663
],
46544664
"default": null,
4655-
"description": "Parameters sent to the model.\n ",
4656-
"title": "Parameters"
4665+
"title": "Model"
4666+
},
4667+
"backend": {
4668+
"anyOf": [
4669+
{
4670+
"$ref": "#/$defs/LocalizedExpression_TypeVar_"
4671+
},
4672+
{
4673+
"type": "string"
4674+
},
4675+
{
4676+
"additionalProperties": true,
4677+
"type": "object"
4678+
},
4679+
{}
4680+
],
4681+
"title": "Backend"
46574682
}
46584683
},
46594684
"required": [
4660-
"model",
46614685
"backend"
46624686
],
4663-
"title": "GraniteioModelBlock",
4687+
"title": "GraniteioProcessor",
46644688
"type": "object"
46654689
},
46664690
"IfBlock": {
@@ -7125,18 +7149,6 @@
71257149
"title": "Kind",
71267150
"type": "string"
71277151
},
7128-
"model": {
7129-
"anyOf": [
7130-
{
7131-
"$ref": "#/$defs/LocalizedExpression_TypeVar_"
7132-
},
7133-
{
7134-
"type": "string"
7135-
}
7136-
],
7137-
"description": "Name of the model following the LiteLLM convention.\n ",
7138-
"title": "Model"
7139-
},
71407152
"input": {
71417153
"anyOf": [
71427154
{
@@ -7270,6 +7282,18 @@
72707282
"title": "Platform",
72717283
"type": "string"
72727284
},
7285+
"model": {
7286+
"anyOf": [
7287+
{
7288+
"$ref": "#/$defs/LocalizedExpression_TypeVar_"
7289+
},
7290+
{
7291+
"type": "string"
7292+
}
7293+
],
7294+
"description": "Name of the model following the LiteLLM convention.\n ",
7295+
"title": "Model"
7296+
},
72737297
"parameters": {
72747298
"anyOf": [
72757299
{

0 commit comments

Comments
 (0)