Skip to content

Commit

Permalink
Gabriel/update langchain (#302)
Browse files Browse the repository at this point in the history
* Accounting for manifold update

* Revert "Accounting for manifold update"

This reverts commit aa445c4.

* Added PR suggestion

* WIP

* Updated langchain -> ^0.2.6

* Remove unnecessary files

* Fixed mypy

* Bumped version

* Bumped version

* Using pydantic.v1.SecretStr

* Finalized mypy fix

* Implemented PR comments

* Updated lock file

* Versions back

* Fixed isort

* Removed unnecessary test/function

* Fixed isort

* Increased timeout

* Fixed isort
  • Loading branch information
gabrielfior authored Jul 12, 2024
1 parent 24af401 commit 266b0bd
Show file tree
Hide file tree
Showing 9 changed files with 235 additions and 272 deletions.
462 changes: 218 additions & 244 deletions poetry.lock

Large diffs are not rendered by default.

11 changes: 10 additions & 1 deletion prediction_market_agent_tooling/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,14 @@
from gnosis.eth import EthereumClient
from gnosis.safe import Safe
from pydantic.types import SecretStr
from pydantic.v1.types import SecretStr as SecretStrV1
from pydantic_settings import BaseSettings, SettingsConfigDict

from prediction_market_agent_tooling.gtypes import ChecksumAddress, PrivateKey
from prediction_market_agent_tooling.gtypes import (
ChecksumAddress,
PrivateKey,
secretstr_to_v1_secretstr,
)
from prediction_market_agent_tooling.markets.manifold.api import get_authenticated_user
from prediction_market_agent_tooling.tools.utils import check_not_none
from prediction_market_agent_tooling.tools.web3_utils import private_key_to_public_key
Expand Down Expand Up @@ -87,6 +92,10 @@ def openai_api_key(self) -> SecretStr:
self.OPENAI_API_KEY, "OPENAI_API_KEY missing in the environment."
)

@property
def openai_api_key_secretstr_v1(self) -> SecretStrV1:
return secretstr_to_v1_secretstr(self.openai_api_key)

@property
def graph_api_key(self) -> SecretStr:
return check_not_none(
Expand Down
2 changes: 1 addition & 1 deletion prediction_market_agent_tooling/markets/categorize.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ def infer_category(
prompt
| ChatOpenAI(
model=model,
api_key=APIKeys().openai_api_key.get_secret_value(),
api_key=APIKeys().openai_api_key_secretstr_v1,
)
| StrOutputParser()
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ def rewrite_question_into_image_generation_prompt(question: str) -> str:
llm = ChatOpenAI(
model="gpt-4-turbo",
temperature=0.0,
api_key=APIKeys().openai_api_key.get_secret_value(),
api_key=APIKeys().openai_api_key_secretstr_v1,
)
rewritten = str(
llm.invoke(
Expand Down
2 changes: 1 addition & 1 deletion prediction_market_agent_tooling/tools/is_predictable.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ def is_predictable_binary(
llm = ChatOpenAI(
model=engine,
temperature=0.0,
api_key=APIKeys().openai_api_key.get_secret_value(),
api_key=APIKeys().openai_api_key_secretstr_v1,
)

prompt = ChatPromptTemplate.from_template(template=prompt_template)
Expand Down
6 changes: 3 additions & 3 deletions pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[tool.poetry]
name = "prediction-market-agent-tooling"
version = "0.42.0"
version = "0.42.1"
description = "Tools to benchmark, deploy and monitor prediction market agents."
authors = ["Gnosis"]
readme = "README.md"
Expand Down Expand Up @@ -31,8 +31,8 @@ scikit-learn = "^1.3.1"
tabulate = "^0.9.0"
types-pytz = "^2024.1.0.20240203"
google-cloud-secret-manager = "^2.18.2"
langchain = { version = "^0.1.9", optional = true}
langchain-openai = { version = "^0.0.5", optional = true}
langchain = { version = "^0.2.6", optional = true}
langchain-openai = { version = "^0.1.0", optional = true}
google-api-python-client = { version = "2.95.0", optional = true}
subgrounds = "^1.9.1"
loguru = "^0.7.2"
Expand Down
10 changes: 0 additions & 10 deletions tests_integration/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,16 +24,6 @@ def local_web3(load_env) -> Web3:
node_daemon.stop()


def local_web3_at_block(
request: pytest.FixtureRequest, block: int, port: int = 8546
) -> Web3:
node = LocalNode(GNOSIS_RPC_URL, port=port, default_block=block)
node_daemon = _local_node(node, True)
# for auto-closing connection
request.addfinalizer(node_daemon.stop)
return node.w3


@pytest.fixture(scope="session")
def local_ethereum_client(local_web3: Web3) -> EthereumClient:
return EthereumClient()
Expand Down
2 changes: 1 addition & 1 deletion tests_integration/local_chain_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -139,5 +139,5 @@ def _local_node(
if start_local_node:
node_daemon = run_anvil(node.remote_url, node.default_block, node.port)

wait_for_port(node.port, timeout=20)
wait_for_port(node.port, timeout=60)
return node_daemon
10 changes: 0 additions & 10 deletions tests_integration/markets/omen/test_local_chain.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import pytest
from eth_account import Account
from numpy import isclose
from pydantic import SecretStr
Expand All @@ -13,22 +12,13 @@
wei_to_xdai,
xdai_to_wei,
)
from tests_integration.conftest import local_web3_at_block
from tests_integration.local_chain_utils import get_anvil_test_accounts


def test_connect_local_chain(local_web3: Web3) -> None:
assert local_web3.is_connected()


def test_connect_local_chain_at_block(load_env, request: pytest.FixtureRequest) -> None:
# start connection
historical_block = 33324170
web3 = local_web3_at_block(request, historical_block, 8546)
assert web3.is_connected()
assert web3.eth.get_block_number() == historical_block


def test_send_xdai(local_web3: Web3) -> None:
accounts = get_anvil_test_accounts()
value = xdai_to_wei(xDai(10))
Expand Down

0 comments on commit 266b0bd

Please sign in to comment.