Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Harrison/add huggingface hub #23

Merged
merged 5 commits into from Oct 26, 2022
Merged

Harrison/add huggingface hub #23

merged 5 commits into from Oct 26, 2022

Conversation

hwchase17
Copy link
Contributor

Add support for huggingface hub

I could not find a good way to enforce stop tokens over the huggingface hub api - that needs to hopefully be cleaned up in the future

@hinthornw hinthornw self-requested a review October 26, 2022 04:12
langchain/llms/huggingface_hub.py Outdated Show resolved Hide resolved
repo_id = values.get("repo_id", DEFAULT_REPO_ID)
values["client"] = InferenceApi(
repo_id=repo_id,
token=os.environ["HUGGINGFACEHUB_API_TOKEN"],
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These parameters seem like nice ones to include as init args with optional env args as backups.

Also the relationship feels a bit convoluted at first glance

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

what in particular seems convoluted?

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think the main thing is that the client is created in a validation function - but that seems out of scope of this PR given the existing structure

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ah yeah i agree. is a bit weird. may look into post_init

if "error" in response:
raise ValueError(f"Error raised by inference API: {response['error']}")
text = response[0]["generated_text"][len(prompt) :]
if stop is not None:
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could we share this across models?

Yeah it's a bit hacky but I don't see better support via InferenceAPI and ultimately it just ends with a bit of wasted computation

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

what do you mean by share across models? its already factored out and used in cohere as well (cohere is a bit different - you can pass stop words but they are included at the end of the prompt)

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah this is sufficient - not enough examples to merit more

from typing import List


def enforce_stop_tokens(text: str, stop: List[str]) -> str:
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Double checking - the prompt isn't returned as part of the generated text, right?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

no it shouldnt be

@hwchase17 hwchase17 merged commit 020c42d into master Oct 26, 2022
@hwchase17 hwchase17 deleted the harrison/add_huggingface branch October 26, 2022 05:00
dashesy added a commit to dashesy/langchain that referenced this pull request May 8, 2023
Prince-Mendiratta pushed a commit to Prince-Mendiratta/langchain that referenced this pull request Oct 17, 2023
…lback_docs

Update examples to use inheritable callbacks
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.

None yet

2 participants