From addd82c3310da209f42197883c2ed8a2ec8c0d2c Mon Sep 17 00:00:00 2001 From: Vin Howe <24789592+vinhowe@users.noreply.github.com> Date: Mon, 22 May 2023 14:54:58 -0600 Subject: [PATCH 1/3] Configure isort to work with black --- pyproject.toml | 2 ++ 1 file changed, 2 insertions(+) create mode 100644 pyproject.toml diff --git a/pyproject.toml b/pyproject.toml new file mode 100644 index 0000000..5d7bf33 --- /dev/null +++ b/pyproject.toml @@ -0,0 +1,2 @@ +[tool.isort] +profile = "black" From bebcdc5ed6f3b2ad68957bb365b596821d39599d Mon Sep 17 00:00:00 2001 From: Vin Howe <24789592+vinhowe@users.noreply.github.com> Date: Mon, 22 May 2023 13:18:57 -0600 Subject: [PATCH 2/3] Add style check GitHub workflow --- .github/workflows/style-check.yml | 35 +++++++++++++++++++++++++++++++ 1 file changed, 35 insertions(+) create mode 100644 .github/workflows/style-check.yml diff --git a/.github/workflows/style-check.yml b/.github/workflows/style-check.yml new file mode 100644 index 0000000..7eabafd --- /dev/null +++ b/.github/workflows/style-check.yml @@ -0,0 +1,35 @@ +# Based on https://github.com/psf/black/actions/runs/17913292/workflow + +name: Style check +on: + push: + paths: + - '**.py' + pull_request: + paths: + - '**.py' +jobs: + black: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v3 + - name: Set up Python 3.10 + uses: actions/setup-python@v4 + with: + python-version: '3.10' + - name: Install Black + run: pip install black + - name: Run black check + run: black --check . + isort: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v3 + - name: Set up Python 3.10 + uses: actions/setup-python@v4 + with: + python-version: '3.10' + - name: Install isort + run: pip install isort + - name: Run isort check + run: isort --check-only . From 90c21818b6bec8a60bbe83869e8f39a48456ead8 Mon Sep 17 00:00:00 2001 From: Vin Howe <24789592+vinhowe@users.noreply.github.com> Date: Mon, 22 May 2023 18:16:23 -0600 Subject: [PATCH 3/3] Formatting + isort --- example_configure_survey.py | 2 +- lm_survey/constants.py | 1 - lm_survey/prompt_templates.py | 1 - lm_survey/samplers/__init__.py | 4 ++-- lm_survey/samplers/async_openai_sampler.py | 3 +-- lm_survey/samplers/auto_sampler.py | 4 ++-- lm_survey/samplers/base_sampler.py | 2 +- lm_survey/samplers/hf_sampler.py | 5 +++-- lm_survey/samplers/openai_sampler.py | 2 +- lm_survey/survey/__init__.py | 6 +++--- lm_survey/survey/dependent_variable_sample.py | 1 + lm_survey/survey/question.py | 2 ++ lm_survey/survey/results.py | 2 ++ lm_survey/survey/survey.py | 8 ++++---- lm_survey/survey/variable.py | 2 ++ 15 files changed, 25 insertions(+), 20 deletions(-) diff --git a/example_configure_survey.py b/example_configure_survey.py index 990f80a..9e7610e 100644 --- a/example_configure_survey.py +++ b/example_configure_survey.py @@ -1,6 +1,6 @@ -from lm_survey.survey.survey import Survey import os +from lm_survey.survey.survey import Survey if __name__ == "__main__": survey_directory = os.path.join("data", "ATP", "American_Trends_Panel_W92") diff --git a/lm_survey/constants.py b/lm_survey/constants.py index ffb6e3e..041bf2a 100644 --- a/lm_survey/constants.py +++ b/lm_survey/constants.py @@ -1,6 +1,5 @@ import typing - MULTIPLE_CHOICE_LIST: typing.List[str] = [ "A", "B", diff --git a/lm_survey/prompt_templates.py b/lm_survey/prompt_templates.py index 501a5c3..e65c4dc 100644 --- a/lm_survey/prompt_templates.py +++ b/lm_survey/prompt_templates.py @@ -2,7 +2,6 @@ from lm_survey.constants import MULTIPLE_CHOICE_LIST - INDEPENDENT_VARIABLE_SUMMARY_TEMPLATE = """Context: {context_summary} {dependent_variable_prompt}""" diff --git a/lm_survey/samplers/__init__.py b/lm_survey/samplers/__init__.py index 114515f..6a6e4b9 100644 --- a/lm_survey/samplers/__init__.py +++ b/lm_survey/samplers/__init__.py @@ -1,5 +1,5 @@ -from lm_survey.samplers.base_sampler import BaseSampler +from lm_survey.samplers.async_openai_sampler import AsyncOpenAiSampler from lm_survey.samplers.auto_sampler import AutoSampler +from lm_survey.samplers.base_sampler import BaseSampler from lm_survey.samplers.hf_sampler import HfSampler from lm_survey.samplers.openai_sampler import OpenAiSampler -from lm_survey.samplers.async_openai_sampler import AsyncOpenAiSampler diff --git a/lm_survey/samplers/async_openai_sampler.py b/lm_survey/samplers/async_openai_sampler.py index 1a57ace..3854efa 100644 --- a/lm_survey/samplers/async_openai_sampler.py +++ b/lm_survey/samplers/async_openai_sampler.py @@ -1,10 +1,9 @@ import sys import openai -from openai.error import RateLimitError - import torch from aiolimiter import AsyncLimiter +from openai.error import RateLimitError from lm_survey.samplers.base_sampler import BaseSampler, MaybeAwaitable diff --git a/lm_survey/samplers/auto_sampler.py b/lm_survey/samplers/auto_sampler.py index 7826125..9560ae2 100644 --- a/lm_survey/samplers/auto_sampler.py +++ b/lm_survey/samplers/auto_sampler.py @@ -1,7 +1,7 @@ -from lm_survey.samplers.hf_sampler import HfSampler -from lm_survey.samplers.openai_sampler import OpenAiSampler from lm_survey.samplers.async_openai_sampler import AsyncOpenAiSampler from lm_survey.samplers.base_sampler import BaseSampler +from lm_survey.samplers.hf_sampler import HfSampler +from lm_survey.samplers.openai_sampler import OpenAiSampler class AutoSampler(BaseSampler): diff --git a/lm_survey/samplers/base_sampler.py b/lm_survey/samplers/base_sampler.py index ee70244..6e14d25 100644 --- a/lm_survey/samplers/base_sampler.py +++ b/lm_survey/samplers/base_sampler.py @@ -1,5 +1,5 @@ -from abc import ABCMeta, abstractmethod import typing +from abc import ABCMeta, abstractmethod T = typing.TypeVar("T") MaybeAwaitable = typing.Union[T, typing.Awaitable[T]] diff --git a/lm_survey/samplers/hf_sampler.py b/lm_survey/samplers/hf_sampler.py index adca6d3..e238e1e 100644 --- a/lm_survey/samplers/hf_sampler.py +++ b/lm_survey/samplers/hf_sampler.py @@ -1,8 +1,9 @@ import typing -from lm_survey.samplers.base_sampler import BaseSampler import torch -from transformers import AutoTokenizer, AutoModelForCausalLM +from transformers import AutoModelForCausalLM, AutoTokenizer + +from lm_survey.samplers.base_sampler import BaseSampler class HfSampler(BaseSampler): diff --git a/lm_survey/samplers/openai_sampler.py b/lm_survey/samplers/openai_sampler.py index d41781b..6309e8b 100644 --- a/lm_survey/samplers/openai_sampler.py +++ b/lm_survey/samplers/openai_sampler.py @@ -1,10 +1,10 @@ import typing +import openai import tiktoken import torch from lm_survey.samplers.base_sampler import BaseSampler -import openai OPENAI_TOKEN_COSTS = { # cents per 1000 tokens diff --git a/lm_survey/survey/__init__.py b/lm_survey/survey/__init__.py index 977c1ef..bbf4bb7 100644 --- a/lm_survey/survey/__init__.py +++ b/lm_survey/survey/__init__.py @@ -1,8 +1,8 @@ from lm_survey.survey.dependent_variable_sample import ( - DependentVariableSample, Completion, + DependentVariableSample, ) -from lm_survey.survey.survey import Survey -from lm_survey.survey.variable import Variable from lm_survey.survey.question import Question, ValidOption from lm_survey.survey.results import SurveyResults +from lm_survey.survey.survey import Survey +from lm_survey.survey.variable import Variable diff --git a/lm_survey/survey/dependent_variable_sample.py b/lm_survey/survey/dependent_variable_sample.py index 6dcf164..9351c6e 100644 --- a/lm_survey/survey/dependent_variable_sample.py +++ b/lm_survey/survey/dependent_variable_sample.py @@ -1,4 +1,5 @@ import typing + from lm_survey.survey.question import Question diff --git a/lm_survey/survey/question.py b/lm_survey/survey/question.py index 7f269f3..b5a9802 100644 --- a/lm_survey/survey/question.py +++ b/lm_survey/survey/question.py @@ -1,5 +1,7 @@ import typing + import pandas as pd + from lm_survey.constants import MULTIPLE_CHOICE_LIST from lm_survey.prompt_templates import ( DEPENDENT_VARIABLE_TEMPLATE, diff --git a/lm_survey/survey/results.py b/lm_survey/survey/results.py index cb8a567..7bbe4b6 100644 --- a/lm_survey/survey/results.py +++ b/lm_survey/survey/results.py @@ -1,8 +1,10 @@ import json import os import typing + import pandas as pd import pandas.core.groupby.generic + from lm_survey.survey.dependent_variable_sample import DependentVariableSample diff --git a/lm_survey/survey/survey.py b/lm_survey/survey/survey.py index 89e2600..0d3231c 100644 --- a/lm_survey/survey/survey.py +++ b/lm_survey/survey/survey.py @@ -1,3 +1,6 @@ +import argparse +import functools +import json import os import typing from pathlib import Path @@ -6,16 +9,13 @@ import pandas as pd from sklearn.metrics import normalized_mutual_info_score +from lm_survey.prompt_templates import INDEPENDENT_VARIABLE_SUMMARY_TEMPLATE from lm_survey.survey.dependent_variable_sample import ( Completion, DependentVariableSample, ) from lm_survey.survey.question import Question, ValidOption from lm_survey.survey.variable import Variable -from lm_survey.prompt_templates import INDEPENDENT_VARIABLE_SUMMARY_TEMPLATE -import json -import functools -import argparse class Survey: diff --git a/lm_survey/survey/variable.py b/lm_survey/survey/variable.py index 0588172..5ebd5b5 100644 --- a/lm_survey/survey/variable.py +++ b/lm_survey/survey/variable.py @@ -1,5 +1,7 @@ import typing + import pandas as pd + from lm_survey.survey.question import Question