-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Text Generation working with the HF hosted and managed endpoints.
- Loading branch information
1 parent
000ad39
commit f8c027f
Showing
8 changed files
with
97 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
19 changes: 19 additions & 0 deletions
19
...e2solve/huggingface/inference/spring/cloud/starter/autoconfigure/HFServiceAutoconfig.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
package io.clue2solve.huggingface.inference.spring.cloud.starter.autoconfigure; | ||
|
||
import io.clue2solve.huggingface.inference.spring.cloud.starter.config.HuggingFaceProperties; | ||
import io.clue2solve.huggingface.inference.spring.cloud.starter.service.HFInferenceService; | ||
import io.clue2solve.huggingface.inference.spring.cloud.starter.service.impl.HFTextGenerationService; | ||
import org.springframework.boot.autoconfigure.AutoConfiguration; | ||
import org.springframework.boot.context.properties.EnableConfigurationProperties; | ||
import org.springframework.context.annotation.Bean; | ||
|
||
@AutoConfiguration | ||
@EnableConfigurationProperties({ HuggingFaceProperties.class }) | ||
public class HFServiceAutoconfig { | ||
|
||
@Bean | ||
public HFInferenceService hfInferenceService(HuggingFaceProperties properties) { | ||
return new HFTextGenerationService(properties); | ||
} | ||
|
||
} |
9 changes: 9 additions & 0 deletions
9
...o/clue2solve/huggingface/inference/spring/cloud/starter/config/HuggingFaceProperties.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
package io.clue2solve.huggingface.inference.spring.cloud.starter.config; | ||
|
||
import org.springframework.boot.context.properties.ConfigurationProperties; | ||
import org.springframework.context.annotation.Configuration; | ||
|
||
@ConfigurationProperties(prefix = "huggingface") | ||
public record HuggingFaceProperties(String apiToken, String modelName) { | ||
|
||
} |
13 changes: 10 additions & 3 deletions
13
...vice/impl/HFInferenceEndpointService.java → ...service/impl/HFTextGenerationService.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
3 changes: 2 additions & 1 deletion
3
src/main/resources/spring/org.springframework.boot.autoconfigure.AutoConfiguration.imports
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,3 @@ | ||
io.clue2solve.spring.cloud.starter.huggingface.inference.autoconfigure.RestTemplateAutoConfiguration | ||
io.clue2solve.spring.cloud.starter.huggingface.inference.service.HFModels | ||
io.clue2solve.spring.cloud.starter.huggingface.inference.service.HFModels | ||
io.clue2solve.huggingface.inference.spring.cloud.starter.autoconfigure.HuggingFaceInferenceAutoConfiguration |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
46 changes: 46 additions & 0 deletions
46
...cloud/starter/huggingface/inference/starter/service/impl/HFTextGenerationServiceTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
package io.clue2solve.spring.cloud.starter.huggingface.inference.starter.service.impl; | ||
|
||
import com.fasterxml.jackson.databind.JsonNode; | ||
import com.fasterxml.jackson.databind.ObjectMapper; | ||
import io.clue2solve.huggingface.inference.spring.cloud.starter.autoconfigure.HFServiceAutoconfig; | ||
import io.clue2solve.huggingface.inference.spring.cloud.starter.service.HFInferenceService; | ||
import io.clue2solve.spring.cloud.starter.huggingface.inference.starter.TestInit; | ||
|
||
import org.junit.jupiter.api.Test; | ||
import org.slf4j.Logger; | ||
import org.slf4j.LoggerFactory; | ||
import org.springframework.beans.factory.annotation.Autowired; | ||
import org.springframework.boot.test.context.SpringBootTest; | ||
|
||
import static org.junit.jupiter.api.Assertions.assertNotNull; | ||
import static org.junit.jupiter.api.Assertions.assertTrue; | ||
|
||
@SpringBootTest(classes = { TestInit.class, HFServiceAutoconfig.class }) | ||
public class HFTextGenerationServiceTest { | ||
|
||
Logger logger = LoggerFactory.getLogger(HFTextGenerationServiceTest.class); | ||
|
||
@Autowired | ||
private HFInferenceService hfInferenceService; | ||
|
||
@Test | ||
public void HFInferenceEndpointServiceTestInvoke() throws Exception { | ||
String response = hfInferenceService.invoke("the world or technology is heading towards"); | ||
|
||
// Assert that the response is not null | ||
assertNotNull(response); | ||
|
||
logger.info(response); | ||
// // Parse the response into a JsonNode | ||
ObjectMapper mapper = new ObjectMapper(); | ||
JsonNode node = mapper.readTree(response); | ||
|
||
// // Pretty print the JsonNode | ||
String prettyJson = mapper.writerWithDefaultPrettyPrinter().writeValueAsString(node); | ||
logger.info("Response: {}", prettyJson); | ||
|
||
// // Assert that the JsonNode is an array | ||
assertTrue(node.isArray()); | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
huggingface.api-token=YOUR_HUGGINGFACE_API_TOKEN | ||
huggingface.model-name=MODEL_NAME ( like 'gpt2' ) | ||
|