emergingtrajectories

Submodules

Classes

Statement

Forecast

Client

Launch the Emerging Trajectories Client.

EmergingTrajectoriesClient

Functions

hello(→ None)

Just a hello() message/function to confirm you've installed everything!

Package Contents

emergingtrajectories.hello() None

Just a hello() message/function to confirm you’ve installed everything!

class emergingtrajectories.Statement(title, fill_in_the_blank)

Bases: object

id = -1
title
fill_in_the_blank
description = ''
deadline = None
created_at = None
updated_at = None
created_by = None
class emergingtrajectories.Forecast(title, value, justification)

Bases: object

id = -1
title
value
justification
statement = None
created_at = None
updated_at = None
created_by = None
prediction_agent = None
additional_data
prior_forecast = None
next_forecasts = []
is_human = False
class emergingtrajectories.Client(api_key: str)

Bases: object

Launch the Emerging Trajectories Client.

Parameters:

api_key – the API key for the Emerging Trajectories platform.

base_url = 'https://app.emergingtrajectories.com/a/api/v0.2/'
api_key
create_statement(title: str, description: str, deadline: datetime.datetime, fill_in_the_blank: str) dict

Create a new statement that users will be forecasting against/for.

Parameters:
  • title – the title of the statement

  • description – a more detailed description of the statement

  • deadline – the deadline (date and time), typically when we’ll learn the “right answer” for the forecasting process

  • fill_in_the_blank – the “fill in the blank” part of the statement, which is what users will be forecasting against

Returns:

the newly created statement returned from the platform

Return type:

dict

get_statement(statement_id: int) dict

Returns a given statement from the platform. Includes title, description, deadline, and fill-in-the-blank.

Parameters:

statement_id – the ID of the statement to retrieve

Returns:

the statement from the platform

Return type:

dict

get_most_recent_forecast(statement_id: int, prediction_agent: str = None) int

Returns the most recent forecast for a given statement. This is useful for creating a new forecast that is an extension of a prior forecast.

Parameters:
  • statement_id – the ID of the statement to retrieve the most recent forecast for

  • prediction_agent – the string for a prediction agent, if you want to further filter the most recent forecast

Returns:

the ID of the most recent forecast for the given statement

Return type:

int

get_forecast(forecast_id: int) dict

Returns a specific forecast’s details from the platform. This typically includes the forecast title, the value associated with the fill-in-the-blank component of a statement, and justificaiton for the forecast.

Parameters:

forecast_id – the ID of the forecast to retrieve

Returns:

the forecast details in the form of a dictionary object

Return type:

dict

create_forecast(statement_id: int, title: str, justification: str, value: float, prediction_agent: str, additional_data: dict = {}, prior_forecast: int = None, is_human: bool = False) None

Creates a forecast tied to a specific statement.

Parameters:
  • statement_id – the ID of the statement to tie the forecast to

  • title – the title of the forecast

  • justification – the justification for the forecast

  • value – the value associated with the fill-in-the-blank component of the statement

  • prediction_agent – the agent making the prediction

  • additional_data – any additional data to include with the forecast. This is not used anywhere, but can be helpful in audting or researching forecast effectiveness

  • prior_forecast – if this forecast is an extension of an earlier forecast, the ID of the prior forecast

  • is_human – whether the prediction is human-generated

Returns:

the newly created forecast from the platform

Return type:

dict

class emergingtrajectories.EmergingTrajectoriesClient(api_key: str)

Bases: object

Parameters:

api_key – the API key for the Emerging Trajectories platform.

base_url = 'https://app.emergingtrajectories.com/a/api/v0.2/'
api_key
get_events(project_codes: str | List[str] = None, limit: int = 100) List[dict]

Get events from the Emerging Trajectories platform.

Parameters:

project_codes – a single project code or a list of project codes to filter events by

Returns:

a list of events, each represented as a dictionary

Return type:

List[dict]

search_public_events(query, project_codes: str | List[str], limit: int = 10) List[dict]

Search for public events on the Emerging Trajectories platform.

Parameters:
  • query – the search query string

  • project_codes – a single project code or a list of project codes to filter events by

  • limit – the maximum number of events to return

Returns:

a list of events, each represented as a dictionary

Return type:

List[dict]

upload_pdf(pdf_path: str, factbase_shortcode: str) bool

Upload a PDF to the Emerging Trajectories platform.

Parameters:
  • pdf_path – the path to the PDF file to upload

  • factbase_shortcode – the short code for the factbase to attach the PDF to

Returns:

returns True if file has been uploaded successfully

Return type:

bool

create_factbase(title: str, description: str) str

Create a new factbase on the Emerging Trajectories platform.

Parameters:
  • title – the title of the factbase

  • description – a description of the factbase

Returns:

The short_code for the factbase.

Return type:

str

get_facts(short_code, query, days_filter=1, pubdate_days_filter=-1, use_text_match=False) str

Query the fact base and simply get the raw facts normally generated for documents or other internal processes.

Parameters:
  • short_code – the short code for the factbase to query

  • query – the query to run

  • days_filter – limit facts to the recent number of days

  • pubdate_days_filter – limit facts to the recent number of days based on publication date

  • use_text_match – use text matching for the query

Returns:

A list of facts as a string.

Return type:

str

query_factbase(short_code, query, days_filter=1, pubdate_days_filter=-1, llm_model=None, llm_temperature=None) str

Query the fact base as if you’d query a document, but with no document required. The responses here are ephemeral and are not stored anywhere.

Parameters:
  • short_code – the short code for the factbase to query

  • query – the query to run

  • days_filter – limit facts to the recent number of days

  • pubdate_days_filter – limit facts to the recent number of days based on publication date

  • llm_model – the LLM model to use

  • llm_temperature – the LLM temperature to use

Returns:

The response written based on facts in the fact base.

Return type:

str

build_research_plan(query: str) dict

Given a research question/query, we create a set of tasks that we can then automate document creation around.

Parameters:

query – the research question/query to build tasks around

Returns:

a dictionary with two keys – “text” which is the text plan, and “plan” which is a JSON plan

Return type:

dict

run_research_sub_task(command: str, args: str | List[str], document_id: int, short_code: str, wait_until_completion: bool = True) int

Run the research sub-task outlined in a research plan.

Parameters:
  • command – the command to run

  • args – the arguments to pass to the command

  • document_id – the ID of the document to attach the research task to

  • short_code – the short code for the factbase to use

  • wait_until_completion – whether to wait until the task is completed before returning

Returns:

the ID of the job or -1 if not applicable

Return type:

int

research_task_header_and_block(doc_id: int, query: str) int

Runs a research analyst task where we generate a header block and then run the query for the document.

Parameters:
  • doc_id – the ID of the document to attach the research task to

  • query – the query to run

Returns:

the ID of the job

Return type:

int

run_data_collector_job(factbase_shortcode: str, settings: dict) int

Creates a new data collector job and runs it. Contact us for information on how to pass settings.

Parameters:
  • factbase_shortcode – the short code for the factbase

  • settings – a dictionary of settings for the data collector job

Returns:

The ID of the job

Return type:

int

run_data_collector_serp(factbase_shortcode: str, query: str | List[str], n: int = 5, settings: dict = None) int

Creates a new data collector job and runs it. Contact us for information on how to pass settings.

Parameters:
  • factbase_shortcode – the short code for the factbase

  • query – a string to search or an array of strings

  • settings – a dictionary of settings for the data collector job

Returns:

The ID of the job

Return type:

int

run_data_collector_news(factbase_shortcode: str, query: str | List[str], n: int = 5, settings: dict = None) int

Creates a new data collector job and runs it. Contact us for information on how to pass settings.

Parameters:
  • factbase_shortcode – the short code for the factbase

  • query – a string to search or an array of strings

  • settings – a dictionary of settings for the data collector job

Returns:

The ID of the job

Return type:

int

get_data_collector_job_status(job_id: int) str

Get the status of a data collector job.

Parameters:

job_id – the ID of the job

Returns:

The status of the job

Return type:

str

create_document(factbase_shortcode: str, title: str = None, days_filter=99999, temperature=None, llm=None, facts_min_date=None, facts_max_date=None) int

Create a new document on the Emerging Trajectories platform.

Parameters:
  • factbase_shortcode – the short code for the factbase to attach the document to

  • title (optional) – the title of the document

  • days_filter (optional) – limit facts to the recent number of days

Returns:

The ID of the document.

Return type:

int

convert_facts_in_text(factbase_shortcode: str, text: str)

Convert text with facts to HTML code with associated links.

Parameters:
  • factbase_shortcode – the short code for the factbase to attach the document to

  • text – the text to convert

Returns:

the converted text as HTML array: a list facts found in the text, with the key being the source ID in the HTML

Return type:

str

update_document(doc_id: int, title: str = None, is_public: bool = None, short_code: str = None) bool

Update document settings.

Parameters:
  • doc_id – the ID of the document

  • title – the new title of the document

  • is_public – whether the document is public (updated setting)

  • short_code – the short code for the document (updated setting)

Returns:

True if successful, False otherwise

Return type:

bool

get_document(doc_id: int) dict

Get document data.

Parameters:

doc_id – the ID of the document

Returns:

The ID of the document.

Return type:

int

add_viewer(doc_id: int, viewer_email: str) bool

Add a viewer to a private document.

Parameters:
  • doc_id – the ID of the document

  • viewer_email – the email of the viewer to add

Returns:

True if successful, False otherwise

Return type:

bool

remove_viewer(doc_id: int, viewer_email: str) bool

Remove a viewer from a private document.

Parameters:
  • doc_id – the ID of the document

  • viewer_email – the email of the viewer to remove

Returns:

True if successful or if the email is NOT a viewer already, False otherwise

Return type:

bool

get_block(doc_id: int, block_named_id: str) str

Get the content of a named block from a document.

Parameters:
  • doc_id – the ID of the document

  • block_named_id – the named ID of the block to retrieve

Returns:

the content of the block

Return type:

str

append_header_block(doc_id, text: str, is_hidden: bool = False) bool

Add a header block to a document.

Parameters:
  • doc_id – the ID of the document to append the header block to

  • text – the text (header) to append

  • is_hidden – whether the block is hidden in public documents

Returns:

True if successful, False otherwise

Return type:

bool

append_text_block(doc_id: int, text: str) bool

Add a text block to a document.

Parameters:
  • doc_id – the ID of the document to append the text block to

  • text – the text to append

Returns:

True if successful, False otherwise

Return type:

bool

append_hidden_block(doc_id: int, prompt: str) bool

Add a text block to a document.

Parameters:
  • doc_id – the ID of the document to append the text block to

  • prompt – the text (typically a prompt) to append

Returns:

True if successful, False otherwise

Return type:

bool

append_askai_fts_block(doc_id: int, query: str, fts_term: str, named_id: str = None, is_hidden: bool = False) dict

Add an AI (FTS) block to a document.

Parameters:
  • doc_id – the ID of the document to append the text block to

  • query – the query to use for the AI block

  • fts_term – the full text search (FTS) terms/query to use for the AI block

  • named_id – the named ID of the AI block

  • is_hidden – whether the block is hidden in public documents

Returns:

JSON dict with document information

append_risk_score_doc_block(doc_id: int, query: str, named_id: str = None, is_hidden: bool = False) dict

Add a risk score block to a document. This risk score only evaluates based on what’s in the document already; it does not query the fact base.

Parameters:
  • doc_id – the ID of the document to append the text block to

  • query – the query to use for the AI block

  • named_id – the named ID of the AI block

  • is_hidden – whether the block is hidden in public documents

Returns:

JSON dict with document information

append_askai_fts_cot_block(doc_id: int, query: str, fts_term: str, named_id: str = None, is_hidden: bool = False) dict

Add an AI (FTS) block to a document.

Parameters:
  • doc_id – the ID of the document to append the text block to

  • query – the query to use for the AI block

  • fts_term – the full text search (FTS) terms/query to use for the AI block

  • named_id – the named ID of the AI block

  • is_hidden – whether the block is hidden in public documents

Returns:

JSON dict with document information

append_askai_cot_block(doc_id: int, query: str, named_id: str = None, is_hidden: bool = False) dict

Add an AI (COT) block to a document.

Parameters:
  • doc_id – the ID of the document to append the text block to

  • query – the query to use for the AI block

  • named_id – the named ID of the AI block

  • is_hidden – whether the block is hidden in public documents

Returns:

JSON dict with document information

append_askai_cot_pubdate_block(doc_id: int, query: str, named_id: str = None, is_hidden: bool = False) dict

Add an AI (COT) block to a document.

Parameters:
  • doc_id – the ID of the document to append the text block to

  • query – the query to use for the AI block

  • named_id – the named ID of the AI block

  • is_hidden – whether the block is hidden in public documents

Returns:

JSON dict with document information

append_askai_block(doc_id: int, query: str, named_id: str = None, is_hidden: bool = False) dict

Add an AI block to a document.

Parameters:
  • doc_id – the ID of the document to append the text block to

  • query – the query to use for the AI block

  • is_hidden – whether the block is hidden in public documents

Returns:

JSON dict with document information

append_askai_block_fact_range(doc_id: int, query: str, named_id: str = None, is_hidden: bool = False, num_results=10, num_before=7, num_after=7) dict

Add an AI ‘fact range’ block to a document. This uses an experimental form of RAG that should reduce hallucinations but also reduces the # of sources that can be queried.

Parameters:
  • doc_id – the ID of the document to append the text block to

  • query – the query to use for the AI block

  • is_hidden – whether the block is hidden in public documents

  • num_results – the number of results (sources) to return when doing a deep dive

  • num_before – the number of facts to include prior to the core fact (with chunking)

  • num_after – the number of facts to include after the core fact (with chunking)

Returns:

JSON dict with document information

create_automation_factbase(short_code, job_type, arg_string=None, args=None)

Create an automation for a fact base.

Parameters:
  • short_code – the short code for the factbase

  • job_type – the type of job to run

  • arg_string – a string of arguments

  • args – a dictionary of arguments if the job requires more than one

Returns:

the automation object

Return type:

dict

create_automation_document(doc_id, job_type, arg_string=None, args=None)

Create an automation for a document.

Parameters:
  • doc_id – the document ID

  • job_type – the type of job to run

  • arg_string – a string of arguments

  • args – a dictionary of arguments if the job requires more than one

Returns:

the automation object

Return type:

dict

get_factbase_automations(factbase_short_code)

Get an array of all automations that can be run on a factbase.

Parameters:

factbase_short_code – the short code for the factbase

Returns:

an array of automations that can be run on the factbase

Return type:

list

queue_automation(automation_id)

Queue an automation (i.e., request the Emerging Trajectories platform to run an automation).

Parameters:

automation_id – the ID of the automation to queue

Returns:

True if successful, False otherwise

Return type:

bool

get_statement(statement_id: int) Statement

Returns a given statement from the platform. Includes title, description, deadline, and fill-in-the-blank.

Parameters:

statement_id – the ID of the statement to retrieve

Returns:

the statement from the platform

Return type:

Statement

get_forecast(forecast_id: int) Forecast

Returns a given forecast from the platform.

Parameters:

forecast_id – the ID of the statement to retrieve

Returns:

the forecast from the platform

Return type:

Forecast

get_facts_from_factbase(fact_db_slug: str, fact_id: str = None, fact_ids: list = None, source_url: str = None) list[dict]

Gets a list of facts from a fact base.

Parameters:
  • fact_db_slug – the slug of the fact database to get facts from.

  • fact_id – the ID of the fact to retrieve.

  • fact_ids – a list of fact IDs to retrieve.

  • source_url – the URL of the source to retrieve facts from.

Returns:

a list of facts from the fact base.

Return type:

list

add_facts_to_factbase(fact_db_slug: str, url: str, facts: list[str]) bool

Adds a list of facts to a factbase on the Emerging Trajectories website.

Parameters:
  • fact_db_slug – the slug of the fact database to add the fact to.

  • url – the URL of the fact.

  • facts – the facts to add (a list of strings).

Returns:

True if successful, False otherwise.

Return type:

bool

add_facts_to_factbase_unique_urls(fact_db_slug: str, urls: list[str], facts: list[str], pubdates: list[datetime.datetime] = None) bool

Adds a list of facts to a factbase on the Emerging Trajectories website. This currently has a maximum # of 100 facts that can be sent at a time.

Parameters:
  • fact_db_slug – the slug of the fact database to add the fact to.

  • urls – the URLs of the facts.

  • facts – the facts to add (a list of strings).

  • pubdates – the publication dates of the facts.

Returns:

True if successful, False otherwise.

Return type:

bool

add_fact_to_factbase(fact_db_slug: str, url: str, fact: str, pubdate=None) bool

Adds a fact to a factbase on the Emerging Trajectories website.

Parameters:
  • fact_db_slug – the slug of the fact database to add the fact to.

  • url – the URL of the fact.

  • fact – the fact to add.

  • pubdate – datetime object for when the fact was published.

Returns:

True if successful, False otherwise.

Return type:

bool

add_content_to_factbase(fact_db_slug: str, url: str, content: str, topic: str) bool

Sends content to the Emerging Trajectories website and extract facts from it.

Parameters:
  • fact_db_slug – the slug of the fact database to add the content to.

  • url – the URL of the content. Note: we do not actually crawl this, we assume the content passed is the right conent.

  • content – the content to extract facts from.

  • topic – the topic of the content.

Returns:

True if successful, False otherwise.

Return type:

bool

add_url_to_factbase(fact_db_slug: str, url: str | list[str], topic: str = '') bool

Sends URL to the Emerging Trajectories website, crawls the URL, and extracts facts from it.

Parameters:
  • fact_db_slug – the slug of the fact database to add the content to.

  • url – the URL of the content, which we will crawl. Could also be an array.

  • topic – the topic of the content.

Returns:

True if successful, False otherwise.

Return type:

bool