Skip to content

Commit

Permalink
Linters, code auto-formatting and testing improvements
Browse files Browse the repository at this point in the history
  • Loading branch information
dmugtasimov committed Jan 31, 2025
1 parent 46f957e commit b165783
Show file tree
Hide file tree
Showing 10 changed files with 37 additions and 34 deletions.
3 changes: 1 addition & 2 deletions .devcontainer/devcontainer.json
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,8 @@
"[python]": {
"editor.defaultFormatter": "ms-python.black-formatter"
},
// TODO(dmu) HIGH: Make linter configuration consistent with .pre-commit-config.yaml
"ruff.args": [
"--exclude",
"migrations",
"--ignore",
"E501,E711,E712",
"--fix",
Expand Down
3 changes: 1 addition & 2 deletions .github/workflows/integration-tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -26,5 +26,4 @@ jobs:
python -m pip install behave langchain openai
if [ -f requirements.txt ]; then pip install -r requirements.txt; fi
- name: Run Integration Tests
run: |
behave
run: behave
3 changes: 3 additions & 0 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,13 @@ jobs:
uses: actions/setup-python@v5
with:
python-version: "3.8"

- name: Install poetry
run: pipx install poetry

- name: Running poetry install
run: poetry install

- name: Build and publish
env:
POETRY_PYPI_TOKEN_PYPI: ${{ secrets.PYPI_PASSWORD }}
Expand Down
27 changes: 11 additions & 16 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -1,20 +1,15 @@
repos:
- repo: https://github.com/pre-commit/pre-commit-hooks
rev: v5.0.0
hooks:
- id: end-of-file-fixer
exclude: (app/utils/evaluate/(javascript_code_wrapper|python_code_wrapper)\.txt|langchain_prompts\.txt)
- id: trailing-whitespace
- repo: https://github.com/astral-sh/ruff-pre-commit
rev: v0.0.290
rev: v0.9.4
hooks:
- id: ruff
args:
[--exclude, features, --ignore, "E501", --fix, --exit-non-zero-on-fix]

- repo: https://github.com/psf/black-pre-commit-mirror
rev: 23.9.1
hooks:
- id: black
args: [--force-exclude, features]

- repo: https://github.com/pycqa/isort
rev: 5.12.0
hooks:
- id: isort
name: isort (python)
args: [--profile, black, --skip, features, --filter-files]
name: 'ruff: fix imports'
args: ["--select", "I", "--fix"]
- id: ruff
- id: ruff-format
8 changes: 7 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
@@ -1,7 +1,13 @@
RUN_TEST := test -f .env && set -a; . ./.env; set +a; poetry run pytest

.PHONY: lint
lint:
poetry run pre-commit run --all-files

.PHONY: test
test:
poetry run pytest
${RUN_TEST}

.PHONY: test-sw
test-sw:
${RUN_TEST} -vv --sw --show-capture=no
12 changes: 6 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,11 @@
<a href="https://docs.promptlayer.com"><img alt="Docs" src="https://custom-icon-badges.herokuapp.com/badge/docs-PL-green.svg?logo=cake&style=for-the-badge"></a>
<a href="https://www.loom.com/share/196c42e43acd4a369d75e9a7374a0850"><img alt="Demo with Loom" src="https://img.shields.io/badge/Demo-loom-552586.svg?logo=loom&style=for-the-badge&labelColor=gray"></a>

---
---

<div align="left">

[PromptLayer](https://promptlayer.com/) is the first platform that allows you to track, manage, and share your GPT prompt engineering. PromptLayer acts a middleware between your code and OpenAI’s python library.
[PromptLayer](https://promptlayer.com/) is the first platform that allows you to track, manage, and share your GPT prompt engineering. PromptLayer acts a middleware between your code and OpenAI’s python library.

PromptLayer records all your OpenAI API requests, allowing you to search and explore request history in the PromptLayer dashboard.

Expand Down Expand Up @@ -53,14 +53,14 @@ openai = promptlayer.openai

### Adding PromptLayer tags: `pl_tags`

PromptLayer allows you to add tags through the `pl_tags` argument. This allows you to track and group requests in the dashboard.
PromptLayer allows you to add tags through the `pl_tags` argument. This allows you to track and group requests in the dashboard.

*Tags are not required but we recommend them!*

```python
openai.Completion.create(
engine="text-ada-001",
prompt="My name is",
engine="text-ada-001",
prompt="My name is",
pl_tags=["name-guessing", "pipeline-2"]
)
```
Expand All @@ -69,7 +69,7 @@ After making your first few requests, you should be able to see them in the Prom

## Using the REST API

This Python library is a wrapper over PromptLayer's REST API. If you use another language, like Javascript, just interact directly with the API.
This Python library is a wrapper over PromptLayer's REST API. If you use another language, like Javascript, just interact directly with the API.

Here is an example request below:

Expand Down
2 changes: 1 addition & 1 deletion promptlayer/promptlayer_base.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ def __getattr__(self, name):
):
return PromptLayerBase(
attr,
function_name=f'{object.__getattribute__(self, "_function_name")}.{name}',
function_name=f"{object.__getattribute__(self, '_function_name')}.{name}",
provider_type=object.__getattribute__(self, "_provider_type"),
api_key=object.__getattribute__(self, "_api_key"),
tracer=object.__getattribute__(self, "_tracer"),
Expand Down
5 changes: 3 additions & 2 deletions promptlayer/track/__init__.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
from promptlayer.track.track import agroup, ametadata, aprompt, ascore, group
from promptlayer.track.track import agroup, ametadata, aprompt, ascore, group, prompt
from promptlayer.track.track import metadata as metadata_
from promptlayer.track.track import prompt
from promptlayer.track.track import score as score_

# TODO(dmu) LOW: Move this code to another file


class TrackManager:
def __init__(self, api_key: str):
Expand Down
6 changes: 3 additions & 3 deletions promptlayer/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -749,9 +749,9 @@ def cleaned_result(self):
hasattr(result.choices[0].delta, "content")
and result.choices[0].delta.content is not None
):
response["content"] = response[
"content"
] = f"{response['content']}{result.choices[0].delta.content}"
response["content"] = response["content"] = (
f"{response['content']}{result.choices[0].delta.content}"
)
final_result = deepcopy(self.results[-1])
final_result.choices[0] = response
return final_result
Expand Down
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[tool.poetry]
name = "promptlayer"
version = "1.0.37"
version = "1.0.38"
description = "PromptLayer is a platform for prompt engineering and tracks your LLM requests."
authors = ["Magniv <[email protected]>"]
license = "Apache-2.0"
Expand Down

0 comments on commit b165783

Please sign in to comment.