Code Monkey home page Code Monkey logo

spring-cloud-huggingface-starter's Introduction

Spring Cloud Huggingface Starter

Lets you use the Huggingface model inference endpoints with Spring Boot and Spring Cloud

Alpha Github Action CI Workflow Status Known Vulnerabilities License

Huggingface

This project provides a developer-friendly way to access the services of Huggingface, a platform that provides a large number of pre-trained models for Natural Language Processing (NLP). This is a Spring Cloud Starter for the Huggingface service that removes all the boilerplate code required to access the service. It uses the standards of Spring Boot and Spring Cloud to provide the configuration and the auto-wiring of the service objects.

This project leverages Spring Cloud for credential management

Just provide the right properties as defined below and the appropriate Huggingface API token will be activated for injection into your Spring objects.

# for Huggingface API token
huggingface.apiToken=YOUR_API_TOKEN

Properties that will enable HuggingfaceService

huggingface.modelName=gpt3
huggingface.topK=5
huggingface.topP=0.5
huggingface.temperature=0.5
huggingface.repetitionPenalty=1.0
huggingface.maxNewTokens=100
huggingface.maxTime=60.0
huggingface.returnFullText=true
huggingface.numReturnSequences=1
huggingface.doSample=true
huggingface.options.useCache=true
huggingface.options.waitForModel=false

The HuggingfaceService

Once the right API token is injected, you can expect the activation of the HuggingfaceService.

One can use the activated service to interact with the Huggingface model inference endpoints based on the docs for the Huggingface Service.

Usage

Once activated, a Service can be autowired and used as below.

@RestController
public class HuggingfaceController {

   private final HuggingfaceService huggingfaceService;


   @Autowired
   public HuggingfaceController(HuggingfaceService huggingfaceService) {
      this.huggingfaceService = huggingfaceService;
   }

   @GetMapping("/invoke")
   public String invoke(@RequestParam String prompt) {
      try {
         return huggingfaceService.invoke(prompt);
      } catch (Exception e) {
         return "Error invoking Huggingface: " + e.getMessage();
      }
   }
}

You might also want to take a look at and/or run the Service tests. To do that, make sure you've set the appropriate HUGGINGFACE_API_TOKEN environment variable, then execute

mvn test -Dspring.profiles.active=authorized

spring-cloud-huggingface-starter's People

Contributors

honnuanand avatar dependabot[bot] avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.