-
Notifications
You must be signed in to change notification settings - Fork 27
x402 individual settlement updates #285
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -415,7 +415,11 @@ def completion( | |||||||||||||||||
| ) | ||||||||||||||||||
|
|
||||||||||||||||||
| print_llm_completion_result( | ||||||||||||||||||
| model_cid, completion_output.transaction_hash, completion_output.completion_output, is_vanilla=False, result=completion_output | ||||||||||||||||||
| model_cid, | ||||||||||||||||||
| completion_output.data_settlement_transaction_hash, | ||||||||||||||||||
| completion_output.completion_output, | ||||||||||||||||||
| is_vanilla=False, | ||||||||||||||||||
| result=completion_output, | ||||||||||||||||||
| ) | ||||||||||||||||||
|
Comment on lines
417
to
423
|
||||||||||||||||||
|
|
||||||||||||||||||
| except Exception as e: | ||||||||||||||||||
|
|
@@ -603,7 +607,12 @@ def chat( | |||||||||||||||||
| print_streaming_chat_result(model_cid, result, is_tee=True) | ||||||||||||||||||
| else: | ||||||||||||||||||
| print_llm_chat_result( | ||||||||||||||||||
| model_cid, result.transaction_hash, result.finish_reason, result.chat_output, is_vanilla=False, result=result | ||||||||||||||||||
| model_cid, | ||||||||||||||||||
| result.data_settlement_transaction_hash, | ||||||||||||||||||
| result.finish_reason, | ||||||||||||||||||
| result.chat_output, | ||||||||||||||||||
| is_vanilla=False, | ||||||||||||||||||
| result=result, | ||||||||||||||||||
| ) | ||||||||||||||||||
|
||||||||||||||||||
| ) | |
| ) | |
| settlement_tx_hash = getattr(result, "data_settlement_transaction_hash", None) | |
| settlement_blob_id = getattr(result, "data_settlement_blob_id", None) | |
| if settlement_tx_hash: | |
| click.echo(f"Settlement tx hash: {settlement_tx_hash}") | |
| if settlement_blob_id: | |
| click.echo(f"Settlement blob id: {settlement_blob_id}") |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -28,6 +28,8 @@ | |
| DEFAULT_TEE_REGISTRY_ADDRESS = "0x4e72238852f3c918f4E4e57AeC9280dDB0c80248" | ||
|
|
||
| X402_PROCESSING_HASH_HEADER = "x-processing-hash" | ||
| X402_DATA_SETTLEMENT_TX_HASH_HEADER = "x-settlement-tx-hash" | ||
| X402_DATA_SETTLEMENT_BLOB_ID_HEADER = "x-settlement-walrus-blob-id" | ||
| X402_PLACEHOLDER_API_KEY = "0x1234567890abcdef1234567890abcdef1234567890abcdef1234567890abcdef" | ||
| BASE_MAINNET_NETWORK = "eip155:8453" | ||
| BASE_MAINNET_RPC = os.getenv("BASE_MAINNET_RPC", "https://base-rpc.publicnode.com") | ||
|
|
@@ -285,7 +287,8 @@ async def _request() -> TextGenerationOutput: | |
| raw_body = await response.aread() | ||
| result = json.loads(raw_body.decode()) | ||
| return TextGenerationOutput( | ||
| transaction_hash="external", | ||
| data_settlement_transaction_hash=response.headers.get(X402_DATA_SETTLEMENT_TX_HASH_HEADER), | ||
| data_settlement_blob_id=response.headers.get(X402_DATA_SETTLEMENT_BLOB_ID_HEADER), | ||
| completion_output=result.get("completion"), | ||
|
Comment on lines
289
to
292
|
||
| tee_signature=result.get("tee_signature"), | ||
| tee_timestamp=result.get("tee_timestamp"), | ||
|
|
@@ -337,7 +340,7 @@ async def chat( | |
|
|
||
| Returns: | ||
| Union[TextGenerationOutput, AsyncGenerator[StreamChunk, None]]: | ||
| - If stream=False: TextGenerationOutput with chat_output, transaction_hash, finish_reason, and payment_hash | ||
| - If stream=False: TextGenerationOutput with chat_output, data settlement metadata, finish_reason, and payment_hash | ||
| - If stream=True: Async generator yielding StreamChunk objects | ||
|
|
||
| Raises: | ||
|
|
@@ -408,7 +411,8 @@ async def _request() -> TextGenerationOutput: | |
| ).strip() | ||
|
|
||
| return TextGenerationOutput( | ||
| transaction_hash="external", | ||
| data_settlement_transaction_hash=response.headers.get(X402_DATA_SETTLEMENT_TX_HASH_HEADER), | ||
| data_settlement_blob_id=response.headers.get(X402_DATA_SETTLEMENT_BLOB_ID_HEADER), | ||
| finish_reason=choices[0].get("finish_reason"), | ||
| chat_output=message, | ||
| usage=result.get("usage"), | ||
|
|
@@ -447,6 +451,8 @@ async def _chat_tools_as_stream(self, params: _ChatParams, messages: List[Dict]) | |
| tee_id=result.tee_id, | ||
| tee_endpoint=result.tee_endpoint, | ||
| tee_payment_address=result.tee_payment_address, | ||
| data_settlement_transaction_hash=result.data_settlement_transaction_hash, | ||
| data_settlement_blob_id=result.data_settlement_blob_id, | ||
| ) | ||
|
|
||
| async def _chat_stream(self, params: _ChatParams, messages: List[Dict]) -> AsyncGenerator[StreamChunk, None]: | ||
|
|
@@ -535,6 +541,8 @@ async def _parse_sse_response(self, response, tee) -> AsyncGenerator[StreamChunk | |
|
|
||
| chunk = StreamChunk.from_sse_data(data) | ||
| if chunk.is_final: | ||
| chunk.data_settlement_transaction_hash = response.headers.get(X402_DATA_SETTLEMENT_TX_HASH_HEADER) | ||
| chunk.data_settlement_blob_id = response.headers.get(X402_DATA_SETTLEMENT_BLOB_ID_HEADER) | ||
|
Comment on lines
543
to
+545
|
||
| chunk.tee_id = tee.tee_id | ||
| chunk.tee_endpoint = tee.endpoint | ||
| chunk.tee_payment_address = tee.payment_address | ||
|
|
||
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Uh oh!
There was an error while loading. Please reload this page.