-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Implement service queries for chat completions (#1)
* Add a `chat_log` field to the state Prepare to keep a chat transcript on chain. * Add an operation to log a chat interaction Update the on-chain chat transcript with the new interaction. * Test logging some chat interactions Ensure that they are stored in the state on chain. * Change the service to handle GraphQL requests For now no requests are actually handled. * Add a `runtime` field to the `ApplicationService` Prepare to perform HTTP queries. * Add a mutation to perform a chat interaction Creates an operation to log a chat interaction, but for now the response is empty. * Implement querying of chat completion API Send an HTTP request to the Atoma network to retrieve a chat completion. * Create a `ChatInteractionResponse` type A helper type to parse the `ChatCompletionResponse` and later build a `ChatInteraction`. * Fetch chat completion to log to chat transcript Include a real response from the Atoma network in the operation to log a chat interaction. * Test if `chat` mutation performs HTTP request Ensure that a `chat` mutation leads to the service sending an HTTP request to the Atoma proxy, and returning an operation to log the chat interaction. * Downgrade Rust version to workaround Wasm issue Use a version known to be able to run Wasm contracts. * Add an integration test for the API query Ensure that the API queries from the service work correctly.
- Loading branch information
Showing
10 changed files
with
544 additions
and
35 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,5 @@ | ||
[toolchain] | ||
channel = "1.84.0" | ||
channel = "1.81.0" | ||
components = [ "clippy", "rustfmt", "rust-src" ] | ||
targets = [ "wasm32-unknown-unknown" ] | ||
profile = "minimal" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
// Copyright (c) Zefchain Labs, Inc. | ||
// SPDX-License-Identifier: Apache-2.0 | ||
|
||
use atoma_demo::{ChatInteraction, Operation}; | ||
use linera_sdk::{util::BlockingWait, Contract, ContractRuntime}; | ||
use test_strategy::proptest; | ||
|
||
use super::ApplicationContract; | ||
|
||
/// Tests if chat interactions are logged on chain. | ||
#[proptest] | ||
fn chat_interactions_are_logged_on_chain(interactions: Vec<ChatInteraction>) { | ||
let mut contract = setup_contract(); | ||
|
||
for interaction in interactions.clone() { | ||
contract | ||
.execute_operation(Operation::LogChatInteraction { interaction }) | ||
.blocking_wait(); | ||
} | ||
|
||
let logged_interactions = contract | ||
.state | ||
.chat_log | ||
.read(..) | ||
.blocking_wait() | ||
.expect("Failed to read logged chat interactions from the state"); | ||
|
||
assert_eq!(logged_interactions, interactions); | ||
} | ||
|
||
/// Creates a [`ApplicationContract`] instance to be tested. | ||
fn setup_contract() -> ApplicationContract { | ||
let runtime = ContractRuntime::new(); | ||
|
||
ApplicationContract::load(runtime).blocking_wait() | ||
} |
Oops, something went wrong.