8000 docs: Add Llama class example · chiensen/llama-cpp-python@b6bb7ac · GitHub
[go: up one dir, main page]

Skip to content

Commit b6bb7ac

Browse files
committed
docs: Add Llama class example
1 parent c5173b0 commit b6bb7ac

File tree

1 file changed

+24
-0
lines changed

1 file changed

+24
-0
lines changed

llama_cpp/llama.py

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -765,6 +765,30 @@ def __init__(
765765
**kwargs, # type: ignore
766766
):
767767
"""Load a llama.cpp model from `model_path`.
768+
769+
Examples:
770+
Basic usage
771+
772+
>>> import llama_cpp
773+
>>> model = llama_cpp.Llama(
774+
... model_path="path/to/model",
775+
... )
776+
>>> print(model("The quick brown fox jumps ", stop=["."])["choices"][0]["text"])
777+
the lazy dog
778+
779+
Loading a chat model
780+
781+
>>> import llama_cpp
782+
>>> model = llama_cpp.Llama(
783+
... model_path="path/to/model",
784+
... chat_format="llama-2",
785+
... )
786+
>>> print(model.create_chat_completion(
787+
... messages=[{
788+
... "role": "user",
789+
... "content": "what is the meaning of life?"
790+
... }]
791+
... ))
768792
769793
Args:
770794
model_path: Path to the model.

0 commit comments

Comments
 (0)
0