Я пытаюсь использовать интеграцию langchain_huggingface.HuggingFaceEndpoint для вызова модели «google/flan-t5-large» из Hugging Face в конвейере LangChain. Вот мой код:
from langchain.prompts import PromptTemplate
from langchain_huggingface import HuggingFaceEndpoint
from langchain_core.runnables import RunnableSequence
import os
# Set your API token
os.environ['HUGGINGFACEHUB_API_TOKEN'] = 'hf_***************'
# Initialize the updated Hugging Face model
flan_t5 = HuggingFaceEndpoint(
repo_id="google/flan-t5-large",
temperature=1e-10,
task="text2text-generation"
)
# Define the prompt template
template = "Translate the following to French:\n\n{question}"
prompt = PromptTemplate(template=template, input_variables=["question"])
# Create the RunnableSequence chain
chain = prompt | flan_t5
# Run the chain with input
question = "Hello"
response = chain.invoke({"question": question})
print("Output:", response)
/usr/local/lib/python3.11/dist-packages/huggingface_hub/inference/_providers/__init__.py in get_provider_helper(provider, task, model)
189 raise ValueError("Specifying a model is required when provider is 'auto'")
190 provider_mapping = _fetch_inference_provider_mapping(model)
--> 191 provider = next(iter(provider_mapping)).provider
StopIteration
Что я пробовал:
Проверил, что мой токен Hugging Face действителен.
Проверил, что «google/flan-t5-large» существует и поддерживает генерацию text2text.
Проверил другие идентификаторы репозитория (например, google/flan-t5-xl), но столкнулся с та же проблема.
Вопрос:
Почему я получаю эту ошибку StopIteration и как ее исправить?
Что-то не так с тем, как я инициализирую HuggingFaceEndpoint или с тем, как определяется поставщик?
Я пытаюсь использовать интеграцию langchain_huggingface.HuggingFaceEndpoint для вызова модели «google/flan-t5-large» из Hugging Face в конвейере LangChain. Вот мой код: [code]from langchain.prompts import PromptTemplate from langchain_huggingface import HuggingFaceEndpoint from langchain_core.runnables import RunnableSequence import os
# Set your API token os.environ['HUGGINGFACEHUB_API_TOKEN'] = 'hf_***************'
# Initialize the updated Hugging Face model flan_t5 = HuggingFaceEndpoint( repo_id="google/flan-t5-large", temperature=1e-10, task="text2text-generation" )
# Define the prompt template template = "Translate the following to French:\n\n{question}" prompt = PromptTemplate(template=template, input_variables=["question"])
# Create the RunnableSequence chain chain = prompt | flan_t5
# Run the chain with input question = "Hello" response = chain.invoke({"question": question})
print("Output:", response) [/code] Однако я получаю следующую ошибку: [code]/usr/local/lib/python3.11/dist-packages/huggingface_hub/inference/_providers/__init__.py in get_provider_helper(provider, task, model) 189 raise ValueError("Specifying a model is required when provider is 'auto'") 190 provider_mapping = _fetch_inference_provider_mapping(model) --> 191 provider = next(iter(provider_mapping)).provider StopIteration [/code] [b]Что я пробовал:[/b] [list] [*]Проверил, что мой токен Hugging Face действителен. [*]Проверил, что «google/flan-t5-large» существует и поддерживает генерацию text2text. [*]Проверил другие идентификаторы репозитория (например, google/flan-t5-xl), но столкнулся с та же проблема. [/list] [b]Вопрос:[/b] [list] [*]Почему я получаю эту ошибку StopIteration и как ее исправить? [*]Что-то не так с тем, как я инициализирую HuggingFaceEndpoint или с тем, как определяется поставщик? [/list]