From 133ea6edd305b1b46476c640480f86915892d5bc Mon Sep 17 00:00:00 2001 From: Ratnakar Asara Date: Thu, 20 Nov 2025 18:43:41 -0500 Subject: [PATCH 1/3] chore: use inject directive to exxtract and set iam access_token wx service Signed-off-by: Ratnakar Asara --- ai/watsonxai-generation/config.yaml | 1 + ai/watsonxai-generation/ibm-iam.graphql | 3 +- ai/watsonxai-generation/watsonx-ai.graphql | 35 +++++++--------------- 3 files changed, 12 insertions(+), 27 deletions(-) diff --git a/ai/watsonxai-generation/config.yaml b/ai/watsonxai-generation/config.yaml index 5675662..59d0b39 100644 --- a/ai/watsonxai-generation/config.yaml +++ b/ai/watsonxai-generation/config.yaml @@ -8,3 +8,4 @@ configurationset: version: '2024-06-28' url: STEPZEN_WATSONXAI_URL project_id: STEPZEN_WATSONXAI_PROJECTID + model_id: "ibm/granite-3-8b-instruct" diff --git a/ai/watsonxai-generation/ibm-iam.graphql b/ai/watsonxai-generation/ibm-iam.graphql index 3de1d0c..06b5a81 100644 --- a/ai/watsonxai-generation/ibm-iam.graphql +++ b/ai/watsonxai-generation/ibm-iam.graphql @@ -6,7 +6,7 @@ extend type Query { or [service ID's API Key](https://cloud.ibm.com/docs/account?topic=account-serviceidapikeys&interface=ui) to [generate an IAM Token](https://cloud.ibm.com/docs/account?topic=account-iamtoken_from_apikey#iamtoken_from_apikey) """ - ibm_iam_token: Secret + ibm_iam_token: JSON @rest( endpoint: "$endpoint" method: POST @@ -27,7 +27,6 @@ extend type Query { } } """ - setters: { path: "access_token" } configuration: "ibm-iam" ) } diff --git a/ai/watsonxai-generation/watsonx-ai.graphql b/ai/watsonxai-generation/watsonx-ai.graphql index c9a760d..e40034b 100644 --- a/ai/watsonxai-generation/watsonx-ai.graphql +++ b/ai/watsonxai-generation/watsonx-ai.graphql @@ -1,45 +1,30 @@ extend type Query { """ - Infers the next tokens for a given deployed model from the `input` text. + Extract IBM IAM token and inject it into wxai_generation for authentication. + This makes the access_token available as an expansion variable. """ - wxai_generation( - input: String - model_id: String! = "ibm/granite-3-8b-instruct" - parameters: WXAI_GenerationParameters - ): WXAI_GenerationResponse - @sequence( - steps: [ - { query: "ibm_iam_token" } - { - query: "_wxai_generation" - arguments: [ - { name: "token", field: "§0" } - { name: "input", argument: "input" } - { name: "model_id", argument: "model_id" } - { name: "parameters", argument: "parameters" } - ] - } - ] - ) + _inject_ibm_iam_token: JSON + @inject(on: [{ expose: true, types: "Query", fields: "wxai_generation" }]) + @materializer(query: "ibm_iam_token") """ - Calls the generation endpoint. + Infers the next tokens for a given deployed model from the `input` text. """ - _wxai_generation( - token: Secret! + wxai_generation( input: String - model_id: String + model_id: String! = "ibm/granite-3-8b-instruct" parameters: WXAI_GenerationParameters ): WXAI_GenerationResponse @rest( method: POST endpoint: "$url;" path: "/ml/v1/text/generation?version=$version" - headers: [{ name: "authorization", value: "Bearer $token" }] + headers: [{ name: "authorization", value: "Bearer $access_token" }] ecmascript: """ function bodyPOST(s) { let body = JSON.parse(s) body.project_id = get("project_id") + body.model_id = get("model_id") return JSON.stringify(body) } """ From 47d1c11c5ac2277d99b61624888f1a521b36c0aa Mon Sep 17 00:00:00 2001 From: Ratnakar Asara Date: Fri, 21 Nov 2025 08:08:08 -0500 Subject: [PATCH 2/3] config not needed Signed-off-by: Ratnakar Asara --- ai/watsonxai-generation/config.yaml | 1 - ai/watsonxai-generation/watsonx-ai.graphql | 3 +-- 2 files changed, 1 insertion(+), 3 deletions(-) diff --git a/ai/watsonxai-generation/config.yaml b/ai/watsonxai-generation/config.yaml index 59d0b39..5675662 100644 --- a/ai/watsonxai-generation/config.yaml +++ b/ai/watsonxai-generation/config.yaml @@ -8,4 +8,3 @@ configurationset: version: '2024-06-28' url: STEPZEN_WATSONXAI_URL project_id: STEPZEN_WATSONXAI_PROJECTID - model_id: "ibm/granite-3-8b-instruct" diff --git a/ai/watsonxai-generation/watsonx-ai.graphql b/ai/watsonxai-generation/watsonx-ai.graphql index e40034b..eac85e5 100644 --- a/ai/watsonxai-generation/watsonx-ai.graphql +++ b/ai/watsonxai-generation/watsonx-ai.graphql @@ -12,7 +12,7 @@ extend type Query { """ wxai_generation( input: String - model_id: String! = "ibm/granite-3-8b-instruct" + model_id: String = "ibm/granite-3-8b-instruct" parameters: WXAI_GenerationParameters ): WXAI_GenerationResponse @rest( @@ -24,7 +24,6 @@ extend type Query { function bodyPOST(s) { let body = JSON.parse(s) body.project_id = get("project_id") - body.model_id = get("model_id") return JSON.stringify(body) } """ From 6a3c6c6f8fd49b5b45ec789cdf40e6bb067997aa Mon Sep 17 00:00:00 2001 From: Ratnakar Asara Date: Fri, 21 Nov 2025 09:58:07 -0500 Subject: [PATCH 3/3] donot change the library Signed-off-by: Ratnakar Asara --- ai/watsonxai-generation/ibm-iam.graphql | 3 ++- ai/watsonxai-generation/watsonx-ai.graphql | 24 +++++++++++++++++++--- 2 files changed, 23 insertions(+), 4 deletions(-) diff --git a/ai/watsonxai-generation/ibm-iam.graphql b/ai/watsonxai-generation/ibm-iam.graphql index 06b5a81..3de1d0c 100644 --- a/ai/watsonxai-generation/ibm-iam.graphql +++ b/ai/watsonxai-generation/ibm-iam.graphql @@ -6,7 +6,7 @@ extend type Query { or [service ID's API Key](https://cloud.ibm.com/docs/account?topic=account-serviceidapikeys&interface=ui) to [generate an IAM Token](https://cloud.ibm.com/docs/account?topic=account-iamtoken_from_apikey#iamtoken_from_apikey) """ - ibm_iam_token: JSON + ibm_iam_token: Secret @rest( endpoint: "$endpoint" method: POST @@ -27,6 +27,7 @@ extend type Query { } } """ + setters: { path: "access_token" } configuration: "ibm-iam" ) } diff --git a/ai/watsonxai-generation/watsonx-ai.graphql b/ai/watsonxai-generation/watsonx-ai.graphql index eac85e5..04d48d4 100644 --- a/ai/watsonxai-generation/watsonx-ai.graphql +++ b/ai/watsonxai-generation/watsonx-ai.graphql @@ -1,12 +1,30 @@ extend type Query { + """ + Internal helper that accepts a Secret token and returns it as JSON. + This allows the Secret type to be converted to JSON for injection. + """ + _token_to_json(token: Secret!): JSON + @value( + script: { + src: """ + {"token": token } + """ + language: JSONATA + } + ) + """ Extract IBM IAM token and inject it into wxai_generation for authentication. This makes the access_token available as an expansion variable. """ _inject_ibm_iam_token: JSON @inject(on: [{ expose: true, types: "Query", fields: "wxai_generation" }]) - @materializer(query: "ibm_iam_token") - + @sequence( + steps: [ + { query: "ibm_iam_token" } + { query: "_token_to_json", arguments: [{ name: "token", field: "§0" }] } + ] + ) """ Infers the next tokens for a given deployed model from the `input` text. """ @@ -19,7 +37,7 @@ extend type Query { method: POST endpoint: "$url;" path: "/ml/v1/text/generation?version=$version" - headers: [{ name: "authorization", value: "Bearer $access_token" }] + headers: [{ name: "authorization", value: "Bearer $token" }] ecmascript: """ function bodyPOST(s) { let body = JSON.parse(s)