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

Mercelisvaughan model 1 #2

Closed
wants to merge 17 commits into from
Closed

Conversation

mercelisvaughan
Copy link
Collaborator

This is a pull request for the sample. This pull request is

  • Adding unit tests for the RevertRiskAPIModel class.
  • Fixing a bug in the request_to_revertRiskAPI method. (I still have to get the bug, I return a 404 for some reason, I need to return 200 and the response)

@mercelisvaughan mercelisvaughan changed the base branch from main to mercelisvaughan-patch-1 April 15, 2024 23:16
Copy link
Collaborator

@isaranto isaranto left a comment

Choose a reason for hiding this comment

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

Nice work getting started! You can add a more descriptive Pull request title. This will end up being a commit in our git history so it is good to have a title that makes sense when looking at commands like git log

Comment on lines 9 to 11
# this method will make a request and return a json response
#return response.json()
return ""
Copy link
Collaborator

Choose a reason for hiding this comment

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

If we create an abstract class we can just issue a pass directive.

Suggested change
# this method will make a request and return a json response
#return response.json()
return ""
pass

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

I completed the method

@@ -4,3 +4,43 @@
This is a Python package that acts as a client and allows users to make requests to the LiftWing API.
Its purpose is to allow users to interact with the API by writing python code instead of manipulating HTTP requests.

Below is an example of how to make a request. This specific request is being made to the revert_risk API
Copy link
Collaborator

Choose a reason for hiding this comment

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

We should remove the code from the README file as this file serves as our basic documentation. A user might only be interested on how to use the package rather than deep dive from the start on what is does behind the hood.

After we publish the package we can include an example of how to use it.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

I have removed the code

from liftwing_model import LiftwingModel

class RevertRiskAPIModel(LiftwingModel):
def __init__(self, base_url="https://api.wikimedia.org/service/lw/inference/v1/models/{language}-reverted:predict"):
Copy link
Collaborator

Choose a reason for hiding this comment

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

This is not the url for the revertrisk model

"https://api.wikimedia.org/service/lw/inference/v1/models/{language}-reverted:predict"

This is the link to the relevant documentation for the revertrisk language agnostic model
https://api.wikimedia.org/wiki/Lift_Wing_API/Reference/Get_reverted_risk_language_agnostic_prediction

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

corrected the url

import json
from liftwing_model import LiftwingModel

class RevertRiskAPIModel(LiftwingModel):
Copy link
Collaborator

Choose a reason for hiding this comment

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

It is a good idea to keep only as base url the first part of the string
https://api.wikimedia.org/service/lw/inference/v1/models/
and the latter part will be the one specific to the model and can be hardcoded for now.

from liftwing_model import LiftwingModel

class RevertRiskAPIModel(LiftwingModel):
def __init__(self, base_url="https://api.wikimedia.org/service/lw/inference/v1/models/{language}-reverted:predict"):
Copy link
Collaborator

Choose a reason for hiding this comment

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

It is a good idea to keep only as base url the first part of the string
https://api.wikimedia.org/service/lw/inference/v1/models/
and the latter part will be the one specific to the model and can be hardcoded for now like this:

self.model_name = "revertrisk-language-agnostic"
self.url = f"{base_url}{self.model_name}:predict"

@@ -0,0 +1,12 @@
import requests

class LiftwingModel:
Copy link
Collaborator

Choose a reason for hiding this comment

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

This can be an abstract class and the request method can be an abstractmethod that has the following arguments:

  • payload : dict
  • method :str ="POST"
  • headers : dict

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

lets talk about the methods I added

@isaranto isaranto changed the base branch from mercelisvaughan-patch-1 to main April 25, 2024 13:21
@isaranto isaranto changed the base branch from main to mercelisvaughan-patch-1 April 25, 2024 13:22
@isaranto isaranto changed the base branch from mercelisvaughan-patch-1 to main April 25, 2024 13:22
@@ -0,0 +1,5 @@
{
Copy link
Collaborator

Choose a reason for hiding this comment

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

This file should be deleted. Since we added it in the .gitignore fiel it also won't be committed automatically in the future

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

deleted

pyproject.toml Outdated
@@ -0,0 +1,12 @@
[tool.poetry]
Copy link
Collaborator

Choose a reason for hiding this comment

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

This configuration for poetry is incomplete and throws an error when trying to run pip install -e .

        File "/private/var/folders/0d/x7f69d5s525d0pn0gp8cyrzr0000gn/T/pip-build-env-46zwyrnz/overlay/lib/python3.11/site-packages/poetry/core/factory.py", line 60, in create_poetry
          raise RuntimeError("The Poetry configuration is invalid:\n" + message)
      RuntimeError: The Poetry configuration is invalid:
        - The fields ['authors'] are required in package mode.

      [end of output]

However I would suggest to use the more generic [project] section instead of the poetry specific ones as described in the documentation (related PEP documentation)
It seems to be a future proof standard for python and poetry is going to adopt that as well as seen in its roadmap (related poetry PR).
Let me know if you need any help on this!

dependencies = [
"requests",
]
dynamic = ["version"]
Copy link
Collaborator

Choose a reason for hiding this comment

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

In order for package installation to work (e.g. pip install -e . this line should be removed:
We use a dynamic version when the version number isn't declared in this file but extracted from somewhere else.
In our case we define the version field so if we set both we would get an error.

@isaranto isaranto closed this Jun 12, 2024
@isaranto isaranto deleted the mercelisvaughan-model-1 branch July 2, 2024 10:22
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.

2 participants