|
| 1 | +extend type Query { |
| 2 | + """ |
| 3 | + Infers the next tokens for a given deployed model from the `input` text. |
| 4 | + """ |
| 5 | + wxai_generation( |
| 6 | + input: String |
| 7 | + model_id: String! = "ibm/granite-3-8b-instruct" |
| 8 | + parameters: WXAI_GenerationParameters |
| 9 | + ): WXAI_GenerationResponse |
| 10 | + @sequence( |
| 11 | + steps: [ |
| 12 | + { query: "ibm_iam_token" } |
| 13 | + { |
| 14 | + query: "_wxai_generation" |
| 15 | + arguments: [ |
| 16 | + { name: "token", field: "§0" } |
| 17 | + { name: "input", argument: "input" } |
| 18 | + { name: "model_id", argument: "model_id" } |
| 19 | + { name: "parameters", argument: "parameters" } |
| 20 | + ] |
| 21 | + } |
| 22 | + ] |
| 23 | + ) |
| 24 | + |
| 25 | + """ |
| 26 | + Calls the generation endpoint. |
| 27 | + """ |
| 28 | + _wxai_generation( |
| 29 | + token: Secret! |
| 30 | + input: String |
| 31 | + model_id: String |
| 32 | + parameters: WXAI_GenerationParameters |
| 33 | + ): WXAI_GenerationResponse |
| 34 | + @rest( |
| 35 | + method: POST |
| 36 | + endpoint: "$url;" |
| 37 | + path: "/ml/v1/text/generation?version=$version" |
| 38 | + headers: [{ name: "authorization", value: "Bearer $token" }] |
| 39 | + ecmascript: """ |
| 40 | + function bodyPOST(s) { |
| 41 | + let body = JSON.parse(s) |
| 42 | + body.project_id = get("project_id") |
| 43 | + return JSON.stringify(body) |
| 44 | + } |
| 45 | + """ |
| 46 | + configuration: "watsonx-service" |
| 47 | + ) |
| 48 | +} |
| 49 | + |
| 50 | +""" |
| 51 | +The parameters for the model of a generative AI request. See https://cloud.ibm.com/apidocs/watsonx-ai#text-generation for more details. |
| 52 | +""" |
| 53 | +input WXAI_GenerationParameters { |
| 54 | + """ |
| 55 | + The temperature specifies the amount of variation in the generation process when using sampling mode. |
| 56 | + """ |
| 57 | + temperature: Float = 0 |
| 58 | + """ |
| 59 | + The strategy the model uses to choose the tokens in the generated output. |
| 60 | + """ |
| 61 | + decoding_method: String |
| 62 | + """ |
| 63 | + The minimum number of new tokens to be generated. |
| 64 | + """ |
| 65 | + min_new_tokens: Int |
| 66 | + """ |
| 67 | + The maximum number of new tokens to be generated. |
| 68 | + """ |
| 69 | + max_new_tokens: Int = 20 |
| 70 | + """ |
| 71 | + The repetition penalty lowers the probability scores of tokens that have already been generated or belong to the context. |
| 72 | + """ |
| 73 | + repetition_penalty: Float |
| 74 | + """ |
| 75 | + A string of one or more characters which will stop the text generation if/when they appear in the generated output. |
| 76 | + """ |
| 77 | + stop_sequences: [String] |
| 78 | +} |
| 79 | + |
| 80 | +""" |
| 81 | +Response of IBM watsonx.ai `generation` endpoint |
| 82 | +""" |
| 83 | +type WXAI_GenerationResponse { |
| 84 | + created_at: DateTime |
| 85 | + model_id: String |
| 86 | + model_version: String |
| 87 | + results: [WXAI_GenerationResult] |
| 88 | +} |
| 89 | + |
| 90 | +""" |
| 91 | +A result in the response of IBM watsonx.ai `generation` endpoint |
| 92 | +""" |
| 93 | +type WXAI_GenerationResult { |
| 94 | + generated_text: String |
| 95 | + generated_token_count: Int |
| 96 | + input_token_count: Int |
| 97 | + stop_reason: String |
| 98 | +} |
0 commit comments