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

add article topic outlink #18

Merged
merged 3 commits into from
Jul 4, 2024
Merged

add article topic outlink #18

merged 3 commits into from
Jul 4, 2024

Conversation

mercelisvaughan
Copy link
Collaborator

@mercelisvaughan mercelisvaughan commented Jun 23, 2024

added article outlink topic and updated the init file to include, this can make a request to the model and return a response with the following

client = ArticleTopicModel()
payload = {
    "page_title": "Douglas Adams",
    "lang": "en",
}
result = client.request(payload=payload)
print(result)

kevinbazira
kevinbazira previously approved these changes Jul 4, 2024
Copy link
Member

@kevinbazira kevinbazira left a comment

Choose a reason for hiding this comment

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

LGTM!

# Conflicts:
#	liftwing/__init__.py
@isaranto
Copy link
Collaborator

isaranto commented Jul 4, 2024

I have added the fields as optional using the Optional annotation so that it is more explicit

from liftwing import ArticleTopicModel

client = ArticleTopicModel()
payload = {
    "page_title": "Douglas Adams",
    "lang": "en",
    "debug": True,
}
result = client.request(payload=payload)

@isaranto isaranto requested a review from kevinbazira July 4, 2024 12:34
@kevinbazira
Copy link
Member

I have added the fields as optional using the Optional annotation so that it is more explicit

looks like this change didn't take effect :)

>>> from liftwing import ArticleTopicModel
>>> 
>>> client = ArticleTopicModel()
>>> payload = {
...     "page_title": "Douglas Adams",
...     "lang": "en",
...     "debug": True,
... }
>>> result = client.request(payload=payload)
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/home/kbazira/kevinbazira/sharedfolder/liftwing-python/ilias1/liftwing-python/liftwing/models/liftwing_model.py", line 31, in request
    _ = self.payload_model(**payload)
  File "/home/kbazira/kevinbazira/sharedfolder/liftwing-python/ilias1/.venv/lib/python3.10/site-packages/pydantic/main.py", line 192, in __init__
    self.__pydantic_validator__.validate_python(data, self_instance=self)
pydantic_core._pydantic_core.ValidationError: 2 validation errors for ArticleTopicPayload
threshold
  Field required [type=missing, input_value={'page_title': 'Douglas A...g': 'en', 'debug': True}, input_type=dict]
    For further information visit https://errors.pydantic.dev/2.8/v/missing
features_str
  Field required [type=missing, input_value={'page_title': 'Douglas A...g': 'en', 'debug': True}, input_type=dict]
    For further information visit https://errors.pydantic.dev/2.8/v/missing

@isaranto
Copy link
Collaborator

isaranto commented Jul 4, 2024

I have added the fields as optional using the Optional annotation so that it is more explicit

I actually hadn't pushed anything :( It required a force push and I missed it. Now it should be ok. Apologies!

Copy link
Member

@kevinbazira kevinbazira left a comment

Choose a reason for hiding this comment

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

I actually hadn't pushed anything :( It required a force push and I missed it. Now it should be ok. Apologies!

Great! Now it works like a charm:

>>> from liftwing import ArticleTopicModel
>>> client = ArticleTopicModel()
>>> payload = {
...     "page_title": "Douglas Adams",
...     "lang": "en",
...     "debug": True,
... }
>>> result = client.request(payload=payload)
>>> print(result)
{'prediction': {'article': 'https://en.wikipedia.org/wiki/Douglas Adams', 'results': [{'topic': 'Culture.Media.Media*', 'score': 0.6859594583511353}, {'topic': 'Culture.Biography.Biography*', 'score': 0.5544804334640503}, {'topic': 'Culture.Literature', 'score': 0.5312193632125854}, {'topic': 'Culture.Media.Entertainment', 'score': 0.14415885508060455}, {'topic': 'Culture.Visual_arts.Visual_arts*', 'score': 0.11597072333097458}, {'topic': 'Culture.Visual_arts.Comics_and_Anime', 'score': 0.048867784440517426}, {'topic': 'STEM.STEM*', 'score': 0.04469086229801178}, {'topic': 'Geography.Regions.Americas.North_America', 'score': 0.04337579756975174}, {'topic': 'Geography.Regions.Europe.Europe*', 'score': 0.03623005375266075}, {'topic': 'Culture.Media.Television', 'score': 0.034110426902770996}, {'topic': 'Culture.Media.Books', 'score': 0.029322227463126183}, {'topic': 'Culture.Media.Films', 'score': 0.02596735954284668}, {'topic': 'Culture.Biography.Women', 'score': 0.02369946800172329}, {'topic': 'Geography.Regions.Europe.Northern_Europe', 'score': 0.022296184673905373}, {'topic': 'History_and_Society.Society', 'score': 0.020974241197109222}, {'topic': 'Culture.Internet_culture', 'score': 0.020974241197109222}, {'topic': 'History_and_Society.Business_and_economics', 'score': 0.01799621433019638}, {'topic': 'History_and_Society.Education', 'score': 0.014073628932237625}, {'topic': 'Culture.Philosophy_and_religion', 'score': 0.01206377986818552}, {'topic': 'STEM.Technology', 'score': 0.010996942408382893}, {'topic': 'Culture.Media.Music', 'score': 0.00942259095609188}, {'topic': 'History_and_Society.Politics_and_government', 'score': 0.009135636501014233}, {'topic': 'History_and_Society.History', 'score': 0.008071991614997387}, {'topic': 'STEM.Biology', 'score': 0.006913838442414999}, {'topic': 'Culture.Media.Video_games', 'score': 0.006913838442414999}, {'topic': 'Culture.Media.Radio', 'score': 0.006913838442414999}, {'topic': 'STEM.Computing', 'score': 0.005921069998294115}, {'topic': 'STEM.Earth_and_environment', 'score': 0.005564924795180559}, {'topic': 'Culture.Media.Software', 'score': 0.005230126902461052}, {'topic': 'Geography.Regions.Asia.Asia*', 'score': 0.004765199031680822}, {'topic': 'Culture.Visual_arts.Architecture', 'score': 0.004619571380317211}, {'topic': 'Geography.Regions.Africa.Africa*', 'score': 0.004341503139585257}, {'topic': 'Geography.Geographical', 'score': 0.0038344827480614185}, {'topic': 'Geography.Regions.Europe.Western_Europe', 'score': 0.003717252518981695}, {'topic': 'Culture.Sports', 'score': 0.0036036029923707247}, {'topic': 'Culture.Linguistics', 'score': 0.0034934247378259897}, {'topic': 'History_and_Society.Military_and_warfare', 'score': 0.0032830648124217987}, {'topic': 'Culture.Performing_arts', 'score': 0.0029910325538367033}, {'topic': 'STEM.Medicine_&_Health', 'score': 0.0027249858248978853}, {'topic': 'STEM.Libraries_&_Information', 'score': 0.002482622629031539}, {'topic': 'History_and_Society.Transportation', 'score': 0.00240673148073256}, {'topic': 'Culture.Food_and_drink', 'score': 0.0023331623524427414}, {'topic': 'Geography.Regions.Europe.Eastern_Europe', 'score': 0.0023331623524427414}, {'topic': 'STEM.Engineering', 'score': 0.0021927168127149343}, {'topic': 'Geography.Regions.Asia.West_Asia', 'score': 0.0021927168127149343}, {'topic': 'Geography.Regions.Oceania', 'score': 0.0021927168127149343}, {'topic': 'Geography.Regions.Europe.Southern_Europe', 'score': 0.0019977742340415716}, {'topic': 'Geography.Regions.Americas.South_America', 'score': 0.0019367348868399858}, {'topic': 'STEM.Physics', 'score': 0.0018775658681988716}, {'topic': 'Geography.Regions.Africa.Northern_Africa', 'score': 0.0017107223393395543}, {'topic': 'Geography.Regions.Asia.East_Asia', 'score': 0.0016584827098995447}, {'topic': 'Geography.Regions.Asia.South_Asia', 'score': 0.0016078451881185174}, {'topic': 'Geography.Regions.Americas.Central_America', 'score': 0.001465063076466322}, {'topic': 'STEM.Space', 'score': 0.0011795104946941137}, {'topic': 'STEM.Mathematics', 'score': 0.0011795104946941137}, {'topic': 'Geography.Regions.Asia.Southeast_Asia', 'score': 0.001108730910345912}, {'topic': 'Geography.Regions.Africa.Southern_Africa', 'score': 0.0010749627836048603}, {'topic': 'Geography.Regions.Africa.Western_Africa', 'score': 0.0008395892800763249}, {'topic': 'Culture.Visual_arts.Fashion', 'score': 0.0008140857680700719}, {'topic': 'STEM.Chemistry', 'score': 0.0006978511810302734}, {'topic': 'Geography.Regions.Asia.North_Asia', 'score': 0.0005984087474644184}, {'topic': 'Geography.Regions.Africa.Eastern_Africa', 'score': 0.0004542184469755739}, {'topic': 'Geography.Regions.Africa.Central_Africa', 'score': 1.0000003385357559e-05}, {'topic': 'Geography.Regions.Asia.Central_Asia', 'score': 1.0000003385357559e-05}]}}

@isaranto isaranto changed the title added article topic outlink add article topic outlink Jul 4, 2024
@isaranto isaranto merged commit e9854af into main Jul 4, 2024
1 check passed
@isaranto isaranto deleted the article-quality-validated branch July 4, 2024 13:02
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