diff --git a/contracts/contracts/ChatGpt.sol b/contracts/contracts/ChatGpt.sol index 9f569ae..bc32a7a 100644 --- a/contracts/contracts/ChatGpt.sol +++ b/contracts/contracts/ChatGpt.sol @@ -32,16 +32,10 @@ contract ChatGpt { // @notice Address of the oracle contract address public oracleAddress; - - // @notice Configuration for the LLM request - IOracle.LlmRequest private config; // @notice CID of the knowledge base string public knowledgeBase; - // @notice Mapping from chat ID to the tool currently running - mapping(uint => string) public toolRunning; - // @notice Event emitted when the oracle address is updated event OracleAddressUpdated(address indexed newOracleAddress); @@ -51,22 +45,6 @@ contract ChatGpt { owner = msg.sender; oracleAddress = initialOracleAddress; knowledgeBase = knowledgeBaseCID; - - config = IOracle.LlmRequest({ - model : "claude-3-5-sonnet-20240620", - frequencyPenalty : 21, // > 20 for null - logitBias : "", // empty str for null - maxTokens : 1000, // 0 for null - presencePenalty : 21, // > 20 for null - responseFormat : "{\"type\":\"text\"}", - seed : 0, // null - stop : "", // null - temperature : 10, // Example temperature (scaled up, 10 means 1.0), > 20 means null - topP : 101, // Percentage 0-100, > 100 means null - tools : "[{\"type\":\"function\",\"function\":{\"name\":\"web_search\",\"description\":\"Search the internet\",\"parameters\":{\"type\":\"object\",\"properties\":{\"query\":{\"type\":\"string\",\"description\":\"Search query\"}},\"required\":[\"query\"]}}},{\"type\":\"function\",\"function\":{\"name\":\"code_interpreter\",\"description\":\"Evaluates python code in a sandbox environment. The environment resets on every execution. You must send the whole script every time and print your outputs. Script should be pure python code that can be evaluated. It should be in python format NOT markdown. The code should NOT be wrapped in backticks. All python packages including requests, matplotlib, scipy, numpy, pandas, etc are available. Output can only be read from stdout, and stdin. Do not use things like plot.show() as it will not work. print() any output and results so you can capture the output.\",\"parameters\":{\"type\":\"object\",\"properties\":{\"code\":{\"type\":\"string\",\"description\":\"The pure python script to be evaluated. The contents will be in main.py. It should not be in markdown format.\"}},\"required\":[\"code\"]}}}]", - toolChoice : "auto", // "none" or "auto" - user : "" // null - }); } // @notice Ensures the caller is the contract owner @@ -114,7 +92,7 @@ contract ChatGpt { ); } else { // Otherwise, create an LLM call - IOracle(oracleAddress).createLlmCall(currentId, config); + IOracle(oracleAddress).createLlmCall(currentId); } emit ChatCreated(msg.sender, currentId); @@ -127,8 +105,8 @@ contract ChatGpt { // @dev Called by teeML oracle function onOracleLlmResponse( uint runId, - IOracle.LlmResponse memory response, - string memory errorMessage + string memory response, + string memory /*errorMessage*/ ) public onlyOracle { ChatRun storage run = chatRuns[runId]; require( @@ -137,48 +115,10 @@ contract ChatGpt { ); Message memory newMessage; - if (!compareStrings(errorMessage, "")) { - newMessage.role = "assistant"; - newMessage.content = errorMessage; - run.messages.push(newMessage); - run.messagesCount++; - } else { - if (!compareStrings(response.functionName, "")) { - toolRunning[runId] = response.functionName; - IOracle(oracleAddress).createFunctionCall(runId, response.functionName, response.functionArguments); - } else { - toolRunning[runId] = ""; - } - newMessage.role = "assistant"; - newMessage.content = response.content; - run.messages.push(newMessage); - run.messagesCount++; - } - } - - // @notice Handles the response from the oracle for a function call - // @param runId The ID of the chat run - // @param response The response from the oracle - // @param errorMessage Any error message - // @dev Called by teeML oracle - function onOracleFunctionResponse( - uint runId, - string memory response, - string memory errorMessage - ) public onlyOracle { - require( - !compareStrings(toolRunning[runId], ""), - "No function to respond to" - ); - ChatRun storage run = chatRuns[runId]; - if (compareStrings(errorMessage, "")) { - Message memory newMessage; - newMessage.role = "user"; - newMessage.content = response; - run.messages.push(newMessage); - run.messagesCount++; - IOracle(oracleAddress).createLlmCall(runId, config); - } + newMessage.content = response; + newMessage.role = "assistant"; + run.messages.push(newMessage); + run.messagesCount++; } // @notice Handles the response from the oracle for a knowledge base query @@ -215,7 +155,7 @@ contract ChatGpt { lastMessage.content = newContent; // Call LLM - IOracle(oracleAddress).createLlmCall(runId, config); + IOracle(oracleAddress).createLlmCall(runId); } // @notice Adds a new message to an existing chat run @@ -246,7 +186,7 @@ contract ChatGpt { ); } else { // Otherwise, create an LLM call - IOracle(oracleAddress).createLlmCall(runId, config); + IOracle(oracleAddress).createLlmCall(runId); } } @@ -273,12 +213,4 @@ contract ChatGpt { } return roles; } - - // @notice Compares two strings for equality - // @param a The first string - // @param b The second string - // @return True if the strings are equal, false otherwise - function compareStrings(string memory a, string memory b) private pure returns (bool) { - return (keccak256(abi.encodePacked((a))) == keccak256(abi.encodePacked((b)))); - } } diff --git a/contracts/contracts/GroqChatGpt.sol b/contracts/contracts/GroqChatGpt.sol index caea3c7..349028e 100644 --- a/contracts/contracts/GroqChatGpt.sol +++ b/contracts/contracts/GroqChatGpt.sol @@ -33,14 +33,11 @@ contract GroqChatGpt { // @notice Address of the oracle contract address public oracleAddress; - // @notice Mapping from chat ID to the tool currently running - mapping(uint => string) public toolRunning; - // @notice Event emitted when the oracle address is updated event OracleAddressUpdated(address indexed newOracleAddress); - // @notice Configuration for the LLM request - IOracle.LlmRequest private config; + // @notice Configuration for the Groq request + IOracle.GroqRequest private config; // @param initialOracleAddress Initial address of the oracle contract constructor(address initialOracleAddress) { @@ -48,7 +45,7 @@ contract GroqChatGpt { oracleAddress = initialOracleAddress; chatRunsCount = 0; - config = IOracle.LlmRequest({ + config = IOracle.GroqRequest({ model : "mixtral-8x7b-32768", frequencyPenalty : 21, // > 20 for null logitBias : "", // empty str for null @@ -59,8 +56,6 @@ contract GroqChatGpt { stop : "", // null temperature : 10, // Example temperature (scaled up, 10 means 1.0), > 20 means null topP : 101, // Percentage 0-100, > 100 means null - tools : "[{\"type\":\"function\",\"function\":{\"name\":\"web_search\",\"description\":\"Search the internet\",\"parameters\":{\"type\":\"object\",\"properties\":{\"query\":{\"type\":\"string\",\"description\":\"Search query\"}},\"required\":[\"query\"]}}},{\"type\":\"function\",\"function\":{\"name\":\"code_interpreter\",\"description\":\"Evaluates python code in a sandbox environment. The environment resets on every execution. You must send the whole script every time and print your outputs. Script should be pure python code that can be evaluated. It should be in python format NOT markdown. The code should NOT be wrapped in backticks. All python packages including requests, matplotlib, scipy, numpy, pandas, etc are available. Output can only be read from stdout, and stdin. Do not use things like plot.show() as it will not work. print() any output and results so you can capture the output.\",\"parameters\":{\"type\":\"object\",\"properties\":{\"code\":{\"type\":\"string\",\"description\":\"The pure python script to be evaluated. The contents will be in main.py. It should not be in markdown format.\"}},\"required\":[\"code\"]}}}]", - toolChoice : "auto", // "none" or "auto" user : "" // null }); } @@ -99,20 +94,20 @@ contract GroqChatGpt { uint currentId = chatRunsCount; chatRunsCount = chatRunsCount + 1; - IOracle(oracleAddress).createLlmCall(currentId, config); + IOracle(oracleAddress).createGroqLlmCall(currentId, config); emit ChatCreated(msg.sender, currentId); return currentId; } - // @notice Handles the response from the oracle for an LLM call + // @notice Handles the response from the oracle for a Groq LLM call // @param runId The ID of the chat run // @param response The response from the oracle // @param errorMessage Any error message // @dev Called by teeML oracle - function onOracleLlmResponse( + function onOracleGroqLlmResponse( uint runId, - IOracle.LlmResponse memory response, + IOracle.GroqResponse memory response, string memory errorMessage ) public onlyOracle { ChatRun storage run = chatRuns[runId]; @@ -127,12 +122,6 @@ contract GroqChatGpt { run.messages.push(newMessage); run.messagesCount++; } else { - if (!compareStrings(response.functionName, "")) { - toolRunning[runId] = response.functionName; - IOracle(oracleAddress).createFunctionCall(runId, response.functionName, response.functionArguments); - } else { - toolRunning[runId] = ""; - } Message memory newMessage; newMessage.role = "assistant"; newMessage.content = response.content; @@ -141,31 +130,6 @@ contract GroqChatGpt { } } - // @notice Handles the response from the oracle for a function call - // @param runId The ID of the chat run - // @param response The response from the oracle - // @param errorMessage Any error message - // @dev Called by teeML oracle - function onOracleFunctionResponse( - uint runId, - string memory response, - string memory errorMessage - ) public onlyOracle { - require( - !compareStrings(toolRunning[runId], ""), - "No function to respond to" - ); - ChatRun storage run = chatRuns[runId]; - if (compareStrings(errorMessage, "")) { - Message memory newMessage; - newMessage.role = "user"; - newMessage.content = response; - run.messages.push(newMessage); - run.messagesCount++; - IOracle(oracleAddress).createLlmCall(runId, config); - } - } - // @notice Adds a new message to an existing chat run // @param message The new message to add // @param runId The ID of the chat run @@ -185,7 +149,7 @@ contract GroqChatGpt { run.messages.push(newMessage); run.messagesCount++; - IOracle(oracleAddress).createLlmCall(runId, config); + IOracle(oracleAddress).createGroqLlmCall(runId, config); } // @notice Retrieves the message history contents of a chat run diff --git a/contracts/contracts/OpenAiChatGpt.sol b/contracts/contracts/OpenAiChatGpt.sol index e857159..5a94f78 100644 --- a/contracts/contracts/OpenAiChatGpt.sol +++ b/contracts/contracts/OpenAiChatGpt.sol @@ -33,14 +33,11 @@ contract OpenAiChatGpt { // @notice Address of the oracle contract address public oracleAddress; - // @notice Mapping from chat ID to the tool currently running - mapping(uint => string) public toolRunning; - // @notice Event emitted when the oracle address is updated event OracleAddressUpdated(address indexed newOracleAddress); - // @notice Configuration for the LLM request - IOracle.LlmRequest private config; + // @notice Configuration for the OpenAI request + IOracle.OpenAiRequest private config; // @param initialOracleAddress Initial address of the oracle contract constructor(address initialOracleAddress) { @@ -48,20 +45,20 @@ contract OpenAiChatGpt { oracleAddress = initialOracleAddress; chatRunsCount = 0; - config = IOracle.LlmRequest({ - model : "gpt-4-turbo-preview", - frequencyPenalty : 21, // > 20 for null - logitBias : "", // empty str for null - maxTokens : 1000, // 0 for null - presencePenalty : 21, // > 20 for null - responseFormat : "{\"type\":\"text\"}", - seed : 0, // null - stop : "", // null - temperature : 10, // Example temperature (scaled up, 10 means 1.0), > 20 means null - topP : 101, // Percentage 0-100, > 100 means null - tools : "[{\"type\":\"function\",\"function\":{\"name\":\"web_search\",\"description\":\"Search the internet\",\"parameters\":{\"type\":\"object\",\"properties\":{\"query\":{\"type\":\"string\",\"description\":\"Search query\"}},\"required\":[\"query\"]}}},{\"type\":\"function\",\"function\":{\"name\":\"code_interpreter\",\"description\":\"Evaluates python code in a sandbox environment. The environment resets on every execution. You must send the whole script every time and print your outputs. Script should be pure python code that can be evaluated. It should be in python format NOT markdown. The code should NOT be wrapped in backticks. All python packages including requests, matplotlib, scipy, numpy, pandas, etc are available. Output can only be read from stdout, and stdin. Do not use things like plot.show() as it will not work. print() any output and results so you can capture the output.\",\"parameters\":{\"type\":\"object\",\"properties\":{\"code\":{\"type\":\"string\",\"description\":\"The pure python script to be evaluated. The contents will be in main.py. It should not be in markdown format.\"}},\"required\":[\"code\"]}}}]", - toolChoice : "auto", // "none" or "auto" - user : "" // null + config = IOracle.OpenAiRequest({ + model : "gpt-4-turbo-preview", + frequencyPenalty : 21, // > 20 for null + logitBias : "", // empty str for null + maxTokens : 1000, // 0 for null + presencePenalty : 21, // > 20 for null + responseFormat : "{\"type\":\"text\"}", + seed : 0, // null + stop : "", // null + temperature : 10, // Example temperature (scaled up, 10 means 1.0), > 20 means null + topP : 101, // Percentage 0-100, > 100 means null + tools : "[{\"type\":\"function\",\"function\":{\"name\":\"web_search\",\"description\":\"Search the internet\",\"parameters\":{\"type\":\"object\",\"properties\":{\"query\":{\"type\":\"string\",\"description\":\"Search query\"}},\"required\":[\"query\"]}}},{\"type\":\"function\",\"function\":{\"name\":\"code_interpreter\",\"description\":\"Evaluates python code in a sandbox environment. The environment resets on every execution. You must send the whole script every time and print your outputs. Script should be pure python code that can be evaluated. It should be in python format NOT markdown. The code should NOT be wrapped in backticks. All python packages including requests, matplotlib, scipy, numpy, pandas, etc are available. Output can only be read from stdout, and stdin. Do not use things like plot.show() as it will not work. print() any output and results so you can capture the output.\",\"parameters\":{\"type\":\"object\",\"properties\":{\"code\":{\"type\":\"string\",\"description\":\"The pure python script to be evaluated. The contents will be in main.py. It should not be in markdown format.\"}},\"required\":[\"code\"]}}}]", + toolChoice : "auto", // "none" or "auto" + user : "" // null }); } @@ -100,20 +97,20 @@ contract OpenAiChatGpt { uint currentId = chatRunsCount; chatRunsCount = chatRunsCount + 1; - IOracle(oracleAddress).createLlmCall(currentId, config); + IOracle(oracleAddress).createOpenAiLlmCall(currentId, config); emit ChatCreated(msg.sender, currentId); return currentId; } - // @notice Handles the response from the oracle for an LLM call + // @notice Handles the response from the oracle for an OpenAI LLM call // @param runId The ID of the chat run // @param response The response from the oracle // @param errorMessage Any error message // @dev Called by teeML oracle - function onOracleLlmResponse( + function onOracleOpenAiLlmResponse( uint runId, - IOracle.LlmResponse memory response, + IOracle.OpenAiResponse memory response, string memory errorMessage ) public onlyOracle { ChatRun storage run = chatRuns[runId]; @@ -129,17 +126,15 @@ contract OpenAiChatGpt { run.messages.push(newMessage); run.messagesCount++; } else { - if (!compareStrings(response.functionName, "")) { - toolRunning[runId] = response.functionName; + if (compareStrings(response.content, "")) { IOracle(oracleAddress).createFunctionCall(runId, response.functionName, response.functionArguments); } else { - toolRunning[runId] = ""; + Message memory newMessage; + newMessage.role = "assistant"; + newMessage.content = response.content; + run.messages.push(newMessage); + run.messagesCount++; } - Message memory newMessage; - newMessage.role = "assistant"; - newMessage.content = response.content; - run.messages.push(newMessage); - run.messagesCount++; } } @@ -153,18 +148,18 @@ contract OpenAiChatGpt { string memory response, string memory errorMessage ) public onlyOracle { + ChatRun storage run = chatRuns[runId]; require( - !compareStrings(toolRunning[runId], ""), + compareStrings(run.messages[run.messagesCount - 1].role, "user"), "No function to respond to" ); - ChatRun storage run = chatRuns[runId]; if (compareStrings(errorMessage, "")) { Message memory newMessage; newMessage.role = "user"; newMessage.content = response; run.messages.push(newMessage); run.messagesCount++; - IOracle(oracleAddress).createLlmCall(runId, config); + IOracle(oracleAddress).createOpenAiLlmCall(runId, config); } } @@ -187,7 +182,7 @@ contract OpenAiChatGpt { run.messages.push(newMessage); run.messagesCount++; - IOracle(oracleAddress).createLlmCall(runId, config); + IOracle(oracleAddress).createOpenAiLlmCall(runId, config); } // @notice Retrieves the message history contents of a chat run diff --git a/contracts/contracts/OpenAiChatGptVision.sol b/contracts/contracts/OpenAiChatGptVision.sol index 2346ade..659e310 100644 --- a/contracts/contracts/OpenAiChatGptVision.sol +++ b/contracts/contracts/OpenAiChatGptVision.sol @@ -31,8 +31,8 @@ contract OpenAiChatGptVision { // @notice Event emitted when the oracle address is updated event OracleAddressUpdated(address indexed newOracleAddress); - // @notice Configuration for the LLM request - IOracle.LlmRequest private config; + // @notice Configuration for the OpenAI request + IOracle.OpenAiRequest private config; // @param initialOracleAddress Initial address of the oracle contract constructor(address initialOracleAddress) { @@ -40,7 +40,7 @@ contract OpenAiChatGptVision { oracleAddress = initialOracleAddress; chatRunsCount = 0; - config = IOracle.LlmRequest({ + config = IOracle.OpenAiRequest({ model : "gpt-4-turbo", frequencyPenalty : 21, // > 20 for null logitBias : "", // empty str for null @@ -104,20 +104,20 @@ contract OpenAiChatGptVision { uint currentId = chatRunsCount; chatRunsCount = chatRunsCount + 1; - IOracle(oracleAddress).createLlmCall(currentId, config); + IOracle(oracleAddress).createOpenAiLlmCall(currentId, config); emit ChatCreated(msg.sender, currentId); return currentId; } - // @notice Handles the response from the oracle for an LLM call + // @notice Handles the response from the oracle for an OpenAI LLM call // @param runId The ID of the chat run // @param response The response from the oracle // @param errorMessage Any error message // @dev Called by teeML oracle - function onOracleLlmResponse( + function onOracleOpenAiLlmResponse( uint runId, - IOracle.LlmResponse memory response, + IOracle.OpenAiResponse memory response, string memory errorMessage ) public onlyOracle { ChatRun storage run = chatRuns[runId]; @@ -169,7 +169,7 @@ contract OpenAiChatGptVision { run.messages.push(newMessage); run.messagesCount++; - IOracle(oracleAddress).createLlmCall(runId, config); + IOracle(oracleAddress).createOpenAiLlmCall(runId, config); } // @notice Retrieves the message history of a chat run diff --git a/contracts/contracts/Test.sol b/contracts/contracts/Test.sol index f36761e..51dd189 100644 --- a/contracts/contracts/Test.sol +++ b/contracts/contracts/Test.sol @@ -177,8 +177,6 @@ contract Test { stop : "", // null temperature : 10, // Example temperature (scaled up, 10 means 1.0), > 20 means null topP : 101, // Percentage 0-100, > 100 means null - tools : "", - toolChoice : "none", // "none" or "auto" user : "" // null }) ); diff --git a/contracts/contracts/Vitailik.sol b/contracts/contracts/Vitailik.sol index c37349b..1ff2db1 100644 --- a/contracts/contracts/Vitailik.sol +++ b/contracts/contracts/Vitailik.sol @@ -66,8 +66,6 @@ contract Vitailik { stop : "", // null temperature : 21, // Example temperature (scaled up, 10 means 1.0), > 20 means null topP : 101, // Percentage 0-100, > 100 means null - tools : "", - toolChoice : "", // "none" or "auto" user : "" // null }); } diff --git a/contracts/contracts/interfaces/IOracle.sol b/contracts/contracts/interfaces/IOracle.sol index 33ba91f..b2b288f 100644 --- a/contracts/contracts/interfaces/IOracle.sol +++ b/contracts/contracts/interfaces/IOracle.sol @@ -81,19 +81,13 @@ interface IOracle { uint temperature; // 0-100 percentage, > 100 for null uint topP; - string tools; - // "none", "auto" or empty str which defaults to auto on OpenAI side - string toolChoice; string user; } struct GroqResponse { string id; - // either content is an empty str or functionName and functionArguments string content; - string functionName; - string functionArguments; uint64 created; string model; diff --git a/contracts/test/ChatGpt.ts b/contracts/test/ChatGpt.ts index 3550bb0..5016064 100644 --- a/contracts/test/ChatGpt.ts +++ b/contracts/test/ChatGpt.ts @@ -43,22 +43,7 @@ describe("ChatGpt", function () { await oracle.updateWhitelist(oracleAccount, true); await chatGpt.startChat("Hello"); - - const response = { - id: "responseId", - content: "Hi", - functionName: "functionNameHere", - functionArguments: "functionArgumentsHere", - created: 1618888901, // Example UNIX timestamp - model: "gpt-4-turbo-preview", - systemFingerprint: "systemFingerprintHere", - object: "chat.completion", - completionTokens: 10, - promptTokens: 5, - totalTokens: 15 - }; - - await oracle.connect(oracleAccount).addResponse(0, 0, response, ""); + await oracle.connect(oracleAccount).addResponse(0, 0, "Hi", ""); const messages = await oracle.getMessages(0, 0) expect(messages.length).to.equal(2) expect(messages[1]).to.equal("Hi") @@ -75,20 +60,7 @@ describe("ChatGpt", function () { await oracle.updateWhitelist(oracleAccount, true); await chatGpt.startChat("Hello"); - const response = { - id: "responseId", - content: "Hi", - functionName: "functionNameHere", - functionArguments: "functionArgumentsHere", - created: 1618888901, // Example UNIX timestamp - model: "gpt-4-turbo-preview", - systemFingerprint: "systemFingerprintHere", - object: "chat.completion", - completionTokens: 10, - promptTokens: 5, - totalTokens: 15 - }; - await oracle.connect(oracleAccount).addResponse(0, 0, response, ""); + await oracle.connect(oracleAccount).addResponse(0, 0, "Hi", ""); await chatGpt.addMessage("message", 0); const messages = await oracle.getMessages(0, 0) @@ -113,24 +85,10 @@ describe("ChatGpt", function () { await oracle.updateWhitelist(oracleAccount, true); await chatGpt.startChat("Hello"); - - const response = { - id: "responseId", - content: "Hi", - functionName: "functionNameHere", - functionArguments: "functionArgumentsHere", - created: 1618888901, // Example UNIX timestamp - model: "gpt-4-turbo-preview", - systemFingerprint: "systemFingerprintHere", - object: "chat.completion", - completionTokens: 10, - promptTokens: 5, - totalTokens: 15 - }; - await oracle.connect(oracleAccount).addResponse(0, 0, response, ""); + await oracle.connect(oracleAccount).addResponse(0, 0, "Hi", ""); await oracle.connect(oracleAccount).markPromptAsProcessed(0); await expect( - oracle.connect(oracleAccount).addResponse(0, 0, response, "") + oracle.connect(oracleAccount).addResponse(0, 0, "Hi", "") ).to.be.revertedWith("Prompt already processed"); }); it("Oracle cannot add 2 responses", async () => { @@ -145,27 +103,14 @@ describe("ChatGpt", function () { await oracle.updateWhitelist(oracleAccount, true); await chatGpt.startChat("Hello"); - const response = { - id: "responseId", - content: "Hi", - functionName: "functionNameHere", - functionArguments: "functionArgumentsHere", - created: 1618888901, // Example UNIX timestamp - model: "gpt-4-turbo-preview", - systemFingerprint: "systemFingerprintHere", - object: "chat.completion", - completionTokens: 10, - promptTokens: 5, - totalTokens: 15 - }; - await oracle.connect(oracleAccount).addResponse(0, 0, response, ""); + await oracle.connect(oracleAccount).addResponse(0, 0, "Hi", ""); // Ultimate edge-case, user whitelisted some random address const randomAccount = allSigners[7]; await chatGpt.setOracleAddress(randomAccount); await expect( - chatGpt.connect(randomAccount).onOracleLlmResponse(0, response, "") + chatGpt.connect(randomAccount).onOracleLlmResponse(0, "Hi", "") ).to.be.revertedWith("No message to respond to"); }); diff --git a/contracts/test/GroqChatGpt.ts b/contracts/test/GroqChatGpt.ts index f24c2d6..04ca669 100644 --- a/contracts/test/GroqChatGpt.ts +++ b/contracts/test/GroqChatGpt.ts @@ -37,48 +37,8 @@ describe("GroqChatGpt", function () { await chatGpt.startChat("Hello"); // promptId: 0, callbackId: 0 - const groqConf = await oracle.llmConfigurations(0) - const tools = [ - { - "type": "function", - "function": { - "name": "web_search", - "description": "Search the internet", - "parameters": { - "type": "object", - "properties": { - "query": { - "type": "string", - "description": "Search query" - } - }, - "required": [ - "query" - ] - } - } - }, - { - "type": "function", - "function": { - "name": "code_interpreter", - "description": "Evaluates python code in a sandbox environment. The environment resets on every execution. You must send the whole script every time and print your outputs. Script should be pure python code that can be evaluated. It should be in python format NOT markdown. The code should NOT be wrapped in backticks. All python packages including requests, matplotlib, scipy, numpy, pandas, etc are available. Output can only be read from stdout, and stdin. Do not use things like plot.show() as it will not work. print() any output and results so you can capture the output.", - "parameters": { - "type": "object", - "properties": { - "code": { - "type": "string", - "description": "The pure python script to be evaluated. The contents will be in main.py. It should not be in markdown format." - } - }, - "required": [ - "code" - ] - } - } - } - ]; - expect(groqConf.toString()).to.equal(`mixtral-8x7b-32768,21,,1000,21,{\"type\":\"text\"},0,,10,101,${JSON.stringify(tools)},auto,`) + const groqConf = await oracle.groqConfigurations(0) + expect(groqConf.toString()).to.equal("mixtral-8x7b-32768,21,,1000,21,{\"type\":\"text\"},0,,10,101,") }); it("Oracle can add response", async () => { const {chatGpt, oracle, allSigners} = await loadFixture(deploy); @@ -91,8 +51,6 @@ describe("GroqChatGpt", function () { const response = { id: "responseId", content: "Hi!", - functionName: "functionNameHere", - functionArguments: "functionArgumentsHere", created: 1618888901, // Example UNIX timestamp model: "mixtral-8x7b-32768", systemFingerprint: "systemFingerprintHere", @@ -101,7 +59,7 @@ describe("GroqChatGpt", function () { promptTokens: 5, totalTokens: 15 }; - await oracle.connect(oracleAccount).addResponse(0, 0, response, ""); + await oracle.connect(oracleAccount).addGroqResponse(0, 0, response, ""); const messages = await oracle.getMessages(0, 0) expect(messages.length).to.equal(2) diff --git a/contracts/test/OpenAiChatGpt.ts b/contracts/test/OpenAiChatGpt.ts index 3e26922..34fc07e 100644 --- a/contracts/test/OpenAiChatGpt.ts +++ b/contracts/test/OpenAiChatGpt.ts @@ -37,7 +37,7 @@ describe("OpenAiChatGpt", function () { await chatGpt.startChat("Hello"); // promptId: 0, callbackId: 0 - const openAiConf = await oracle.llmConfigurations(0) + const openAiConf = await oracle.openAiConfigurations(0) const tools = [ { "type": "function", @@ -101,7 +101,7 @@ describe("OpenAiChatGpt", function () { promptTokens: 5, totalTokens: 15 }; - await oracle.connect(oracleAccount).addResponse(0, 0, response, ""); + await oracle.connect(oracleAccount).addOpenAiResponse(0, 0, response, ""); const messages = await oracle.getMessages(0, 0) expect(messages.length).to.equal(2) diff --git a/contracts/test/Vitailik.ts b/contracts/test/Vitailik.ts index 74f48f9..648e68c 100644 --- a/contracts/test/Vitailik.ts +++ b/contracts/test/Vitailik.ts @@ -93,8 +93,6 @@ describe("Vitailik", function () { { id: "123", content: "oracle response", - functionName: "", - functionArguments: "", created: 1337, model: "mixtral-8x7b-32768", systemFingerprint: "asd", @@ -130,8 +128,6 @@ describe("Vitailik", function () { { id: "123", content: "oracle response", - functionName: "", - functionArguments: "", created: 1337, model: "mixtral-8x7b-32768", systemFingerprint: "asd", @@ -150,8 +146,6 @@ describe("Vitailik", function () { { id: "123", content: "oracle response2", - functionName: "", - functionArguments: "", created: 1337, model: "mixtral-8x7b-32768", systemFingerprint: "asd", @@ -187,8 +181,6 @@ describe("Vitailik", function () { { id: "123", content: "oracle response", - functionName: "", - functionArguments: "", created: 1337, model: "mixtral-8x7b-32768", systemFingerprint: "asd", @@ -230,8 +222,6 @@ describe("Vitailik", function () { { id: "123", content: "oracle response\nYour HP: 0", - functionName: "", - functionArguments: "", created: 1337, model: "mixtral-8x7b-32768", systemFingerprint: "asd", @@ -265,8 +255,6 @@ describe("Vitailik", function () { { id: "123", content: "oracle response\n Dict: return { "id": "", "content": "", - "functionName": "", - "functionArguments": "", "created": 0, "model": "", "systemFingerprint": "", @@ -456,10 +454,6 @@ def _format_groq_response(completion: Optional[GroqChatCompletion]) -> Dict: return { "id": completion.id, "content": choice.content if choice.content else "", - "functionName": choice.tool_calls[0].function.name if choice.tool_calls else "", - "functionArguments": ( - choice.tool_calls[0].function.arguments if choice.tool_calls else "" - ), "created": completion.created, "model": completion.model, "systemFingerprint": completion.system_fingerprint or "",