Skip to content

Commit

Permalink
Fixes unit tests
Browse files Browse the repository at this point in the history
  • Loading branch information
kgrofelnik committed Jun 26, 2024
1 parent bc1ba94 commit 2805807
Show file tree
Hide file tree
Showing 4 changed files with 7 additions and 16 deletions.
11 changes: 6 additions & 5 deletions contracts/test/ChatGpt.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import {expect} from "chai";
import {ethers} from "hardhat";

describe("ChatGpt", function () {
const addResponseSignature = "addResponse(uint256,uint256,string,string)";
// We define a fixture to reuse the same setup in every test.
// We use loadFixture to run this setup once, snapshot that state,
// and reset Hardhat Network to that snapshot in every test.
Expand Down Expand Up @@ -43,7 +44,7 @@ describe("ChatGpt", function () {
await oracle.updateWhitelist(oracleAccount, true);

await chatGpt.startChat("Hello");
await oracle.connect(oracleAccount).addResponse(0, 0, "Hi", "");
await oracle.connect(oracleAccount)[addResponseSignature](0, 0, "Hi", "");
const messages = await oracle.getMessages(0, 0)
expect(messages.length).to.equal(2)
expect(messages[1]).to.equal("Hi")
Expand All @@ -60,7 +61,7 @@ describe("ChatGpt", function () {
await oracle.updateWhitelist(oracleAccount, true);

await chatGpt.startChat("Hello");
await oracle.connect(oracleAccount).addResponse(0, 0, "Hi", "");
await oracle.connect(oracleAccount)[addResponseSignature](0, 0, "Hi", "");
await chatGpt.addMessage("message", 0);

const messages = await oracle.getMessages(0, 0)
Expand All @@ -85,10 +86,10 @@ describe("ChatGpt", function () {
await oracle.updateWhitelist(oracleAccount, true);

await chatGpt.startChat("Hello");
await oracle.connect(oracleAccount).addResponse(0, 0, "Hi", "");
await oracle.connect(oracleAccount)[addResponseSignature](0, 0, "Hi", "");
await oracle.connect(oracleAccount).markPromptAsProcessed(0);
await expect(
oracle.connect(oracleAccount).addResponse(0, 0, "Hi", "")
oracle.connect(oracleAccount)[addResponseSignature](0, 0, "Hi", "")
).to.be.revertedWith("Prompt already processed");
});
it("Oracle cannot add 2 responses", async () => {
Expand All @@ -103,7 +104,7 @@ describe("ChatGpt", function () {
await oracle.updateWhitelist(oracleAccount, true);

await chatGpt.startChat("Hello");
await oracle.connect(oracleAccount).addResponse(0, 0, "Hi", "");
await oracle.connect(oracleAccount)[addResponseSignature](0, 0, "Hi", "");

// Ultimate edge-case, user whitelisted some random address
const randomAccount = allSigners[7];
Expand Down
2 changes: 0 additions & 2 deletions oracles/src/domain/llm/groq_llm.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,6 @@ async def execute(chat: Chat) -> Optional[GroqChatCompletion]:
stop=chat.config.stop,
temperature=chat.config.temperature,
top_p=chat.config.top_p,
tools=chat.config.tools,
tool_choice=chat.config.tool_choice,
user=chat.config.user,
)
assert (
Expand Down
2 changes: 0 additions & 2 deletions oracles/src/entities.py
Original file line number Diff line number Diff line change
Expand Up @@ -103,8 +103,6 @@ class GroqConfig:
stop: Optional[str]
temperature: Optional[float]
top_p: Optional[float]
tools: Optional[List[ChatCompletionToolParam]]
tool_choice: Optional[ToolChoiceType]
user: Optional[str]


Expand Down
8 changes: 1 addition & 7 deletions oracles/src/repositories/web3/chat_repository.py
Original file line number Diff line number Diff line change
Expand Up @@ -302,13 +302,7 @@ async def _get_groq_config(self, i: int) -> Optional[GroqConfig]:
stop=_value_or_none(config[7]),
temperature=_parse_float_from_int(config[8], 0, 20),
top_p=_parse_float_from_int(config[9], 0, 100, decimals=2),
tools=_parse_tools(config[10]),
tool_choice=(
config[11]
if (config[11] and config[11] in get_args(ToolChoiceType))
else None
),
user=_value_or_none(config[12]),
user=_value_or_none(config[10]),
)
except:
return None
Expand Down

0 comments on commit 2805807

Please sign in to comment.