Name | langdict JSON |
Version |
0.0.1rc1
JSON |
| download |
home_page | None |
Summary | The Simplest LLM Application Framework |
upload_time | 2024-09-23 14:31:20 |
maintainer | None |
docs_url | None |
author | None |
requires_python | <4.0,>=3.9 |
license | MIT License Copyright (c) 2024 LangDict Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. |
keywords |
llm
rag
agent
compund ai systems
langdict
|
VCS |
|
bugtrack_url |
|
requirements |
No requirements were recorded.
|
Travis-CI |
No Travis.
|
coveralls test coverage |
No coveralls.
|
<p align="center">
<img src="images/logo.png" style="inline" width=600>
</p>
<h4 align="center">
The Simplest LLM Application Framework
</h4>
---
# LangDict
LangDict is a framework for developing Compound AI System using only `Python dictionary`. This framework provides an intuitive usage for developing LLM Application for production.
Developing an LLM Application simply means adding API calls. Therefore, LangDict was created with the design philosophy that LLM Applications can be constructed from specifications, not complex functionality.
Create your own LLM Application with minimal understanding of other libraries and frameworks.
LangDict focuses on the intuitive interface, modularity, extensibility, and reusability of [PyTorch](https://github.com/pytorch/pytorch)'s `nn.Module`. Agent and Compound AI Systems can be easily developed from a composition of these modules.
## Features
<details>
<summary>LLM Applicaiton framework for simple, intuitive, dictionary-based development</summary>
```python
chitchat = LangDict.from_dict({
"messages": [
("system", "You are a helpful AI bot. Your name is {name}."),
("human", "Hello, how are you doing?"),
("ai", "I'm doing well, thanks!"),
("human", "{user_input}"),
],
"llm": {
"model": "gpt-4o-mini",
"max_tokens": 200
},
"output": {
"type": "string"
}
})
# format placeholder is key of input dictionary
chitchat({
"name": "LangDict",
"user_input": "What is your name?"
})
```
</details>
<details>
<summary>Stream / Batch / Async compatibility</summary>
```python
rag = RAG()
single_inputs = {
"conversation": [{"role": "user", "content": "How old is Obama?"}]
}
# invoke
rag(single_inputs)
# stream
rag(single_inputs, stream=True)
# batch
batch_inputs = [{ ... }, { ...}, ...]
rag(batch_inputs, batch=True)
```
</details>
<details>
<summary>Modularity: Extensibility, Modifiability, Reusability</summary>
```python
class RAG(Module):
def __init__(self, docs: List[str]):
super().__init__()
self.query_rewrite = LangDictModule.from_dict({ ... }) # Module
self.search = SimpleKeywordSearch(docs=docs) # Module
self.answer = LangDictModule.from_dict({ ... }) # Module
def forward(self, inputs: Dict):
query_rewrite_result = self.query_rewrite({
"conversation": inputs["conversation"],
})
doc = self.search(query_rewrite_result)
return self.answer({
"conversation": inputs["conversation"],
"context": doc,
})
```
</details>
<details>
<summary>Easy to change trace options (Console, Langfuse)</summary>
```python
# Apply Trace option to all modules
rag = RAG()
# Console Trace
rag.trace(backend="console")
# Langfuse
rag.trace(backend="langfuse")
```
</details>
## Quick Start
Install LangDict:
```python
$ pip install langdict
```
### Example
Chitchat (`LangDict`)
- Create LLM functions based on your specification.
```python
from langdict import LangDict
chitchat_spec = {
"messages": [
("system", "You are a helpful AI bot. Your name is {name}."),
("human", "Hello, how are you doing?"),
("ai", "I'm doing well, thanks!"),
("human", "{user_input}"),
],
"llm": {
"model": "gpt-4o-mini",
"max_tokens": 200
},
"output": {
"type": "string"
}
}
chitchat = LangDict.from_dict(chitchat_spec)
chitchat({
"name": "LangDict",
"user_input": "What is your name?"
})
>>> 'My name is LangDict. How can I assist you today?'
```
`Module` (+ `LangDictModule`, `stream`, `trace`)
- Develop Compound AI System based on modules and get observability with a single line of code.
```python
from typing import Any, Dict, List
from langdict import Module, LangDictModule
class RAG(Module):
def __init__(self, docs: List[str]):
super().__init__()
self.query_rewrite = LangDictModule.from_dict(query_rewrite_spec)
self.search = SimpleRetriever(docs=docs) # Module
self.answer = LangDictModule.from_dict(answer_spec)
def forward(self, inputs: Dict[str, Any]):
query_rewrite_result = self.query_rewrite({
"conversation": inputs["conversation"],
})
doc = self.search(query_rewrite_result)
return self.answer({
"conversation": inputs["conversation"],
"context": doc,
})
rag = RAG()
inputs = {
"conversation": [{"role": "user", "content": "How old is Obama?"}]
}
rag(inputs)
>>> 'Barack Obama was born on August 4, 1961. As of now, in October 2023, he is 62 years old.'
# Stream
for token in rag(inputs, stream=True):
print(f"token > {token}")
>>>
token > Bar
token > ack
token > Obama
token > was
token > born
token > on
token > August
token >
token > 4
...
# Trace
rag.trace(backend="langfuse")
```
## Dependencies
LangDict requires the following:
- [`LangChain`](https://github.com/langchain-ai/langchain) - LangDict consists of PromptTemplate + LLM + Output Parser.
- langchain
- langchain-core
- [`LiteLLM`](https://github.com/BerriAI/litellm) - Call 100+ LLM APIs in OpenAI format.
### Optional
- [`Langfuse`](https://github.com/langfuse/langfuse) - If you use langfuse with the Trace option, you need to install it separately.
Raw data
{
"_id": null,
"home_page": null,
"name": "langdict",
"maintainer": null,
"docs_url": null,
"requires_python": "<4.0,>=3.9",
"maintainer_email": "Dongjun Lee <djlee.hb@gmail.com>",
"keywords": "LLM, RAG, Agent, Compund AI Systems, LangDict",
"author": null,
"author_email": "Dongjun Lee <djlee.hb@gmail.com>",
"download_url": null,
"platform": null,
"description": "\n<p align=\"center\">\n <img src=\"images/logo.png\" style=\"inline\" width=600>\n</p>\n\n<h4 align=\"center\">\n The Simplest LLM Application Framework\n</h4>\n\n---\n\n# LangDict\n\nLangDict is a framework for developing Compound AI System using only `Python dictionary`. This framework provides an intuitive usage for developing LLM Application for production.\n\nDeveloping an LLM Application simply means adding API calls. Therefore, LangDict was created with the design philosophy that LLM Applications can be constructed from specifications, not complex functionality.\n\nCreate your own LLM Application with minimal understanding of other libraries and frameworks.\n\nLangDict focuses on the intuitive interface, modularity, extensibility, and reusability of [PyTorch](https://github.com/pytorch/pytorch)'s `nn.Module`. Agent and Compound AI Systems can be easily developed from a composition of these modules.\n\n\n## Features\n\n<details>\n <summary>LLM Applicaiton framework for simple, intuitive, dictionary-based development</summary>\n\n```python\nchitchat = LangDict.from_dict({\n \"messages\": [\n (\"system\", \"You are a helpful AI bot. Your name is {name}.\"),\n (\"human\", \"Hello, how are you doing?\"),\n (\"ai\", \"I'm doing well, thanks!\"),\n (\"human\", \"{user_input}\"),\n ],\n \"llm\": {\n \"model\": \"gpt-4o-mini\",\n \"max_tokens\": 200\n },\n \"output\": {\n \"type\": \"string\"\n }\n})\n# format placeholder is key of input dictionary\nchitchat({\n \"name\": \"LangDict\",\n \"user_input\": \"What is your name?\"\n})\n```\n\n</details>\n\n<details>\n <summary>Stream / Batch / Async compatibility</summary>\n\n```python\nrag = RAG()\n\nsingle_inputs = {\n \"conversation\": [{\"role\": \"user\", \"content\": \"How old is Obama?\"}]\n}\n# invoke\nrag(single_inputs)\n\n# stream\nrag(single_inputs, stream=True)\n\n# batch\nbatch_inputs = [{ ... }, { ...}, ...]\nrag(batch_inputs, batch=True)\n```\n\n</details>\n\n<details>\n <summary>Modularity: Extensibility, Modifiability, Reusability</summary>\n\n```python\nclass RAG(Module):\n\n def __init__(self, docs: List[str]):\n super().__init__()\n self.query_rewrite = LangDictModule.from_dict({ ... }) # Module\n self.search = SimpleKeywordSearch(docs=docs) # Module\n self.answer = LangDictModule.from_dict({ ... }) # Module\n\n def forward(self, inputs: Dict):\n query_rewrite_result = self.query_rewrite({\n \"conversation\": inputs[\"conversation\"],\n })\n doc = self.search(query_rewrite_result)\n return self.answer({\n \"conversation\": inputs[\"conversation\"],\n \"context\": doc,\n })\n```\n\n</details>\n\n<details>\n <summary>Easy to change trace options (Console, Langfuse)</summary>\n\n```python\n# Apply Trace option to all modules\nrag = RAG()\n\n# Console Trace\nrag.trace(backend=\"console\")\n\n# Langfuse\nrag.trace(backend=\"langfuse\")\n```\n\n</details>\n\n\n## Quick Start\n\nInstall LangDict:\n\n```python\n$ pip install langdict\n```\n\n### Example\n\nChitchat (`LangDict`)\n- Create LLM functions based on your specification.\n\n```python\nfrom langdict import LangDict\n\n\nchitchat_spec = {\n \"messages\": [\n (\"system\", \"You are a helpful AI bot. Your name is {name}.\"),\n (\"human\", \"Hello, how are you doing?\"),\n (\"ai\", \"I'm doing well, thanks!\"),\n (\"human\", \"{user_input}\"),\n ],\n \"llm\": {\n \"model\": \"gpt-4o-mini\",\n \"max_tokens\": 200\n },\n \"output\": {\n \"type\": \"string\"\n }\n}\nchitchat = LangDict.from_dict(chitchat_spec)\nchitchat({\n \"name\": \"LangDict\",\n \"user_input\": \"What is your name?\"\n})\n>>> 'My name is LangDict. How can I assist you today?'\n```\n\n`Module` (+ `LangDictModule`, `stream`, `trace`)\n- Develop Compound AI System based on modules and get observability with a single line of code.\n\n```python\nfrom typing import Any, Dict, List\n\nfrom langdict import Module, LangDictModule\n\n\nclass RAG(Module):\n\n def __init__(self, docs: List[str]):\n super().__init__()\n self.query_rewrite = LangDictModule.from_dict(query_rewrite_spec)\n self.search = SimpleRetriever(docs=docs) # Module\n self.answer = LangDictModule.from_dict(answer_spec)\n\n def forward(self, inputs: Dict[str, Any]):\n query_rewrite_result = self.query_rewrite({\n \"conversation\": inputs[\"conversation\"],\n })\n doc = self.search(query_rewrite_result)\n return self.answer({\n \"conversation\": inputs[\"conversation\"],\n \"context\": doc,\n })\n\nrag = RAG()\ninputs = {\n \"conversation\": [{\"role\": \"user\", \"content\": \"How old is Obama?\"}]\n}\n\nrag(inputs)\n>>> 'Barack Obama was born on August 4, 1961. As of now, in October 2023, he is 62 years old.'\n\n# Stream\nfor token in rag(inputs, stream=True):\n print(f\"token > {token}\")\n>>>\ntoken > Bar\ntoken > ack\ntoken > Obama\ntoken > was\ntoken > born\ntoken > on\ntoken > August\ntoken > \ntoken > 4\n...\n\n# Trace\nrag.trace(backend=\"langfuse\")\n```\n\n## Dependencies\n\nLangDict requires the following:\n\n- [`LangChain`](https://github.com/langchain-ai/langchain) - LangDict consists of PromptTemplate + LLM + Output Parser.\n - langchain\n - langchain-core\n- [`LiteLLM`](https://github.com/BerriAI/litellm) - Call 100+ LLM APIs in OpenAI format.\n\n### Optional\n\n- [`Langfuse`](https://github.com/langfuse/langfuse) - If you use langfuse with the Trace option, you need to install it separately.\n",
"bugtrack_url": null,
"license": "MIT License Copyright (c) 2024 LangDict Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the \"Software\"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. ",
"summary": "The Simplest LLM Application Framework",
"version": "0.0.1rc1",
"project_urls": {
"Bug Tracker": "https://github.com/LangDict/langdict/issues",
"Documentation": "https://langdict.github.io/docs",
"Homepage": "https://langdict.github.io/",
"Repository": "https://github.com/LangDict/langdict.git"
},
"split_keywords": [
"llm",
" rag",
" agent",
" compund ai systems",
" langdict"
],
"urls": [
{
"comment_text": "",
"digests": {
"blake2b_256": "ec6c47d5eda9732e21dc695219092bd75c85ee4d72e05e300c93d15e9869751a",
"md5": "8e41b8b54ea4f807d835dca0a01435a3",
"sha256": "0c9080a9ec6d4692455aa4d94b4d03ea173e681914be580dd181448346a13c72"
},
"downloads": -1,
"filename": "langdict-0.0.1rc1-py3-none-any.whl",
"has_sig": false,
"md5_digest": "8e41b8b54ea4f807d835dca0a01435a3",
"packagetype": "bdist_wheel",
"python_version": "py3",
"requires_python": "<4.0,>=3.9",
"size": 22960,
"upload_time": "2024-09-23T14:31:20",
"upload_time_iso_8601": "2024-09-23T14:31:20.444860Z",
"url": "https://files.pythonhosted.org/packages/ec/6c/47d5eda9732e21dc695219092bd75c85ee4d72e05e300c93d15e9869751a/langdict-0.0.1rc1-py3-none-any.whl",
"yanked": false,
"yanked_reason": null
}
],
"upload_time": "2024-09-23 14:31:20",
"github": true,
"gitlab": false,
"bitbucket": false,
"codeberg": false,
"github_user": "LangDict",
"github_project": "langdict",
"github_not_found": true,
"lcname": "langdict"
}