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

Basic NFT functionality in agentTown #120

Open
wants to merge 1 commit into
base: kresimir/ai
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 13 additions & 5 deletions contracts/contracts/AiTownAgent.sol
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,10 @@ pragma solidity ^0.8.9;
// Uncomment this line to use console.log
// import "hardhat/console.sol";
import "./interfaces/IOracle.sol";
import "@openzeppelin/contracts/token/ERC1155/ERC1155.sol";

// @title AiTownAgent
contract AiTownAgent {
contract AiTownAgent is ERC1155 {

struct ChatRun {
address owner;
Expand All @@ -25,7 +26,7 @@ contract AiTownAgent {

// @notice Address of the contract owner
address private owner;

// @notice Address of the oracle contract
address public oracleAddress;

Expand All @@ -37,7 +38,9 @@ contract AiTownAgent {

// @param initialOracleAddress Initial address of the oracle contract
// @param systemPrompt System prompt for the run
constructor(address initialOracleAddress, string memory _systemPrompt) {
constructor(address initialOracleAddress, string memory _systemPrompt, string memory _tokenUri)
ERC1155(_tokenUri)
{
owner = msg.sender;
oracleAddress = initialOracleAddress;
systemPrompt = _systemPrompt;
Expand Down Expand Up @@ -96,6 +99,11 @@ contract AiTownAgent {
IOracle.Message memory newMessage = createTextMessage("assistant", response);
run.messages.push(newMessage);
run.messagesCount++;

if (run.messagesCount == 7 && this.balanceOf(run.owner, 0) == 0) {
// token_id:0, amount: 1
_mint(run.owner, 0, 1, "");
}
}

function addMessage(string memory message, string memory conversationId) public {
Expand Down Expand Up @@ -127,8 +135,8 @@ contract AiTownAgent {

function createTextMessage(string memory role, string memory content) private pure returns (IOracle.Message memory) {
IOracle.Message memory newMessage = IOracle.Message({
role: role,
content: new IOracle.Content[](1)
role : role,
content : new IOracle.Content[](1)
});
newMessage.content[0].contentType = "text";
newMessage.content[0].value = content;
Expand Down