Download src/polyhedra/services/data_fetch_sources.py from polyHedra/PolyHedra: direct link, hf CLI and curl.
- Browser
- Download file 2.11 kB
-
https://huggingface.co/spaces/polyHedra/PolyHedra/resolve/main/src/polyhedra/services/data_fetch_sources.py
- Command line
-
hf download hf://spaces/polyHedra/PolyHedra/src/polyhedra/services/data_fetch_sources.py
-
curl -L -o data_fetch_sources.py https://huggingface.co/spaces/polyHedra/PolyHedra/resolve/main/src/polyhedra/services/data_fetch_sources.py
2.11 kB
| """Resolve published DataFetcher evidence shared by typed analysis agents.""" | |
| from polyhedra.agents.quant.market_data_contracts import ( | |
| DataFetcherOutput, | |
| MarketDataArtifact, | |
| ) | |
| from polyhedra.core.artifacts import JsonArtifactRef | |
| from polyhedra.services.evidence_verifier import EvidenceSource | |
| from polyhedra.services.file_writer import ScopedFileWriter | |
| def resolve_data_fetch_evidence( | |
| manifest: DataFetcherOutput, | |
| market_data: list[MarketDataArtifact], | |
| files: ScopedFileWriter, | |
| ) -> tuple[list[EvidenceSource], list[JsonArtifactRef]]: | |
| """Bind typed DataFetcher values to their immutable published identities.""" | |
| manifest_ref = JsonArtifactRef( | |
| schema_version=manifest.schema_version, | |
| artifact_id=manifest.artifact_id, | |
| run_id=manifest.run_id, | |
| session_id=manifest.session_id, | |
| producer="DataFetcher", | |
| path=f"quant/runs/{manifest.run_id}/data_fetch.json", | |
| ) | |
| sources = [EvidenceSource(manifest_ref, manifest)] | |
| refs = [manifest_ref] | |
| result_by_ticker = {item.ticker: item for item in manifest.ticker_results} | |
| for market in market_data: | |
| result = result_by_ticker[market.ticker] | |
| reference = result.market_data_ref | |
| if reference is None: | |
| raise ValueError("analysis requires each market-data artifact reference") | |
| if ( | |
| reference.schema_version, | |
| reference.artifact_id, | |
| reference.run_id, | |
| reference.session_id, | |
| reference.producer, | |
| ) != ( | |
| market.schema_version, | |
| market.artifact_id, | |
| market.run_id, | |
| market.session_id, | |
| market.producer, | |
| ): | |
| raise ValueError("market-data contents contradict the DataFetcher reference") | |
| sources.append(EvidenceSource(reference, market)) | |
| refs.append(reference) | |
| for source in sources: | |
| if files.published_reference(source.reference.path) != source.reference: | |
| raise ValueError("DataFetcher input was not published through the scoped runtime") | |
| return sources, refs | |