onlyjazz / book-launch

Launch a book on social media
0 stars 0 forks source link

feedback_agent_post_stats hangs after 12 posts #6

Open onlyjazz opened 1 hour ago

onlyjazz commented 1 hour ago

Running in the Pycharm debugger console

Is there a 15' timeout?

No 429 messages

onlyjazz commented 57 minutes ago

Bug was in insert_post - not initializing the prompt_identifier

Solved with:

def get_prompt_identifier():
    # Get the latest round of the publishing cycle
    query = f'*[_type == "cycle"]{{round}}'
    data = query_sanity_documents(query)
    current_cycle = data['result'][0]['round']
    # Get the prompt.identifier for this cycle
    query = f'*[_type == "prompt" && cycle=={current_cycle}].identifier'
    data = query_sanity_documents(query)
    prompt_identifier = data['result'][0]
    return prompt_identifier

def insert_post(post_header, post_content):
    """
    Inserts a new post document into the Sanity Content Lake.

    Args:
    - document: The document to insert (should be a dictionary).

    Returns:
    - Response from the Sanity API.
    """
    cta = get_cta()
    post_content_cta = post_content + "\n\n" + cta
    url = f"https://{project_id}.api.sanity.io/{api_version}/data/mutate/{dataset}"
    headers = {
        "Content-Type": "application/json",
        "Authorization": f"Bearer {token}"
    }
    doc = {
        "_type": "post",
        "header": post_header,
        "prompt_identifier": get_prompt_identifier(),