LitChain
Simple wrapper around openai's client.chat.completions.create. To simplify function/tool calling. openai docs
This repo takes some inspiration from langchain. But does not use it.
We think that, in langchain, it's fast changes make it a good forum to be aware of the most recent advances and methods in llm usage. But that is unstable, unnecessary complex, sometimes redundant, and makes you loss control over your code and prompts. And that using a simple prompt and an external library is enough for a lot of cases. So we don't want to use it in production.
Usage
Main operator
from litchain import LlmBaseModel, tool
@tool
def get_current_weather(location, unit="fahrenheit"):
"""Get the current weather in a given location."""
[...]
model = LlmBaseModel(
system="GPT assistant",
prompt_template="What's the weather in {city}?",
tools=[get_current_weather],
tool_choice="get_weather")
prompt = model.get_prompt(city="San Francisco")
model.predict_sample(prompt=prompt)
For full code, check examples/hello_world
Examples
Run
/examples/mail_classifier/mail_classifier.py --email "I want to buy a car"
for a simple example.
List of examples:
- hello_world.py: A simple example using get_current_weather func from openai docs.
- mail_classifier.py: A simple example of a mail classifier.
- movie_trivia_autogpt.py: A simple example of a movie trivia generator using sequential llm calls.
Setup
Instalation
pip install litchain
or from source
pip install -r requirements.txt
pip install -e .
Env variables
You will need to set the following env variables:
- OPENAI_API_KEY: Your openai api key.
Authors
Iuiu
Release files for litchain 0.0.2
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | |
|---|---|---|---|
| litchain-0.0.2.tar.gz | 9.1 kB | Details |
Release files / litchain-0.0.2.tar.gz
| Download URL | litchain-0.0.2.tar.gz |
|---|---|
| Size | 9.1 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
404f801de6ea8230ed29a1d82e2d521774c4f005bf12cb2f30fb982506f7e493
|
|
BLAKE2b-256 checksum How to use checksums |
845df4097c3aea0694573bebcb2fd60e485becf305c0c2ad0d63441e87ba5b75
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/4.0.2 CPython/3.9.9
|