1 /* 2 * Copyright (c) Meta Platforms, Inc. and affiliates. 3 * All rights reserved. 4 * 5 * This source code is licensed under the BSD-style license found in the 6 * LICENSE file in the root directory of this source tree. 7 */ 8 9 package org.pytorch.executorch; 10 11 import com.facebook.jni.annotations.DoNotStrip; 12 import org.pytorch.executorch.annotations.Experimental; 13 14 /** 15 * Callback interface for Llama model. Users can implement this interface to receive the generated 16 * tokens and statistics. 17 * 18 * <p>Warning: These APIs are experimental and subject to change without notice 19 */ 20 @Experimental 21 public interface LlamaCallback { 22 /** 23 * Called when a new result is available from JNI. Users will keep getting onResult() invocations 24 * until generate() finishes. 25 * 26 * @param result Last generated token 27 */ 28 @DoNotStrip onResult(String result)29 public void onResult(String result); 30 31 /** 32 * Called when the statistics for the generate() is available. 33 * 34 * @param tps Tokens/second for generated tokens. 35 */ 36 @DoNotStrip onStats(float tps)37 public void onStats(float tps); 38 } 39