Skip to content
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

Implement smart contract for model feedback signal #529

Open
abrichr opened this issue Nov 21, 2023 · 3 comments
Open

Implement smart contract for model feedback signal #529

abrichr opened this issue Nov 21, 2023 · 3 comments
Labels
enhancement New feature or request

Comments

@abrichr
Copy link
Member

abrichr commented Nov 21, 2023

Feature request

This task involves implementing a smart contract to represent the "feedback" of a "human" to an "output" of a "model" via an "agent", where "feedback" is the human feedback on the quality of an agent's behavior and/or the raw output of the model.

Motivation

Ultimately we want to improve the behavior of one or more Agents, currently implemented as ReplayStrategies.

Yoshua Bengio had a nice short paper on his old website about how intelligence can't exist in an individual, and a collective is necessary for intelligence nodes to interact with each other.

(Sadly looks like it wasn't saved [ https://archive.is/http://iro.umontreal.ca/~bengioy/ ]; see https://arxiv.org/abs/1203.2990 for something possibly related)

One of the ideas was that language is obviously a pretty big component of AGI, and that language would not have been possible without having cooperation.

Tools are also clearly important (e.g. https://openai.com/research/emergent-tool-use; you are reading this through a tool).

Perhaps human intelligence evolution can inform hierarchy :

  • tools (e.g. "embodiment" / "agency" -> "a rock" / "a click")
  • vision and language (i.e. LMMs)
  • cooperation (i.e. reward)

Cooperation between humans involves love, pain, capital. What does cooperation between humans and LLMs look like?

Feedback welcome!

Related:

#393
#61

@abrichr abrichr added the enhancement New feature or request label Nov 21, 2023
@abrichr abrichr changed the title Implement feedback smart contract for model feedback signal Implement smart contract for model feedback signal Nov 21, 2023
@abrichr
Copy link
Member Author

abrichr commented Nov 21, 2023

Since ChatGPT is down, here is Cohere.ai's response for the following prompt:

Implement solidity code that implements a smart contract to represent the "feedback" of a "human" to an "output" of a "model" via an "agent", where "feedback" is the human feedback on the quality of an agent's behavior and/or the raw output of the model.


Here's an example implementation of a smart contract in Solidity that represents the feedback of a human to an output of a model via an agent:

// FeedbackContract.sol

pragma solidity >=0.7.0;

interface Agent {
    function getOutput() external view returns (bytes);
}

contract Feedback {
    Event NewFeedback(address indexed human, address indexed agent, bytes feedback);

    // Array to store feedback entries
    mapping(address => bytes[]) public feedbackRecords;

    // Array to store all agents
    address[] public agents;

    // Add an agent to the array of agents
    function addAgent(address _agent) public {
        agents.push(_agent);
    }

    // Remove an agent from the array of agents
    function removeAgent(address _agent) public {
        // Using delete to remove agent from agents array
        agents.delete(_agent);
    }

    // Function for a human to give feedback on an agent's output
    function giveFeedback(address _human, address _agent, bytes memory feedback) public {
        require(_human != address(0));    // Check if the sender is a valid human
        require(_agent != address(0));   // Check if the sender is a valid agent
        require(agents.includes(_agent)); // Check if the agent is registered

        // Store the feedback
        feedbackRecords[_human].push(feedback);
        
        // Emit the NewFeedback event
        emit NewFeedback(_human, _agent, feedback);
    }

    // Function to retrieve feedback given by a human for a specific agent
    function getFeedback(address _human, address _agent) external view returns (bytes[]) {
        require(_human != address(0)); // Check if the input is a valid human address
        require(_agent != address(0));  // Check if the input is a valid agent address
        
        // Return the feedback bytes array for the given human and agent
        return feedbackRecords[_human];
    }

    // Function to retrieve the number of feedback entries for a specific human and agent
    function getFeedbackCount(address _human, address _agent) external view returns (uint) {
        require(_human != address(0)); // Check if the input is a valid human address
        require(_agent != address(0));  // Check if the input is a valid agent address

        // Return the length of the feedbackRecords array for the given human and agent
        return feedbackRecords[_human].length;
    }
}

// SampleAgent.sol

pragma solidity >=0.7.0;

interface Agent {
    function getOutput() external view returns (bytes);
}

contract SampleAgent is Agent {
    bytes constant readonly output = "Sample agent's output";

    function getOutput() external view returns (bytes) {
        return output;
    }
}

This smart contract encapsulates the feedback functionality between humans, agents, and models. Humans provide feedback via the giveFeedback method, targeting a specific agent and including their thoughts in bytes format. The addAgent method facilitates the addition of agents to the contract, while removeAgent enables the removal of inactive agents. The feedback records are stored in the feedbackRecords mapping, with each human's feedback linked to the respective agent.

The SampleAgent contract, which implements the Agent interface, serves as an example of an agent that provides a predefined output. You can integrate this contract with your model to establish the connection between model outputs and human feedback.

Please note that this is a basic example for illustrative purposes. Depending on your specific requirements, you may need to extend, modify, or adapt this code to cater to more complex use cases and considerations.

@abrichr
Copy link
Member Author

abrichr commented Dec 14, 2023

Implement solidity code that implements a smart contract to represent the "feedback" of a "human" to an "output" of a "model" via an "agent", where "feedback" is the human feedback on the quality of an agent's behavior and/or the raw output of the model.

ChatGPT:


To implement a Solidity smart contract that represents the feedback of a human to an output of a model via an agent, we need to define a few key concepts:

  1. Agent: This could be represented as an address that interacts with the smart contract.
  2. Model Output: This can be represented as a struct or a mapping, storing the outputs generated by the model.
  3. Feedback: This will be the human's input about the quality of the agent's behavior or the model's output.

The contract will have functions to:

  • Record a new output from the model.
  • Allow a human to provide feedback on a specific output.
  • Retrieve the feedback and details of a specific output.

Here's a basic implementation in Solidity:

// SPDX-License-Identifier: MIT
pragma solidity ^0.8.0;

contract FeedbackContract {

    // A struct to hold the details of a model output
    struct ModelOutput {
        uint256 id;
        address agent;
        string output;
    }

    // A struct to hold feedback details
    struct Feedback {
        uint256 outputId;
        address human;
        string comment;
        uint8 rating; // A rating from 1 to 5
    }

    // State variables
    ModelOutput[] public modelOutputs;
    Feedback[] public feedbacks;

    // Mapping from output ID to its feedback
    mapping(uint256 => Feedback) public feedbackByOutput;

    // Function to record a new model output
    function recordOutput(address agent, string memory output) public {
        modelOutputs.push(ModelOutput(modelOutputs.length, agent, output));
    }

    // Function to add feedback to a model output
    function addFeedback(uint256 outputId, string memory comment, uint8 rating) public {
        require(rating >= 1 && rating <= 5, "Rating should be between 1 and 5");
        require(outputId < modelOutputs.length, "Invalid output ID");

        Feedback memory newFeedback = Feedback(outputId, msg.sender, comment, rating);
        feedbacks.push(newFeedback);
        feedbackByOutput[outputId] = newFeedback;
    }

    // Function to retrieve a specific model output
    function getModelOutput(uint256 outputId) public view returns (ModelOutput memory) {
        require(outputId < modelOutputs.length, "Invalid output ID");
        return modelOutputs[outputId];
    }

    // Function to retrieve feedback for a specific model output
    function getFeedback(uint256 outputId) public view returns (Feedback memory) {
        require(outputId < modelOutputs.length, "Invalid output ID");
        return feedbackByOutput[outputId];
    }
}

This contract allows an agent to record outputs of a model, and humans can provide feedback on these outputs. Each output and feedback is stored in arrays, and there's a mapping to link feedback directly to a model output. The contract includes basic validation for the input data. This is a simple structure and can be expanded or modified based on specific requirements.

@abrichr
Copy link
Member Author

abrichr commented Dec 14, 2023

So how can we integrate mor.org into https://github.com/OpenAdaptAI/OpenAdapt -- for example, to implement a smart contract to represent the "feedback" of a "human" to an "output" of a "model" via an "agent", where "feedback" is the human feedback on the quality of an agent's behavior and/or the raw output of the model.

ChatGPT:


Integrating Morpheus (mor.org) with OpenAdaptAI (https://github.com/OpenAdaptAI/OpenAdapt) for feedback representation involves a few steps:

  1. Smart Agent Integration: Use Morpheus to create or utilize existing Smart Agents that can interact with the OpenAdaptAI model. These agents can facilitate communication between the human users and the AI model.

  2. Feedback Mechanism: Develop a smart contract on Morpheus that captures human feedback. This contract would record the human's input about the quality of the agent's behavior or the model's output.

  3. Model Output Handling: Ensure the smart contract can process and store the outputs from the OpenAdaptAI model, making them accessible to the Smart Agents.

  4. Interaction Flow: Design the interaction flow so that when a model output is generated, the Smart Agent presents it to the human user. The user's feedback is then captured and recorded in the smart contract.

  5. Data Management: Utilize Morpheus's decentralized infrastructure for managing the data flow and storage, ensuring privacy and security.

  6. APIs and Cloud Functions: Leverage Morpheus's APIs and cloud functions for seamless integration and scalability of the feedback mechanism.

By combining OpenAdaptAI's capabilities with Morpheus's decentralized AI infrastructure and Smart Agents, a robust, user-friendly system for human feedback on AI model outputs can be established.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

1 participant