Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
79 changes: 71 additions & 8 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -99,14 +99,77 @@ policy derived from the true game tree using
with a simple game harness that generates moves using raw observations as input.
This `eval` colab is set up specifically for Kuhn poker.

## Define Your Own Client Interface

This package is set up to use Google LLMs (a.k.a. Gemini models). If you would
like to use alternative models, there is one file `_src/client_lib.py` that you
must modify to depend on your desired LLM client. Specifically, the `query_llm`
method must be updated. Make sure to adhere to the protocols defined at the top
of the file. Simply clone this repo, modify the code accordingly, and build from
source.
## Using Alternative LLM Providers

This package supports multiple LLM providers out of the box:

### Google Gemini (Default)

```python
import strategicwm as swm

client = swm.client_lib.Client(api_key="your-google-api-key")
model_id = "gemini-1.5-pro"
```

### OpenAI GPT

First, install the OpenAI optional dependency:

```bash
pip install strategicwm[openai]
```

Then use the OpenAI client:

```python
import strategicwm as swm

client = swm.client_openai.OpenAIClient(api_key="your-openai-api-key")
model_id = "gpt-4"
```

### Anthropic Claude

First, install the Anthropic optional dependency:

```bash
pip install strategicwm[anthropic]
```

Then use the Anthropic client:

```python
import strategicwm as swm

client = swm.client_anthropic.AnthropicClient(api_key="your-anthropic-api-key")
model_id = "claude-3-5-sonnet-20241022"
```

### Using the Client Factory

For a unified interface across providers, use the client factory:

```python
import strategicwm as swm

# Create client for any provider
client, query_fn = swm.client_factory.create_client(
provider="openai", # or "gemini", "anthropic"
api_key="your-api-key",
)

# Get the default model for a provider
model_id = swm.client_factory.get_default_model("openai")
```

### Install All Providers

To install support for all LLM providers at once:

```bash
pip install strategicwm[all-providers]
```

## References

Expand Down
19 changes: 19 additions & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,25 @@ dev = [
"pyink",
]

# OpenAI client support
# Installed through `pip install -e .[openai]`
openai = [
"openai>=1.0.0",
]

# Anthropic client support
# Installed through `pip install -e .[anthropic]`
anthropic = [
"anthropic>=0.18.0",
]

# All LLM providers (Gemini is included by default)
# Installed through `pip install -e .[all-providers]`
all-providers = [
"openai>=1.0.0",
"anthropic>=0.18.0",
]

[tool.pyink]
# Formatting configuration to follow Google style-guide
line-length = 80
Expand Down
15 changes: 15 additions & 0 deletions strategicwm/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@

# pylint: disable=g-importing-member,useless-import-alias
from strategicwm._src import client_lib
from strategicwm._src import client_factory
from strategicwm._src.colab_utils import eval_utils as kuhn_eval_utils
from strategicwm._src.se import analysis
from strategicwm._src.se import pyspiel_utils
Expand All @@ -24,6 +25,17 @@
from strategicwm._src.se.visualization import annotate
from strategicwm._src.se.visualization.game_tree import GameTreeVis
from strategicwm._src.se.visualization.value_function import plot_value_functions

# Optional client imports - only available if the corresponding package is installed
try:
from strategicwm._src import client_openai
except ImportError:
client_openai = None # type: ignore

try:
from strategicwm._src import client_anthropic
except ImportError:
client_anthropic = None # type: ignore
# pylint: enable=g-importing-member,useless-import-alias


Expand All @@ -36,6 +48,9 @@
"analysis",
"annotate",
"client_lib",
"client_factory",
"client_openai",
"client_anthropic",
"GameTreeVis",
"Gardener",
"io",
Expand Down
Loading