Code Generation (ibm/granite-34b-code-instruct)

POST {{baseUrl}}/ml/v1/text/generation?version=2023-05-29

Request Params

KeyDatatypeRequiredDescription
versionstring

Request Body

{"input"=>"Using the directions below, generate Python code for the given task.\n\nInput: # Write a Python function that prints 'Hello World!' string 'n' times.\nOutput: def print_n_times(n):\n    for i in range(n):\n        print(\"Hello World!\")\n\n<end of code>\n\nInput: # Write a Python function, which generates sequence of prime numbers.\n# The function 'primes' will take the argument 'n', an int. It will return a list which contains all primes less than 'n'.\nOutput:", "parameters"=>{"decoding_method"=>"greedy", "max_new_tokens"=>1000, "min_new_tokens"=>1, "stop_sequences"=>["<end of code>"], "repetition_penalty"=>1}, "model_id"=>"ibm/granite-34b-code-instruct", "project_id"=>"{{projectId}}", "moderations"=>{"hap"=>{"input"=>{"enabled"=>true, "threshold"=>0.5, "mask"=>{"remove_entity_value"=>true}}, "output"=>{"enabled"=>true, "threshold"=>0.5, "mask"=>{"remove_entity_value"=>true}}}}}

RESPONSES

status: OK

{&quot;model_id&quot;:&quot;ibm/granite-34b-code-instruct&quot;,&quot;created_at&quot;:&quot;2024-05-12T13:42:49.501Z&quot;,&quot;results&quot;:[{&quot;generated_text&quot;:&quot; def primes(n):\n    primes = []\n    for i in range(2, n):\n        is_prime = True\n        for j in range(2, i):\n            if i % j == 0:\n                is_prime = False\n                break\n        if is_prime:\n            primes.append(i)\n    return primes\n\n\u003cend of code\u003e&quot;,&quot;generated_token_count&quot;:79,&quot;input_token_count&quot;:120,&quot;stop_reason&quot;:&quot;stop_sequence&quot;}]}