-
Notifications
You must be signed in to change notification settings - Fork 74
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: add support for pydantic v1 users (#163)
* ✨ add pydantic util functions * ⚡ update openai adapter modules * ⚡ update langchain adapter modules * bump(ver): 0.8.0 → 0.8.1 * 📝 add pypi friendly readme * 🔧 update pyproject.toml
- Loading branch information
Showing
10 changed files
with
126 additions
and
22 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
<div align="center"> | ||
|
||
<img src="https://raw.githubusercontent.com/ajndkr/lanarky/main/assets/logo-light-mode.png#gh-light-mode-only" alt="lanarky-logo-light-mode" width="500"> | ||
|
||
<h4>The web framework for building LLM microservices.</h4> | ||
|
||
[![Stars](https://img.shields.io/github/stars/ajndkr/lanarky)](https://github.com/ajndkr/lanarky/stargazers) | ||
[![License](https://img.shields.io/badge/License-MIT-yellow.svg)](https://github.com/ajndkr/lanarky/blob/main/LICENSE) | ||
[![Twitter](https://img.shields.io/twitter/follow/LanarkyAPI?style=social)](https://twitter.com/intent/follow?screen_name=LanarkyAPI) | ||
[![Discord](https://img.shields.io/badge/join-Discord-7289da.svg)](https://discord.gg/6qUfrQAEeE) | ||
|
||
[![Python](https://img.shields.io/pypi/pyversions/lanarky.svg)](https://pypi.org/project/lanarky/) | ||
[![Coverage](https://coveralls.io/repos/github/ajndkr/lanarky/badge.svg?branch=main)](https://coveralls.io/github/ajndkr/lanarky?branch=main) | ||
[![Version](https://badge.fury.io/py/lanarky.svg)](https://pypi.org/project/lanarky/) | ||
[![Stats](https://img.shields.io/pypi/dm/lanarky.svg)](https://pypistats.org/packages/lanarky) | ||
|
||
</div> | ||
|
||
Lanarky is a **python (3.9+)** web framework for developers who want to build microservices using LLMs. | ||
Here are some of its key features: | ||
|
||
- **LLM-first**: Unlike other web frameworks, lanarky is built specifically for LLM developers. | ||
It's unopinionated in terms of how you build your microservices and guarantees zero vendor lock-in | ||
with any LLM tooling frameworks or cloud providers | ||
- **Fast & Modern**: Built on top of FastAPI, lanarky offers all the FastAPI features you know and love. | ||
If you are new to FastAPI, visit [fastapi.tiangolo.com](https://fastapi.tiangolo.com) to learn more | ||
- **Streaming**: Streaming is essential for many real-time LLM applications, like chatbots. Lanarky has | ||
got you covered with built-in streaming support over **HTTP** and **WebSockets**. | ||
- **Open-source**: Lanarky is open-source and free to use. Forever. | ||
|
||
To learn more about lanarky and get started, you can find the full documentation on [lanarky.ajndkr.com](https://lanarky.ajndkr.com) | ||
|
||
## Installation | ||
|
||
The library is available on PyPI and can be installed via `pip`: | ||
|
||
```bash | ||
pip install lanarky | ||
``` | ||
|
||
## Contributing | ||
|
||
[![Code check](https://github.com/ajndkr/lanarky/actions/workflows/code-check.yaml/badge.svg)](https://github.com/ajndkr/lanarky/actions/workflows/code-check.yaml) | ||
[![Publish](https://github.com/ajndkr/lanarky/actions/workflows/publish.yaml/badge.svg)](https://github.com/ajndkr/lanarky/actions/workflows/publish.yaml) | ||
|
||
Contributions are more than welcome! If you have an idea for a new feature or want to help improve lanarky, | ||
please create an issue or submit a pull request on [GitHub](https://github.com/ajndkr/lanarky). | ||
|
||
See [CONTRIBUTING.md](https://github.com/ajndkr/lanarky/blob/main/CONTRIBUTING.md) for more information. | ||
|
||
## License | ||
|
||
The library is released under the [MIT License](https://github.com/ajndkr/lanarky/blob/main/LICENSE). |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
from typing import Any | ||
|
||
import pydantic | ||
from pydantic.fields import FieldInfo | ||
|
||
PYDANTIC_V2 = pydantic.VERSION.startswith("2.") | ||
|
||
|
||
def model_dump(model: pydantic.BaseModel, **kwargs) -> dict[str, Any]: | ||
"""Dump a pydantic model to a dictionary. | ||
Args: | ||
model: A pydantic model. | ||
""" | ||
if PYDANTIC_V2: | ||
return model.model_dump(**kwargs) | ||
else: | ||
return model.dict(**kwargs) | ||
|
||
|
||
def model_dump_json(model: pydantic.BaseModel, **kwargs) -> str: | ||
"""Dump a pydantic model to a JSON string. | ||
Args: | ||
model: A pydantic model. | ||
""" | ||
if PYDANTIC_V2: | ||
return model.model_dump_json(**kwargs) | ||
else: | ||
return model.json(**kwargs) | ||
|
||
|
||
def model_fields(model: pydantic.BaseModel) -> dict[str, FieldInfo]: | ||
"""Get the fields of a pydantic model. | ||
Args: | ||
model: A pydantic model. | ||
""" | ||
if PYDANTIC_V2: | ||
return model.model_fields | ||
else: | ||
return model.__fields__ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters