Skip to content

feat: Pull models directly from huggingface#1206

Merged
abetlen merged 3 commits into
mainfrom
add-hf-pull
Feb 21, 2024
Merged

feat: Pull models directly from huggingface#1206
abetlen merged 3 commits into
mainfrom
add-hf-pull

Conversation

@abetlen

@abetlen abetlen commented Feb 21, 2024

Copy link
Copy Markdown
Owner

Adds the ability to pull models directly from huggingface hub via a from_pretrained method on the Llama class. You'll need to pip install huggingface-hub to use this feature.

Usage

import llama_cpp

llama = llama_cpp.Llama.from_pretrained(
    repo_id="Qwen/Qwen1.5-0.5B-Chat-GGUF",
    filename="*q8_0.gguf",
    verbose=False
)

response = llama.create_chat_completion(
    messages=[
        {
            "role": "user",
            "content": "What is the capital of France?"
        }
    ],
    response_format={
        "type": "json_object",
        "schema": {
            "type": "object",
            "properties": {
                "country": {"type": "string"},
                "capital": {"type": "string"}
            },
            "required": ["country", "capital"],
        }
    },
    stream=True
)

for chunk in response:
    delta = chunk["choices"][0]["delta"]
    if "content" not in delta:
        continue
    print(delta["content"], end="", flush=True)

print()

Closes #1145

@abetlen abetlen merged commit 0f8aa4a into main Feb 21, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Automatically pull models from Huggingface

1 participant