Skip to content

Commit

Permalink
Merge pull request #9 from OpenBB-finance/feature/add-testing-infra
Browse files Browse the repository at this point in the history
Add testing
  • Loading branch information
mnicstruwig authored Dec 13, 2023
2 parents c62c91d + 81b4b48 commit 8f64e8d
Show file tree
Hide file tree
Showing 8 changed files with 88 additions and 6 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/lint.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
name: ci
name: Lint

on: [push]
on: [pull_request]

jobs:
lint:
Expand Down
30 changes: 30 additions & 0 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
name: Test

on: [pull_request]

jobs:
unit-test:
runs-on: ubuntu-latest
strategy:
matrix:
python-version: ["3.11"]
steps:
- name: Checkout code
uses: actions/checkout@v3
- name: Install Poetry
uses: snok/install-poetry@v1
with:
version: 1.7.1
virtualenvs-create: true
virtualenvs-in-project: true
- name: Set up Python ${{ matrix.python-version }}
uses: actions/setup-python@v3
with:
python-version: ${{ matrix.python-version }}
cache: 'poetry'
- name: Install dependencies
run: |
python -m pip install --upgrade pip
poetry install
- name: Run Pytest
run : poetry run pytest tests/
17 changes: 16 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,10 @@ utilizing function calling to interact with the OpenBB platform.


## Set-up
- Create a new virtual environment
At present, we currently support Python 3.11. If you're using a earlier version
of Python, your mileage may vary. We'll be adding wider support very soon!

- Create a new virtual environment, with `poetry `
- `poetry install`

## Usage
Expand Down Expand Up @@ -36,6 +39,7 @@ There is more functionality coming very soon!

## Development

### Linting and Formatting
We're currently experimenting with `ruff` as a drop-in replacement for `black`, `isort` and `pylint`.

You can run linting checks as follows:
Expand All @@ -62,3 +66,14 @@ You can install the `pre-commit` hooks as follows:
``` sh
pre-commit install
```

### Testing

We are in the process of adding tests.

We use `pytest` as our test-runner:

``` sh
pytest tests/
```

6 changes: 4 additions & 2 deletions openbb_agents/tools.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
import inspect
from functools import wraps
from types import ModuleType
from typing import List, Union
from typing import Callable, List, Union

import tiktoken
from langchain.embeddings import OpenAIEmbeddings
Expand Down Expand Up @@ -132,7 +132,9 @@ def wrapper_func(*args, **kwargs):
return wrapper_func


def from_openbb_to_langchain_func(openbb_command_root, openbb_callable, openbb_schema):
def from_openbb_to_langchain_func(
openbb_command_root: str, openbb_callable: Callable, openbb_schema: dict
) -> StructuredTool:
func_schema = openbb_schema["openbb"]["QueryParams"]["fields"]
# Lookup the default provider's input arguments...
default_provider = obb.coverage.commands[openbb_command_root.replace("/", ".")][0]
Expand Down
2 changes: 1 addition & 1 deletion poetry.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ openbb-charting = "^1.0.0"
[tool.poetry.group.dev.dependencies]
pre-commit = "^3.5.0"
ruff = "^0.1.7"
pytest = "^7.4.3"

[tool.isort]
profile = "black"
Expand Down
Empty file added tests/__init__.py
Empty file.
34 changes: 34 additions & 0 deletions tests/test_tools.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
from openbb import obb

from openbb_agents.tools import from_openbb_to_langchain_func


def test_from_openbb_to_langchain_func():
"""Test that we can create a StructuredTool from an OpenBB function."""
test_openbb_command_root = "/equity/profile"

test_openbb_callable = obb.equity.profile
test_openbb_schema = obb.coverage.command_model[".equity.profile"]

actual_result = from_openbb_to_langchain_func(
openbb_command_root=test_openbb_command_root,
openbb_callable=test_openbb_callable,
openbb_schema=test_openbb_schema,
)

assert actual_result.name == "/equity/profile"
assert "Equity Info" in actual_result.description # Check for docstring
assert "name" in actual_result.description # Check for output field
assert actual_result.args_schema.__name__ == "/equity/profileInputModel"
assert actual_result.args_schema.schema() == {
"title": "/equity/profileInputModel",
"type": "object",
"properties": {
"symbol": {
"title": "Symbol",
"description": "Symbol to get data for.",
"type": "string",
}
},
"required": ["symbol"],
}

0 comments on commit 8f64e8d

Please sign in to comment.