From OpenAI to Open LLMs with Messages API on Hugging Face
Text Generation Inference 1.4.0 adds a Messages API compatible with OpenAI's Chat Completion API, so open LLMs on Inference Endpoints can be called from existing OpenAI client code by changing the base URL and token. The guide deploys Nous-Hermes-2-Mixtral-8x7B-DPO via huggingface_hub with TGI token-limit settings and then calls it from the OpenAI Python and JavaScript clients. It also plugs the endpoint into LangChain (ChatOpenAI) and LlamaIndex (OpenAILike) RAG pipelines. Limitations: no function calling, only models with a chat_template, and a subset of parameters (stream, max_tokens, temperature, top_p, seed, logprobs, frequency_penalty).
Related posts
- Inference for PROs
Hugging Face mediumAdeptHugging Face PRO subscribers get curated, rate-limit-boosted HTTP inference endpoints served by text-generation-inference for models such as Llama 3, Mixtral 8x7B, Zephyr, Code Llama, Stable Diffusion XL and Bark, intended for prototyping rather than heavy production (Inference Endpoints is recommended for that). Usage is shown via curl, the huggingface_hub InferenceClient and the OpenAI-compatible Messages API, including Llama 2 chat templates and Code Llama's <PRE>/<SUF>/<MID> infilling format. Generation parameters (do_sample, temperature, top_k, top_p, repetition_penalty, max_new_tokens, stop_sequences, SDXL guidance and steps) are explained, along with disabling response caching via the x-use-cache: 0 header and token streaming.
- Hugging Face x LangChain : A new partner package
Hugging Face mediumAdeptlangchain-huggingface is a new Python partner package jointly maintained by Hugging Face and LangChain, replacing community-written integrations that had drifted out of date. It provides HuggingFacePipeline for running transformers models locally, HuggingFaceEndpoint for the serverless Inference API or deployed TGI endpoints via InferenceClient, and ChatHuggingFace, which turns message lists into model-specific prompts with tokenizer.apply_chat_template. For embeddings it offers HuggingFaceEmbeddings (local sentence-transformers) and HuggingFaceEndpointEmbeddings (Hub or TEI instances), each shown with short code examples.
- Deploy LLMs with Hugging Face Inference Endpoints
Hugging Face mediumAdeptFalcon 40B Instruct can be deployed to Hugging Face Inference Endpoints through the web UI by choosing a repository, cloud, region and instance. For best performance the suggested 4x T4 instance should be switched to a single A100. Once the endpoint is live it can be called with cURL, and generation is controlled through parameters such as temperature, max_new_tokens (max 512), top_k/top_p, repetition_penalty and stop sequences. Tokens can be streamed to clients using huggingface_hub's InferenceClient in Python or HfInferenceEndpoint from @huggingface/inference in JavaScript, with code that skips special tokens and stops on stop sequences.
- Tool Use, Unified
Hugging Face mediumAdeptHugging Face Transformers extends Jinja chat templates to cover tool use, giving a single portable API for passing tools to Mistral, Cohere, NousResearch and Llama models. Tools are defined as JSON schema, or as Python functions whose type hints and docstrings are converted automatically via get_json_schema. Tool calls go into the chat as a tool_calls field on assistant messages, and results are added as separate tool-role messages. A full walkthrough with Hermes-2-Pro-Llama-3-8B shows the loop end to end. Parsing the model's emitted tool-call text is still model-specific and needs a little json.loads or regex work.
- Local LLM Messenger: Chat with GenAI on Your iPhone
Docker mediumAdeptLocal LLM Messenger (LoLLMM), an honorable-mention project from Docker's AI/ML Hackathon by Justin Garrison, lets you send iMessages to LLMs running on your own machine. A FastAPI Python app receives Sendblue webhooks, routes prompts to local Ollama models (defaulting to llama2) or optionally OpenAI's GPT-3.5 Turbo and DALL-E 2, keeps conversation context in a file, and supports slash commands for switching models. Docker Compose runs the app, an ngrok tunnel exposing port 8000, and an Ollama container with optional NVIDIA GPU access. A setup walkthrough covers cloning the repo, configuring API keys in .env, and adding the ngrok authtoken.