File size: 1,559 Bytes
cd05df7
 
 
110299e
cd05df7
 
 
 
 
 
 
110299e
cd05df7
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
from typing import Any, Optional
from smolagents.tools import Tool
import os
import upload_post

class UploadPostStatusTool(Tool):
    name = "upload_post_status"
    description = "Check the status of an Upload-Post upload. Pass the request_id returned by an upload, or the job_id returned by a scheduled or queued post. Returns a dict with the per-platform results, including the post URLs once published."
    inputs = {'request_id': {'type': 'string', 'description': 'request_id returned by an upload.', 'nullable': True}, 'job_id': {'type': 'string', 'description': 'job_id returned by a scheduled or queued upload.', 'nullable': True}}
    output_type = "object"

    def __init__(self, api_key=None, **kwargs):
        super().__init__()
        import os

        self.api_key = api_key or os.environ.get("UPLOAD_POST_API_KEY")
        self.client = None

    def setup(self):
        from upload_post import UploadPostClient

        if not self.api_key:
            raise ValueError(
                "Missing Upload-Post API key: pass api_key=... or set UPLOAD_POST_API_KEY."
            )
        self.client = UploadPostClient(self.api_key)
        self.is_initialized = True

    def forward(self, request_id: Optional[str] = None, job_id: Optional[str] = None) -> Any:
        if not self.is_initialized:
            self.setup()
        if request_id:
            return self.client.get_status(request_id)
        if job_id:
            return self.client.get_job_status(job_id)
        raise ValueError("Provide either request_id or job_id.")