Skip to content

Commit

Permalink
Merge pull request #926 from robinroy03/gsoc_9_10_11
Browse files Browse the repository at this point in the history
DOC: GSoC Blogs 9, 10, 11, 12
  • Loading branch information
skoudoro authored Aug 23, 2024
2 parents 5fce9b0 + cc3a199 commit f7d8d5b
Show file tree
Hide file tree
Showing 5 changed files with 218 additions and 0 deletions.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
63 changes: 63 additions & 0 deletions docs/source/posts/2024/2024-08-15_week9.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
Week 9: Hosting FineTuned Models
================================

.. post:: Aug 15 2024
:author: Robin Roy
:tags: google
:category: gsoc

Hi, I'm `Robin <https://github.com/robinroy03>`_ and this is my blog about week 9.

This week I worked on hosting the Finetuned model as an API and started work on GitHub GraphQL.

Things I did in Week 9
----------------------

1) **Hosting the fine-tuned API**

Last week we fine-tuned the Gemini model, but it didn't have an endpoint which we could use to connect with Discord/other frontend applications. I thought it would be a simple task until I realized it wasn't. Some features are still in beta phase, like this one :)

Fine-tuned models need more permissions to be used under an API, cause it is your data (as per Google policy). Google Gemini API provides only 1 way to achieve this right now, and that is by using a short-lived token. Short-lived tokens can't be used on a server cause we'll have to rotate it, and to rotate them I'll need to sign in to my Google account every time, and I can't program it.

The way we generally solve this is by using a token with no expiry - but the Gemini API does not support that. I tried making service accounts to bypass expiry but it was all failing. The documentation does not mention anywhere how to fix this issue either.

After a lot of googling, I ended up checking the `Google Gemini Cookbook repo <https://github.com/google-gemini/cookbook/>`_, here we have a notebook which talks about this problem! I was so happy seeing `this Authentication_with_OAuth.ipynb file <https://github.com/google-gemini/cookbook/blob/main/quickstarts/Authentication_with_OAuth.ipynb>`_. The solution is to essentially add permission to the fine-tuned model through a REST call. There is no UI/SDK way to do this. You'll have to trigger a certain REST endpoint to update the permissions to "EVERYONE" so anyone can access the fine-tuned model. For FURY it's fine since FURY does not contain any sensitive information.

So right now our workflow is as follows:
- Fine-tune a model on Google AI Studio.
- Update model permissions using a separate script.
- Call through the FURY-Engine API as usual.


2) **GraphQL work**

The next thing I did was start working on GitHub integration. The Discord Bot is hosted and stable, now it was time to do the same with GitHub. For GitHub, the aim is to use the LLM to give a first response to discussions posts. GitHub uses GraphQL instead of REST APIs.

If you do not know GraphQL you can learn about it in detail from `this YouTube playlist <https://www.youtube.com/playlist?list=PL4cUxeGkcC9gUxtblNUahcsg0WLxmrK_y>`_ and later from the `official docs <https://graphql.org/>`_. But I'll give you a quick explanation anyway since I think the playlist and docs miss this part:

GraphQL is essentially HTTP POST/GET calls. We'll avoid all the jargon here and talk from first principles. REST API philosophy is to provide multiple endpoints `/google`, `/groq`, etc (these are FURY-engine endpoints). They do different things. Now these are just styles, remember that. At the end of the day you're still sending network packets to the server, these just dictate which URL you send it to and what data it contains.

GraphQL is different in the sense it does not have multiple endpoints. There's only one endpoint (example: https://api.github.com/graphql for GitHub). We send all our requests to this endpoint and then the server uses it to do an action and return results. So you may ask "Why" do we need to follow the GraphQL syntax, why not just modify REST API to follow our custom style? You can do that. GraphQL is just a style of doing things that smart people at Meta decided to standardize.

The reason people use GraphQL is because it reduces the number of queries required. You can read the docs to see example GraphQL queries, it is compact and you can easily get a lot of information with one single call. Different people have different opinions about how to make and consume APIs. But fundamentally it's just another layer of abstraction.

What is coming up next week?
----------------------------

- Work on GitHub App.


Did you get stuck anywhere?
---------------------------

I was stuck with the Gemini API part but it was fixed. It was also a learning experience to not trust documentation always :)


LINKS:

- `Google Gemini Cookbook repo <https://github.com/google-gemini/cookbook/>`_
- `Authentication_with_OAuth.ipynb file <https://github.com/google-gemini/cookbook/blob/main/quickstarts/Authentication_with_OAuth.ipynb>`_
- `GraphQL YouTube playlist <https://www.youtube.com/playlist?list=PL4cUxeGkcC9gUxtblNUahcsg0WLxmrK_y>`_
- `GraphQL official docs <https://graphql.org/>`_

Thank you for reading!
39 changes: 39 additions & 0 deletions docs/source/posts/2024/2024-08-16_week10.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
Week 10: Learning GraphQL
=========================

.. post:: Aug 16 2024
:author: Robin Roy
:tags: google
:category: gsoc

Hi, I'm `Robin <https://github.com/robinroy03>`_ and this is my blog about week 10.

This week I worked on the GitHub GraphQL implementation. I tested out things and was learning GraphQL properly since I have never used it before.


**Learning and testing GraphQL**

I spent time learning and implementing prototypes of the GitHub app. Initially, I tested using `GitHub Explorer <https://docs.github.com/en/graphql/overview/explorer>`_ to control my account. I initially spent some time searching for other GitHub libraries but later gave up and made my custom scripts. There are no Python GraphQL libraries available, and the ones available do not integrate with Discussion tabs.

I used Explorer to mainly focus only on the query language, and not on implementation. The plan was to use a GitHub app to send webhooks to the HuggingFace server, which will respond to it.

We use ``query`` to fetch discussions and ``mutation`` to send a reply. They are GraphQL operations.


What is coming up next week?
----------------------------

- Working GitHub App


Did you get stuck anywhere?
---------------------------

No, I did not get stuck anywhere. I was learning new things and experimenting with stuff.


LINKS:

- `GitHub Explorer <https://docs.github.com/en/graphql/overview/explorer>`_

Thank you for reading!
63 changes: 63 additions & 0 deletions docs/source/posts/2024/2024-08-17_week_11.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
Week 11: Getting the App Live
=============================

.. post:: Aug 17 2024
:author: Robin Roy
:tags: google
:category: gsoc

Hi, I'm `Robin <https://github.com/robinroy03>`_ and this is my blog about week 11.

This week I worked on Getting the GitHub App live.


**Getting the App Live**

Last week I prototyped and got to know the language and the API. But I can't use my account as an automated bot account. So it was required to make a GitHub App. The architecture for it is as follows:

- Make a GitHub App to listen to Discussion posts
- Send a webhook to https://robinroy03-github-bot.hf.space/github whenever any change happens.
- Respond to the webhook as required.

I was told by `Serge <https://github.com/skoudoro>`_ to try and fit the endpoint inside the Discord Bot script. I tried but it was weird so I left it. The Discord Bot is set up using threading which is a hack (although it is how every discord bot is set up in HuggingFace). Placing it inside any other repository won't be good so I ended up making another new repository.

I faced an issue while trying to get the app live. I had another documentation rabbit hole situation. So what ended up happening was I was unable to authenticate myself with the GitHub app to send commands. To command an app you have to authenticate as a `GitHub App Installation`. To authenticate as an App installation, you need 3 key things:

- Installation ID
- App ID
- Private Key of the App

You use the ``App ID`` and ``Private Key`` to make a ``JWT``. You use the ``JWT`` with ``Installation ID`` to make an ``Installation Access Token``. You'll now use this ``Installation Access Token`` to authorize you and then send commands to the GitHub App. The ``Access Token`` will expire after 1 hour, so we'll have to regenerate it.

The problem was that the documentation didn't mention how to generate ``Installation Access Token`` and it kept confusing everyone with ``Installation ID``. Even the names were misleading, since it isn't an ``Installation Token`` in the real sense cause it is already installed. I ended up fixing it by landing at `this StackOverflow Post <https://stackoverflow.com/questions/77325437/how-do-i-get-an-github-app-installation-token-to-authenticate-cloning-a-reposito>`_ which took me to this `Discussions Post <https://github.com/orgs/community/discussions/48186>`_. I think the majority uses `Octokit.js SDK` to generate Access Tokens and regenerate JWTs. Sadly Python has no library so we had to go all manual.

So I ended up sending a PR to GitHub Docs :)

- Issue: https://github.com/github/docs/issues/34258
- PR: https://github.com/github/docs/pull/34259


You can test the GitHub App today! Checkout https://github.com/robinroy03/FURY-data-script/discussions


What is coming up next week?
----------------------------

- Week 12 :) I'll be finalizing stuff.
- Make the GitHub App respond to mentions.


Did you get stuck anywhere?
---------------------------

Was stuck with the documentation but got it fixed.


LINKS:

- `StackOverflow Post <https://stackoverflow.com/questions/77325437/how-do-i-get-an-github-app-installation-token-to-authenticate-cloning-a-reposito>`_
- `Discussions Post <https://github.com/orgs/community/discussions/48186>`_
- https://github.com/github/docs/issues/34258
- https://github.com/github/docs/pull/34259

Thank you for reading!
53 changes: 53 additions & 0 deletions docs/source/posts/2024/2024-08-20_week_12.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
Week 12: Wrapping things up
===========================

.. post:: Aug 20 2024
:author: Robin Roy
:tags: google
:category: gsoc

Hi, I'm `Robin <https://github.com/robinroy03>`_ and this is my blog about week 12.

As the final official week, I spent my time wrapping things up and also improving the UX of the GitHub Application.

Things I did in Week 12
-----------------------

1) **Improving GitHub App UX**

Previously the bot responded to every discussion post. It was not a good approach and we tried stuff like @mentions. The problem is GitHub does not support bot mentions natively. Actually `Serge <https://github.com/skoudoro/>`_ had a better approach that is using Discussion Templates. I integrated that. Right now, you have a checkbox that you can tick to get the LLM answer as the first response.

The new UI looks like this:

.. image:: /_static/images/robin_gsoc_FURY_DISCUSSIONS_TEMPLATE.jpg
:alt: Present GitHub Discussions Template


2) **Documentation**

Some of the API endpoints had no documentation, the documentation work is still ongoing. But I worked on adding basic info like how to test locally and stuff. It was added directly to the README.md files. I'll also make a separate GitHub Gists where I'll detail all the components and how they integrate with each other.

3) **API testing**

I plan to have testing for every endpoint. Testing includes the following:

- Check the endpoints with valid data to see the response. Validate the JSON format.
- Check the endpoints with incorrect schema and record the response.
- Test by adjusting parameters like KNN.

Testing will be a separate file, it'll be production testing. We'll hit the live endpoints directly.


What is coming up next week?
----------------------------

I'm working on the final report. Also, I'm working on finishing testing, documentation and updating the LLM response. The plan is to use a Re-Ranker to rerank the KNN references and filter ones not in context.


Did you get stuck anywhere?
---------------------------

No, I did not get stuck. I was having some health issues this week so was unable to make a lot of progress. But the general plan is prepared, and now I'll have to compile everything.


Thank you for reading!

0 comments on commit f7d8d5b

Please sign in to comment.