srush / MiniChain

A tiny library for coding with large language models.
https://srush-minichain.hf.space/
MIT License
1.19k stars 73 forks source link

How to use with a hugging Face Model ? #19

Open Layt0n opened 1 year ago

Layt0n commented 1 year ago

Hello, I like your library but i can't understand how to use a different model than OpenAI's one. I'm interested in particular in using HF models.

ishaan-jaff commented 9 months ago

Hi @Layt0n I’m the maintainer of LiteLLM (abstraction to call 100+ LLMs)- we allow you to create a proxy server to call 100+ LLMs, and I think it can solve your problem (I'd love your feedback if it does not)

Try it here: https://docs.litellm.ai/docs/proxy_server https://github.com/BerriAI/litellm

Using LiteLLM Proxy Server

import openai
openai.api_base = "http://0.0.0.0:8000/" # proxy url
print(openai.ChatCompletion.create(model="test", messages=[{"role":"user", "content":"Hey!"}]))

Creating a proxy server

Ollama models

$ litellm --model ollama/llama2 --api_base http://localhost:11434

Hugging Face Models

$ export HUGGINGFACE_API_KEY=my-api-key #[OPTIONAL]
$ litellm --model claude-instant-1

Anthropic

$ export ANTHROPIC_API_KEY=my-api-key
$ litellm --model claude-instant-1

Palm

$ export PALM_API_KEY=my-palm-key
$ litellm --model palm/chat-bison