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

[BUG] Unable to receive events via Webhooks #5782

Open
AnaAbadLorenzo opened this issue Jan 17, 2025 · 1 comment
Open

[BUG] Unable to receive events via Webhooks #5782

AnaAbadLorenzo opened this issue Jan 17, 2025 · 1 comment
Assignees
Labels
type: bug Indicates an unexpected problem or unintended behavior

Comments

@AnaAbadLorenzo
Copy link

AnaAbadLorenzo commented Jan 17, 2025

Describe the bug

I have a problem receiving events via webhooks.
My purpose is that every time the answer to a question (that is a suggestion of a model) is changed from the argilla UI, my server receives an event indicating that it has been changed.
I have argilla up locally through a docker with the configuration uploaded in this repository.
Below I provide the code I use for the argilla upload and webhook configuration.

Stacktrace and code to create the bug

import os
import pandas as pd
import argilla as rg
import uuid
from model import GroupedMessage, Record
from dotenv import dotenv_values
import datetime

#******************************************************************************
# Read data from file
#******************************************************************************

def _get_each_row(file_path):
    df = pd.read_parquet(file_path)
    return [
        GroupedMessage(
            list(row['ids']),
            row['content']
            row['classification']
        )
        for _, row in df.iterrows()
    ]

def get_grouped_messages():
    path='../../resources/processing'
    grouped_messages = []

    for file_name in os.listdir(path):
        file_path = os.path.join(path, file_name)
        if os.path.isfile(file_path) and file_name.endswith('.parquet'):
            grouped_messages.extend(_get_each_row(file_path))

    return grouped_messages

#******************************************************************************
# Create argilla form
#******************************************************************************

def create_dataset_if_not_exists(client):
    dataset_name = "messages_validation"
    dataset = client.datasets(name=dataset_name)
    if dataset is None:
        settings = rg.Settings(
            guidelines="Check if this message is correctly done",
            fields=[
                rg.TextField(
                    name="message_content",
                    title="Message content"
                ),
            ],
            questions=[
                rg.LabelQuestion(
                    name="inferred_class",
                    title="Is this message correct ",
                    labels=["YES", "NO"]
                ),
            ],
            allow_extra_metadata=True,
        )
        dataset = rg.Dataset(
            name=dataset_name,
            settings=settings,
            client=client
        )
        dataset.create()
    return dataset

def _map_record(domain: Record) -> rg.Record:
    return rg.Record(
        id=str(uuid.uuid4()),
        fields={"message_content": domain.content},
        metadata={
            "classification_ids": domain.ids
        },
        suggestions=[rg.Suggestion(question_name="inferred_class", value=domain.classification)]
    )

def upload_records_to_argilla(records: list[Record], dataset):
    argilla_records = list(map(_map_record, records))
    dataset.records.log(argilla_records)

#******************************************************************************
# Main execution
#******************************************************************************

conf = dotenv_values('../.env')
argilla_client = rg.Argilla(api_url=conf['ARGILLA_API_URL'], api_key=conf['ARGILLA_API_KEY'])
dataset = create_dataset_if_not_exists(argilla_client)

for webhook in argilla_client.webhooks:
    print(f"Deleting webhook: {webhook.url}")
    webhook.delete()

server = rg.get_webhook_server()

argilla_batch_size = 50
grouped_messages = get_grouped_messages()
records = []

for webhook in argilla_client.webhooks:
    print(webhook)

for grouped_message in grouped_messages:
     try:
         records.append(Record(grouped_message.ids, grouped_message.content, grouped_message.classification))
     except Exception as error:
         print(f"Error creating record: {error}")
     if len(records) == argilla_batch_size:
         upload_records_to_argilla(records, dataset)
         records = []

if len(records) != 0:
    upload_records_to_argilla(records, dataset)

@rg.webhook_listener(events=["record.completed"], client=argilla_client)
async def record_events(record: rg.Record, type: str, timestamp: datetime):
    print(f"Received event type {type} at {timestamp}: ", record)

I launch de application with

WEBHOOK_SERVER_URL=http://host.docker.internal:8000 \
uvicorn main:server

When I complete a record suggestion, I obtain this error

2025-01-20 10:50:30 [01/20/25 09:50:30] INFO     INFO:rq.worker:high:                  worker.py:671
2025-01-20 10:50:30                              argilla_server.jobs.webhook_jobs.noti              
2025-01-20 10:50:30                              fy_event_job(UUID('08db6e1f-9eb8-4af5              
2025-01-20 10:50:30                              -b4bc-5cb225c1b9c0'),                              
2025-01-20 10:50:30                              <RecordEvent.completed:                            
2025-01-20 10:50:30                              'record.completed'>,                               
2025-01-20 10:50:30                              datetime.datetime(2025, 1, 20, 9, 50,              
2025-01-20 10:50:30                              30, 658465), {'id':                                
2025-01-20 10:50:30                              '44f03485-2e60-4e37-89fc-87635ca25b0a              
2025-01-20 10:50:30                              ', 'status': 'completed', 'fiel...)                
2025-01-20 10:50:30                              (9c3f389a-c3e8-4ad7-aa55-76f175aa0f2d              
2025-01-20 10:50:30                              )                                                  
2025-01-20 10:50:31 [01/20/25 09:50:31] ERROR    ERROR:rq.worker:[Job                 worker.py:1503
2025-01-20 10:50:31                              9c3f389a-c3e8-4ad7-aa55-76f175aa0f2d               
2025-01-20 10:50:31                              ]: exception raised while executing                
2025-01-20 10:50:31                              (argilla_server.jobs.webhook_jobs.no               
2025-01-20 10:50:31                              tify_event_job)                                    
2025-01-20 10:50:31                              Traceback (most recent call last):                 
2025-01-20 10:50:31                                File                                             
2025-01-20 10:50:31                              "/opt/venv/lib/python3.13/site-packa               
2025-01-20 10:50:31                              ges/httpx/_transports/default.py",                 
2025-01-20 10:50:31                              line 72, in map_httpcore_exceptions                
2025-01-20 10:50:31                                  yield                                          
2025-01-20 10:50:31                                File                                             
2025-01-20 10:50:31                              "/opt/venv/lib/python3.13/site-packa               
2025-01-20 10:50:31                              ges/httpx/_transports/default.py",                 
2025-01-20 10:50:31                              line 236, in handle_request                        
2025-01-20 10:50:31                                  resp =                                         
2025-01-20 10:50:31                              self._pool.handle_request(req)                     
2025-01-20 10:50:31                                File                                             
2025-01-20 10:50:31                              "/opt/venv/lib/python3.13/site-packa               
2025-01-20 10:50:31                              ges/httpcore/_sync/connection_pool.p               
2025-01-20 10:50:31                              y", line 256, in handle_request                    
2025-01-20 10:50:31                                  raise exc from None                            
2025-01-20 10:50:31                                File                                             
2025-01-20 10:50:31                              "/opt/venv/lib/python3.13/site-packa               
2025-01-20 10:50:31                              ges/httpcore/_sync/connection_pool.p               
2025-01-20 10:50:31                              y", line 236, in handle_request                    
2025-01-20 10:50:31                                  response =                                     
2025-01-20 10:50:31                              connection.handle_request(                         
2025-01-20 10:50:31                                      pool_request.request                       
2025-01-20 10:50:31                                  )                                              
2025-01-20 10:50:31                                File                                             
2025-01-20 10:50:31                              "/opt/venv/lib/python3.13/site-packa               
2025-01-20 10:50:31                              ges/httpcore/_sync/connection.py",                 
2025-01-20 10:50:31                              line 101, in handle_request                        
2025-01-20 10:50:31                                  raise exc                                      
2025-01-20 10:50:31                                File                                             
2025-01-20 10:50:31                              "/opt/venv/lib/python3.13/site-packa               
2025-01-20 10:50:31                              ges/httpcore/_sync/connection.py",                 
2025-01-20 10:50:31                              line 78, in handle_request                         
2025-01-20 10:50:31                                  stream = self._connect(request)                
2025-01-20 10:50:31                                File                                             
2025-01-20 10:50:31                              "/opt/venv/lib/python3.13/site-packa               
2025-01-20 10:50:31                              ges/httpcore/_sync/connection.py",                 
2025-01-20 10:50:31                              line 124, in _connect                              
2025-01-20 10:50:31                                  stream =                                       
2025-01-20 10:50:31                              self._network_backend.connect_tcp(**               
2025-01-20 10:50:31                              kwargs)                                            
2025-01-20 10:50:31                                File                                             
2025-01-20 10:50:31                              "/opt/venv/lib/python3.13/site-packa               
2025-01-20 10:50:31                              ges/httpcore/_backends/sync.py",                   
2025-01-20 10:50:31                              line 207, in connect_tcp                           
2025-01-20 10:50:31                                  with map_exceptions(exc_map):                  
2025-01-20 10:50:31                                       ~~~~~~~~~~~~~~^^^^^^^^^                   
2025-01-20 10:50:31                                File                                             
2025-01-20 10:50:31                              "/usr/local/lib/python3.13/contextli               
2025-01-20 10:50:31                              b.py", line 162, in __exit__                       
2025-01-20 10:50:31                                  self.gen.throw(value)                          
2025-01-20 10:50:31                                  ~~~~~~~~~~~~~~^^^^^^^                          
2025-01-20 10:50:31                                File                                             
2025-01-20 10:50:31                              "/opt/venv/lib/python3.13/site-packa               
2025-01-20 10:50:31                              ges/httpcore/_exceptions.py", line                 
2025-01-20 10:50:31                              14, in map_exceptions                              
2025-01-20 10:50:31                                  raise to_exc(exc) from exc                     
2025-01-20 10:50:31                              httpcore.ConnectError: [Errno 99]                  
2025-01-20 10:50:31                              Cannot assign requested address                    
2025-01-20 10:50:31                                                                                 
2025-01-20 10:50:31                              The above exception was the direct                 
2025-01-20 10:50:31                              cause of the following exception:                  
2025-01-20 10:50:31                                                                                 
2025-01-20 10:50:31                              Traceback (most recent call last):                 
2025-01-20 10:50:31                                File                                             
2025-01-20 10:50:31                              "/opt/venv/lib/python3.13/site-packa               
2025-01-20 10:50:31                              ges/rq/worker.py", line 1430, in                   
2025-01-20 10:50:31                              perform_job                                        
2025-01-20 10:50:31                                  rv = job.perform()                             
2025-01-20 10:50:31                                File                                             
2025-01-20 10:50:31                              "/opt/venv/lib/python3.13/site-packa               
2025-01-20 10:50:31                              ges/rq/job.py", line 1280, in                      
2025-01-20 10:50:31                              perform                                            
2025-01-20 10:50:31                                  self._result = self._execute()                 
2025-01-20 10:50:31                                                 ~~~~~~~~~~~~~^^                 
2025-01-20 10:50:31                                File                                             
2025-01-20 10:50:31                              "/opt/venv/lib/python3.13/site-packa               
2025-01-20 10:50:31                              ges/rq/job.py", line 1320, in                      
2025-01-20 10:50:31                              _execute                                           
2025-01-20 10:50:31                                  coro_result =                                  
2025-01-20 10:50:31                              loop.run_until_complete(result)                    
2025-01-20 10:50:31                                File                                             
2025-01-20 10:50:31                              "/usr/local/lib/python3.13/asyncio/b               
2025-01-20 10:50:31                              ase_events.py", line 720, in                       
2025-01-20 10:50:31                              run_until_complete                                 
2025-01-20 10:50:31                                  return future.result()                         
2025-01-20 10:50:31                                         ~~~~~~~~~~~~~^^                         
2025-01-20 10:50:31                                File                                             
2025-01-20 10:50:31                              "/opt/venv/lib/python3.13/site-packa               
2025-01-20 10:50:31                              ges/argilla_server/jobs/webhook_jobs               
2025-01-20 10:50:31                              .py", line 54, in notify_event_job                 
2025-01-20 10:50:31                                  response = notify_event(webhook,               
2025-01-20 10:50:31                              event, timestamp, data)                            
2025-01-20 10:50:31                                File                                             
2025-01-20 10:50:31                              "/opt/venv/lib/python3.13/site-packa               
2025-01-20 10:50:31                              ges/argilla_server/webhooks/v1/commo               
2025-01-20 10:50:31                              ns.py", line 40, in notify_event                   
2025-01-20 10:50:31                                  return httpx.post(                             
2025-01-20 10:50:31                                         ~~~~~~~~~~^                             
2025-01-20 10:50:31                                      webhook.url,                               
2025-01-20 10:50:31                                      ^^^^^^^^^^^^                               
2025-01-20 10:50:31                                  ...<2 lines>...                                
2025-01-20 10:50:31                                      timeout=NOTIFY_EVENT_DEFAULT               
2025-01-20 10:50:31                              _TIMEOUT,                                          
2025-01-20 10:50:31                                      ^^^^^^^^^^^^^^^^^^^^^^^^^^^^               
2025-01-20 10:50:31                              ^^^^^^^^^                                          
2025-01-20 10:50:31                                  )                                              
2025-01-20 10:50:31                                  ^                                              
2025-01-20 10:50:31                                File                                             
2025-01-20 10:50:31                              "/opt/venv/lib/python3.13/site-packa               
2025-01-20 10:50:31                              ges/httpx/_api.py", line 331, in                   
2025-01-20 10:50:31                              post                                               
2025-01-20 10:50:31                                  return request(                                
2025-01-20 10:50:31                                      "POST",                                    
2025-01-20 10:50:31                                  ...<15 lines>...                               
2025-01-20 10:50:31                                      trust_env=trust_env,                       
2025-01-20 10:50:31                                  )                                              
2025-01-20 10:50:31                                File                                             
2025-01-20 10:50:31                              "/opt/venv/lib/python3.13/site-packa               
2025-01-20 10:50:31                              ges/httpx/_api.py", line 118, in                   
2025-01-20 10:50:31                              request                                            
2025-01-20 10:50:31                                  return client.request(                         
2025-01-20 10:50:31                                         ~~~~~~~~~~~~~~^                         
2025-01-20 10:50:31                                      method=method,                             
2025-01-20 10:50:31                                      ^^^^^^^^^^^^^^                             
2025-01-20 10:50:31                                  ...<8 lines>...                                
2025-01-20 10:50:31                                      follow_redirects=follow_redi               
2025-01-20 10:50:31                              rects,                                             
2025-01-20 10:50:31                                      ^^^^^^^^^^^^^^^^^^^^^^^^^^^^               
2025-01-20 10:50:31                              ^^^^^^                                             
2025-01-20 10:50:31                                  )                                              
2025-01-20 10:50:31                                  ^                                              
2025-01-20 10:50:31                                File                                             
2025-01-20 10:50:31                              "/opt/venv/lib/python3.13/site-packa               
2025-01-20 10:50:31                              ges/httpx/_client.py", line 837, in                
2025-01-20 10:50:31                              request                                            
2025-01-20 10:50:31                                  return self.send(request,                      
2025-01-20 10:50:31                              auth=auth,                                         
2025-01-20 10:50:31                              follow_redirects=follow_redirects)                 
2025-01-20 10:50:31                                         ~~~~~~~~~^^^^^^^^^^^^^^^^               
2025-01-20 10:50:31                              ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^               
2025-01-20 10:50:31                              ^^^                                                
2025-01-20 10:50:31                                File                                             
2025-01-20 10:50:31                              "/opt/venv/lib/python3.13/site-packa               
2025-01-20 10:50:31                              ges/httpx/_client.py", line 926, in                
2025-01-20 10:50:31                              send                                               
2025-01-20 10:50:31                                  response =                                     
2025-01-20 10:50:31                              self._send_handling_auth(                          
2025-01-20 10:50:31                                      request,                                   
2025-01-20 10:50:31                                  ...<2 lines>...                                
2025-01-20 10:50:31                                      history=[],                                
2025-01-20 10:50:31                                  )                                              
2025-01-20 10:50:31                                File                                             
2025-01-20 10:50:31                              "/opt/venv/lib/python3.13/site-packa               
2025-01-20 10:50:31                              ges/httpx/_client.py", line 954, in                
2025-01-20 10:50:31                              _send_handling_auth                                
2025-01-20 10:50:31                                  response =                                     
2025-01-20 10:50:31                              self._send_handling_redirects(                     
2025-01-20 10:50:31                                      request,                                   
2025-01-20 10:50:31                                      follow_redirects=follow_redi               
2025-01-20 10:50:31                              rects,                                             
2025-01-20 10:50:31                                      history=history,                           
2025-01-20 10:50:31                                  )                                              
2025-01-20 10:50:31                                File                                             
2025-01-20 10:50:31                              "/opt/venv/lib/python3.13/site-packa               
2025-01-20 10:50:31                              ges/httpx/_client.py", line 991, in                
2025-01-20 10:50:31                              _send_handling_redirects                           
2025-01-20 10:50:31                                  response =                                     
2025-01-20 10:50:31                              self._send_single_request(request)                 
2025-01-20 10:50:31                                File                                             
2025-01-20 10:50:31                              "/opt/venv/lib/python3.13/site-packa               
2025-01-20 10:50:31                              ges/httpx/_client.py", line 1027, in               
2025-01-20 10:50:31                              _send_single_request                               
2025-01-20 10:50:31                                  response =                                     
2025-01-20 10:50:31                              transport.handle_request(request)                  
2025-01-20 10:50:31                                File                                             
2025-01-20 10:50:31                              "/opt/venv/lib/python3.13/site-packa               
2025-01-20 10:50:31                              ges/httpx/_transports/default.py",                 
2025-01-20 10:50:31                              line 235, in handle_request                        
2025-01-20 10:50:31                                  with map_httpcore_exceptions():                
2025-01-20 10:50:31                                       ~~~~~~~~~~~~~~~~~~~~~~~^^                 
2025-01-20 10:50:31                                File                                             
2025-01-20 10:50:31                              "/usr/local/lib/python3.13/contextli               
2025-01-20 10:50:31                              b.py", line 162, in __exit__                       
2025-01-20 10:50:31                                  self.gen.throw(value)                          
2025-01-20 10:50:31                                  ~~~~~~~~~~~~~~^^^^^^^                          
2025-01-20 10:50:31                                File                                             
2025-01-20 10:50:31                              "/opt/venv/lib/python3.13/site-packa               
2025-01-20 10:50:31                              ges/httpx/_transports/default.py",                 
2025-01-20 10:50:31                              line 89, in map_httpcore_exceptions                
2025-01-20 10:50:31                                  raise mapped_exc(message) from                 
2025-01-20 10:50:31                              exc                                                
2025-01-20 10:50:31                              httpx.ConnectError: [Errno 99]                     
2025-01-20 10:50:31                              Cannot assign requested address                    
2025-01-20 10:50:31                                                                                 

Expected behavior

When I launch the server, I access argilla to see the dataset records. I want that when I change the suggestion of one of them and press send, I receive the event

Environment

  • Docker with same configuration as indicated in this repository

Additional context

No response

@AnaAbadLorenzo AnaAbadLorenzo changed the title Unable to receive events via Webhooks [BUG] Unable to receive events via Webhooks Jan 20, 2025
@frascuchon frascuchon self-assigned this Jan 20, 2025
@frascuchon frascuchon added the type: bug Indicates an unexpected problem or unintended behavior label Jan 20, 2025
@frascuchon
Copy link
Member

Hi @AnaAbadLorenzo and thanks for your feedback.

Can you verify the webhook server is up and running at http://localhost:8000? Also, can you share some env info (OS, docker version, ...)? It looks like a network error, but I cannot determine the origin.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
type: bug Indicates an unexpected problem or unintended behavior
Projects
None yet
Development

No branches or pull requests

2 participants