from ibm_watson_machine_learning.foundation_models import Model
from honeyhive import HoneyHiveTracer
HoneyHiveTracer.init(
    api_key="MY_HONEYHIVE_API_KEY",
    project='MY_HONEYHIVE_PROJECT_NAME',
)
def get_credentials():
    return {
        "url": "https://us-south.ml.cloud.ibm.com", # or another region
        "apikey": "MY_IBM_IAM_API_KEY",
    }
model_id = "ibm/granite-3-2b-instruct"
parameters = {
    "decoding_method": "sample",
    "max_new_tokens": 60,
    "min_new_tokens": 10,
    "random_seed": 42,
    "temperature": 0.9,
    "top_k": 50,
    "top_p": 1,
    "repetition_penalty": 2
}
model = Model(
    model_id=model_id,
    params=parameters,
    credentials=get_credentials(),
    project_id="MY_IBM_PROJECT_ID",
)
prompt_input = "Which IBM model beat Gary Kasparov in chess?"
generated_response = model.generate(prompt=prompt_input)
print(generated_response['results'][0]['generated_text'])