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
6 changes: 6 additions & 0 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
// TODO:
// * https://github.com/microsoft/vscode-python/issues/23078
// * https://github.com/microsoft/vscode/issues/197603
"python.envFile": "${workspaceFolder}/.file-that-should-hopefully-not-exist"
}
17 changes: 13 additions & 4 deletions python/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,18 +16,27 @@ After defining your types, TypeChat takes care of the rest by:

Types are all you need!

## Installation
## Getting Started

TypeChat for Python is not yet on PyPI, but you can try our [examples](./examples/) by cloning this repository.

You will need [Python >=3.11](https://www.python.org/downloads/) and [hatch](https://hatch.pypa.io/1.6/install/).
Install TypeChat:

```sh
pip install typechat
```

You can also develop TypeChat from source, which needs [Python >=3.11](https://www.python.org/downloads/), [hatch](https://hatch.pypa.io/1.6/install/), and [Node.js >=20](https://nodejs.org/en/download):

```sh
git clone https://github.com/microsoft/TypeChat
cd TypeChat/python
hatch shell
npm ci
```

To see TypeChat in action, we recommend exploring the [TypeChat example projects](https://github.com/microsoft/TypeChat/tree/main/python/examples). You can try them on your local machine or in a GitHub Codespace.

To learn more about TypeChat, visit the [documentation](https://microsoft.github.io/TypeChat) which includes more information on TypeChat and how to get started.

## Contributing

This project welcomes contributions and suggestions. Most contributions require you to agree to a
Expand Down
21 changes: 19 additions & 2 deletions python/examples/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -27,13 +27,30 @@ You can experiment with these TypeChat examples on your local machine.

You will need [Python >=3.11](https://www.python.org/downloads/) and [hatch](https://hatch.pypa.io/1.6/install/).

```
```sh
git clone https://github.com/microsoft/TypeChat
cd TypeChat/python
hatch shell
python examples/sentiment/demo.py
```

Alternatively, you can just use `venv` and `pip`:

```sh
git clone https://github.com/microsoft/TypeChat
cd TypeChat/python
python -m venv ../.venv

# Activate the virtual environment
# Windows
../.venv/Scripts/Activate.ps1
# Unix/POSIX
source ../.venv/bin/activate

pip install .[examples]

python examples/sentiment/demo.py
```

### Option 2: GitHub Codespaces

Expand Down Expand Up @@ -77,7 +94,7 @@ To use an Azure OpenAI endpoint, include the following environment variables:

We recommend setting environment variables by creating a `.env` file in the root directory of the project that looks like the following:

```
```ini
# For OpenAI
OPENAI_MODEL=...
OPENAI_API_KEY=...
Expand Down
25 changes: 19 additions & 6 deletions python/pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,20 @@ dependencies = [
"typing_extensions>=4.10.0",
]

[project.optional-dependencies]
# Development-time dependencies.
dev = [
"coverage[toml]>=6.5",
"pytest>=8.0.2",
"syrupy>=4.6.1",
]

# Dependencies for examples.
examples = [
"python-dotenv>=1.0.0",
"spotipy",
]

[project.urls]
Documentation = "https://github.com/microsoft/TypeChat#readme"
Issues = "https://github.com/microsoft/TypeChat/issues"
Expand All @@ -44,12 +58,11 @@ path = "src/typechat/__about__.py"
type = "virtual"
path = "../.venv"

dependencies = [
"coverage[toml]>=6.5",
"python-dotenv>=1.0.0",
"pytest>=8.0.2",
"syrupy>=4.6.1",
"spotipy", # for examples
# Include dependencies from optional-dependencies for
# development of the core package along with examples.
features = [
"dev",
"examples"
]

[tool.hatch.envs.default.scripts]
Expand Down
4 changes: 3 additions & 1 deletion python/src/typechat/_internal/model.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ class HttpxLanguageModel(TypeChatLanguageModel, AsyncContextManager):
_async_client: httpx.AsyncClient
_max_retry_attempts: int = 3
_retry_pause_seconds: float = 1.0
_timeout_seconds = 10

def __init__(self, url: str, headers: dict[str, str], default_params: dict[str, str]):
super().__init__()
Expand Down Expand Up @@ -73,6 +74,7 @@ async def complete(self, prompt: str | list[PromptSection]) -> Success[str] | Fa
self.url,
headers=headers,
json=body,
timeout=self._timeout_seconds
)
if response.is_success:
json_result = cast(
Expand All @@ -85,7 +87,7 @@ async def complete(self, prompt: str | list[PromptSection]) -> Success[str] | Fa
return Failure(f"REST API error {response.status_code}: {response.reason_phrase}")
except Exception as e:
if retry_count >= self._max_retry_attempts:
return Failure(str(e))
return Failure(str(e) or f"{repr(e)} raised from within internal TypeChat language model.")

await asyncio.sleep(self._retry_pause_seconds)
retry_count += 1
Expand Down
3 changes: 2 additions & 1 deletion site/src/_data/docsTOC.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,8 @@
{ "title": "Introduction", "url": "/docs/introduction/"},
{ "title": "Examples", "url": "/docs/examples/"},
{ "title": "Techniques", "url": "/docs/techniques/"},
{ "title": "FAQ", "url": "/docs/faq/"}
{ "title": "FAQ", "url": "/docs/faq/"},
{ "title": "Basic Usage for TypeScript", "url": "/docs/typescript/basic-usage/"}
]
}
]
29 changes: 20 additions & 9 deletions site/src/_includes/footer.njk
Original file line number Diff line number Diff line change
@@ -1,15 +1,26 @@
<footer class="container mt-auto d-flex flex-wrap justify-content-between align-items-center py-3 border-top">
<div class="col-md-4 d-flex align-items-center">
<span class="mb-3 mb-md-0 text-body-secondary">© Microsoft</span>
</div>
{#-
<ul class="nav mx-auto ml-md-0">
<li class="nav-item nav-item mx-1">
<a class="nav-link text-body-secondary" target="_blank" href="https://microsoft.github.io/">© Microsoft</span>
</li>
<li class="nav-item mx-1">
<a class="nav-link text-body-secondary" target="_blank" href="https://go.microsoft.com/fwlink/?LinkId=521839">Privacy</a>
</li>
<li class="nav-item mx-1">
<a class="nav-link text-body-secondary" target="_blank" href="https://go.microsoft.com/fwlink/?LinkID=20697">Terms of Use</a>
</li>
</ul>

<ul class="nav col-md-4 justify-content-end list-unstyled d-flex">
<li class="ms-3">
<a class="text-body-secondary" href="#">
Social Media - TODO
<ul class="nav mx-auto mr-md-0">
<li class="nav-item">
<a class="nav-link text-body-secondary" href="https://twitter.com/typechat">
Twitter
</a>
</li>
<li class="nav-item">
<a class="nav-link text-body-secondary" href="https://bsky.app/profile/typechat.bsky.social">
Bluesky
</a>
</li>
</ul>
#}
</footer>
Loading