mirror of
https://github.com/hwchase17/langchain.git
synced 2026-06-09 10:17:00 +00:00
@@ -326,7 +326,8 @@ class ChatHuggingFace(BaseChatModel):
|
||||
.. code-block:: python
|
||||
|
||||
from huggingface_hub import login
|
||||
login() # You will be prompted for your HF key, which will then be saved locally
|
||||
|
||||
login() # You will be prompted for your HF key, which will then be saved locally
|
||||
|
||||
Key init args — completion params:
|
||||
llm: `HuggingFaceTextGenInference`, `HuggingFaceEndpoint`, `HuggingFaceHub`, or
|
||||
@@ -447,9 +448,13 @@ class ChatHuggingFace(BaseChatModel):
|
||||
|
||||
.. code-block:: python
|
||||
|
||||
[{'name': 'GetPopulation',
|
||||
'args': {'location': 'Los Angeles, CA'},
|
||||
'id': '0'}]
|
||||
[
|
||||
{
|
||||
"name": "GetPopulation",
|
||||
"args": {"location": "Los Angeles, CA"},
|
||||
"id": "0",
|
||||
}
|
||||
]
|
||||
|
||||
Response metadata
|
||||
.. code-block:: python
|
||||
@@ -458,10 +463,13 @@ class ChatHuggingFace(BaseChatModel):
|
||||
ai_msg.response_metadata
|
||||
|
||||
.. code-block:: python
|
||||
{'token_usage': ChatCompletionOutputUsage(completion_tokens=100,
|
||||
prompt_tokens=8, total_tokens=108),
|
||||
'model': '',
|
||||
'finish_reason': 'length'}
|
||||
{
|
||||
"token_usage": ChatCompletionOutputUsage(
|
||||
completion_tokens=100, prompt_tokens=8, total_tokens=108
|
||||
),
|
||||
"model": "",
|
||||
"finish_reason": "length",
|
||||
}
|
||||
|
||||
""" # noqa: E501
|
||||
|
||||
|
||||
@@ -28,12 +28,12 @@ class HuggingFaceEmbeddings(BaseModel, Embeddings):
|
||||
from langchain_huggingface import HuggingFaceEmbeddings
|
||||
|
||||
model_name = "sentence-transformers/all-mpnet-base-v2"
|
||||
model_kwargs = {'device': 'cpu'}
|
||||
encode_kwargs = {'normalize_embeddings': False}
|
||||
model_kwargs = {"device": "cpu"}
|
||||
encode_kwargs = {"normalize_embeddings": False}
|
||||
hf = HuggingFaceEmbeddings(
|
||||
model_name=model_name,
|
||||
model_kwargs=model_kwargs,
|
||||
encode_kwargs=encode_kwargs
|
||||
encode_kwargs=encode_kwargs,
|
||||
)
|
||||
|
||||
"""
|
||||
|
||||
@@ -23,6 +23,7 @@ class HuggingFaceEndpointEmbeddings(BaseModel, Embeddings):
|
||||
.. code-block:: python
|
||||
|
||||
from langchain_huggingface import HuggingFaceEndpointEmbeddings
|
||||
|
||||
model = "sentence-transformers/all-mpnet-base-v2"
|
||||
hf = HuggingFaceEndpointEmbeddings(
|
||||
model=model,
|
||||
|
||||
@@ -45,7 +45,7 @@ class HuggingFaceEndpoint(LLM):
|
||||
typical_p=0.95,
|
||||
temperature=0.01,
|
||||
repetition_penalty=1.03,
|
||||
huggingfacehub_api_token="my-api-key"
|
||||
huggingfacehub_api_token="my-api-key",
|
||||
)
|
||||
print(llm.invoke("What is Deep Learning?"))
|
||||
|
||||
@@ -63,7 +63,7 @@ class HuggingFaceEndpoint(LLM):
|
||||
repetition_penalty=1.03,
|
||||
callbacks=callbacks,
|
||||
streaming=True,
|
||||
huggingfacehub_api_token="my-api-key"
|
||||
huggingfacehub_api_token="my-api-key",
|
||||
)
|
||||
print(llm.invoke("What is Deep Learning?"))
|
||||
|
||||
@@ -73,7 +73,7 @@ class HuggingFaceEndpoint(LLM):
|
||||
provider="novita",
|
||||
max_new_tokens=100,
|
||||
do_sample=False,
|
||||
huggingfacehub_api_token="my-api-key"
|
||||
huggingfacehub_api_token="my-api-key",
|
||||
)
|
||||
print(llm.invoke("What is Deep Learning?"))
|
||||
|
||||
|
||||
@@ -61,7 +61,10 @@ class HuggingFacePipeline(BaseLLM):
|
||||
tokenizer = AutoTokenizer.from_pretrained(model_id)
|
||||
model = AutoModelForCausalLM.from_pretrained(model_id)
|
||||
pipe = pipeline(
|
||||
"text-generation", model=model, tokenizer=tokenizer, max_new_tokens=10
|
||||
"text-generation",
|
||||
model=model,
|
||||
tokenizer=tokenizer,
|
||||
max_new_tokens=10,
|
||||
)
|
||||
hf = HuggingFacePipeline(pipeline=pipe)
|
||||
|
||||
|
||||
Reference in New Issue
Block a user