Skip to content

GPT Training

Project layout

experiment/ # experiment for new tools
├── gpt-engineer
   ├── README.md
src/ # src for runnable scripts and apps
├── examples/ # one-time scripts
├── libs/ # common libs
├── projects/apps/ # runnable apps
docs/ # md files for mkdocs
├── index.md
README.md
mkdocs.yml

Versions

python 3.12.6
poetry 1.8.3

Tools

  1. asdf

    asdf local python <version>
    asdf local poetry <version>
    
  2. poetry

    poetry install
    

Environment Variables

.env
OPENAI_API_KEY=
OPENAI_ORGANIZATION=
GOOGLE_CSE_ID=
GOOGLE_API_KEY=
SERPAPI_API_KEY=
TAVILY_API_KEY=
poetry add poetry-dotenv-plugin

Config

pyproject.toml
pyproject.toml
[tool.poetry]
name = "gpt-training"
version = "0.1.0"
description = "GPT Training"
authors = ["Masato Naka <masatonaka1989@gmail.com>"]
readme = "README.md"
packages = [{include = "src"}]

[tool.poetry.dependencies]
python = "^3.12"
mkdocs-material = "^9.5.3"
streamlit = "^1.30.0"
openai = "^1.7.2"
langchainhub = "^0.1.14"
langchain = "^0.3.0"
langchain-openai = "^0.2.0"
google-api-python-client = "^2.115.0"
langchain-google-genai = "^2.0.0"
pillow = "^11.0.0"
langgraph = "^0.2.0"
wikipedia = "^1.4.0"
google-search-results = "^2.4.2"
tabulate = "^0.9.0"
langchain-community = "^0.3.0"
langchain-experimental = "^0.3.0"
langchain-google-community = "^2.0.0"


[tool.poetry.group.dev.dependencies]
pytest = "^8.0.0"
pytest-cov = "^6.0.0"
pytest-env = "^1.1.3"
poetry-dotenv-plugin = "^0.2.0"
mkdocs-awesome-pages-plugin = "^2.9.2"
ruff = "^0.8.0"
langchain-cli = "^0.0.33"

[tool.ruff]
exclude = [
    ".venv",
    "venv",
    "__pycache__",
    ".git",
]

line-length = 200
indent-width = 4


[build-system]
requires = ["poetry-core"]
build-backend = "poetry.core.masonry.api"

# From https://github.com/googleapis/google-cloud-python/issues/11184
# https://docs.pytest.org/en/stable/reference/customize.html
[tool.pytest.ini_options]
testpaths = [
    "tests",
]
pythonpath = [
    "src",
]
addopts = "--junitxml=pytest.xml --cov-report=term-missing --cov=src tests/ -vvv -s"
env = [
    "ENV=test",
    "OPENAI_API_KEY=dummy",
    "OPENAI_ORGANIZATION=dummy",
    "GOOGLE_CSE_ID=dummy",
    "GOOGLE_API_KEY=dummy",
]

Run

Run a script

poetry run python src/examples/agent_react.py

Run an app

poetry run streamlit run src/projects/apps/streamlit/app.py

Testing

Installation

poetry add pytest pytest-cov pytest-env --group dev

Run

poetry run pytest

patch

Source code:

from langchain_community.utilities import GoogleSearchAPIWrapper
google = GoogleSearchAPIWrapper()

Test:

@patch("src.libs.tools.google")
def test_xxx(mock_google):
    google_mock.results.return_value = [
        {
            "title": "内閣制度と歴代内閣",
            "link": "https://www.kantei.go.jp/jp/rekidai/ichiran.html",
            "snippet": "(外務大臣 内田康哉が内閣総理大臣臨時兼任). 22, (第2次) 山本權兵衞, 大正12.9.2 -大正13.1.7, 128, 70歳, 嘉永5.10.15, 昭和8.12.8 (81歳), 鹿児島県, 549. 23(13)\xa0...",
        },
    ]

FakeListLLM

langchain/testing.md