Class HuggingfaceChatClient
java.lang.Object
org.springframework.ai.huggingface.HuggingfaceChatClient
- All Implemented Interfaces:
ChatClient
,ModelClient<Prompt,
ChatResponse>
An implementation of
ChatClient
that interfaces with HuggingFace Inference
Endpoints for text generation.- Author:
- Mark Pollack
-
Constructor Summary
ConstructorDescriptionHuggingfaceChatClient
(String apiToken, String basePath) Constructs a new HuggingfaceChatClient with the specified API token and base path. -
Method Summary
Modifier and TypeMethodDescriptionGenerate text based on the provided prompt.int
Gets the maximum number of new tokens to be generated.void
setMaxNewTokens
(int maxNewTokens) Sets the maximum number of new tokens to be generated.Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
Methods inherited from interface org.springframework.ai.chat.ChatClient
call
-
Constructor Details
-
HuggingfaceChatClient
Constructs a new HuggingfaceChatClient with the specified API token and base path.- Parameters:
apiToken
- The API token for HuggingFace.basePath
- The base path for API requests.
-
-
Method Details
-
call
Generate text based on the provided prompt.- Specified by:
call
in interfaceChatClient
- Specified by:
call
in interfaceModelClient<Prompt,
ChatResponse> - Parameters:
prompt
- The input prompt based on which text is to be generated.- Returns:
- ChatResponse containing the generated text and other related details.
-
getMaxNewTokens
public int getMaxNewTokens()Gets the maximum number of new tokens to be generated.- Returns:
- The maximum number of new tokens.
-
setMaxNewTokens
public void setMaxNewTokens(int maxNewTokens) Sets the maximum number of new tokens to be generated.- Parameters:
maxNewTokens
- The maximum number of new tokens.
-