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

Fix issue where hugging face response was not correct type #769

Merged
merged 1 commit into from
Jan 5, 2024
Merged

Conversation

rossdanlm
Copy link
Contributor

@rossdanlm rossdanlm commented Jan 5, 2024

Fix issue where hugging face response was not correct type

Turned out to be a typing issue that python did not actually help with.

I also had to adjust the way we load in hugging face key because I got rate limited. We NEED to have more clear way to set API keys in aiconfig/.env file though, or else people won't know how to use it! cc @tanya-rai let's add an FAQ/README similar to what we have in the cookbooks:

"# Create .env file at aiconfig/.env containing the following line:\n",
"# OPENAI_API_KEY=<your key here>\n",
"# You can get your key from https://platform.openai.com/api-keys \n",

We need to do this for keys

  • HUGGING_FACE_API_TOKEN
  • ANYSCALE_ENDPOINT_API_KEY
  • OPENAI_API_KEY
  • GOOGLE_API_KEY

Testing

Connected to local editor (you'll have to modify the max_tokens setting) and runs now. We should also have automated testing for this hugging face model parser. Created task for it in #768

Screenshot 2024-01-05 at 00 47 51

@rossdanlm rossdanlm force-pushed the pr769 branch 2 times, most recently from e356f92 to 5d07265 Compare January 5, 2024 06:09
@rossdanlm rossdanlm marked this pull request as ready for review January 5, 2024 06:10
rossdanlm pushed a commit that referenced this pull request Jan 5, 2024
Sometimes key is not defined or set, we need to do this to unblock #769

The functionality is still unchanged because the optional param `required` defaults to true

## Test Plan
Pass all automated tests (which it didn't before)
rossdanlm pushed a commit that referenced this pull request Jan 5, 2024
Sometimes key is not defined or set, we need to do this to unblock #769

The functionality is still unchanged because the optional param `required` defaults to true

## Test Plan
Pass all automated tests (which it didn't before)
rossdanlm pushed a commit that referenced this pull request Jan 5, 2024
Sometimes key is not defined or set, we need to do this to unblock #769

The functionality is still unchanged because the optional param `required` defaults to true

## Test Plan
Pass all automated tests (which it didn't before)
Copy link
Contributor

@rholinshead rholinshead left a comment

Choose a reason for hiding this comment

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

Nice, thanks for fixing

token = maybe_get_api_key_from_environment("HUGGING_FACE_API_TOKEN")
# You are allowed to use Hugging Face for a bit before you get
# rate limited, in which case you will receive a clear error
token = maybe_get_api_key_from_environment("HUGGING_FACE_API_TOKEN", required=False)
Copy link
Contributor

Choose a reason for hiding this comment

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

why is required=False?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I left a comment, but it's because Hugging Face allows you to use their API for a bit before you get rate-limited. When you get rate limited, we get a very clear error from Hugging Face saying to login and use an API key

@@ -120,7 +120,7 @@ class HuggingFaceTextGenerationParser(ParameterizedModelParser):
A model parser for HuggingFace text generation models.
"""

def __init__(self, model_id: str = None, use_api_token=False):
def __init__(self, model_id: str = None, use_api_token=True):
Copy link
Contributor

Choose a reason for hiding this comment

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

Why was this false before and why is it set to True now?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

It's because after using it for a bit, you end up getting rate-limited, so this needs to be true so that you can by default fetch your API key

rossdanlm pushed a commit that referenced this pull request Jan 5, 2024
Sometimes key is not defined or set, we need to do this to unblock #769

The functionality is still unchanged because the optional param `required` defaults to true

## Test Plan
Pass all automated tests (which it didn't before)
@rossdanlm rossdanlm force-pushed the pr769 branch 2 times, most recently from 364c209 to 5055bec Compare January 5, 2024 22:43
rossdanlm added a commit that referenced this pull request Jan 5, 2024
Make `get_api_key_from_environment` return nullable


Sometimes key is not defined or set, we need to do this to unblock
#769

The functionality is still unchanged because the optional param
`required` defaults to true

## Test Plan
Pass all automated tests (which it didn't before)

---
Stack created with [Sapling](https://sapling-scm.com). Best reviewed
with
[ReviewStack](https://reviewstack.dev/lastmile-ai/aiconfig/pull/772).
* #769
* __->__ #772
Turned out to be a typing issue that python did not actually help with.

I also had to adjust the way we load in hugging face key because I got rate limited. We NEED to have more clear way to set API keys in `aiconfig/.env` file though, or else people won't know how to use it! cc @tanya-rai let's add an FAQ/README similar to what we have in the cookbooks: https://github.com/lastmile-ai/aiconfig/blob/3dcf70bcddda7f7041c3bfb6e5d4b6c9a7abd4ab/cookbooks/Getting-Started/getting_started.ipynb?short_path=dcb1340#L23-L25

We need to do this for keys
- HUGGING_FACE_API_TOKEN
- ANYSCALE_ENDPOINT_API_KEY
- OPENAI_API_KEY
- GOOGLE_API_KEY


## Testing
Connected to local editor (you'll have to modify the `max_tokens` setting) and runs now. We should also have automated testing for this hugging face model parser. Created task for it in #768

<img width="1512" alt="Screenshot 2024-01-05 at 00 47 51" src="https://github.com/lastmile-ai/aiconfig/assets/151060367/5ecae48a-c0cd-43cf-a7ed-ccc74929c6b3">
@rossdanlm rossdanlm merged commit a50fa41 into main Jan 5, 2024
2 checks passed
@rossdanlm rossdanlm deleted the pr769 branch January 5, 2024 23:20
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.

3 participants