mirror of
https://github.com/BerriAI/litellm.git
synced 2025-04-25 18:54:30 +00:00
add everyting for docs
This commit is contained in:
parent
de45a738ee
commit
0fe8799f94
1015 changed files with 185353 additions and 0 deletions
47
docs/snippets/get_started/installation.mdx
Normal file
47
docs/snippets/get_started/installation.mdx
Normal file
|
@ -0,0 +1,47 @@
|
|||
## Official release
|
||||
|
||||
To install LangChain run:
|
||||
|
||||
import Tabs from '@theme/Tabs';
|
||||
import TabItem from '@theme/TabItem';
|
||||
import CodeBlock from "@theme/CodeBlock";
|
||||
|
||||
<Tabs>
|
||||
<TabItem value="pip" label="Pip" default>
|
||||
<CodeBlock language="bash">pip install langchain</CodeBlock>
|
||||
</TabItem>
|
||||
<TabItem value="conda" label="Conda">
|
||||
<CodeBlock language="bash">conda install langchain -c conda-forge</CodeBlock>
|
||||
</TabItem>
|
||||
</Tabs>
|
||||
|
||||
This will install the bare minimum requirements of LangChain.
|
||||
A lot of the value of LangChain comes when integrating it with various model providers, datastores, etc.
|
||||
By default, the dependencies needed to do that are NOT installed.
|
||||
However, there are two other ways to install LangChain that do bring in those dependencies.
|
||||
|
||||
To install modules needed for the common LLM providers, run:
|
||||
|
||||
```bash
|
||||
pip install langchain[llms]
|
||||
```
|
||||
|
||||
To install all modules needed for all integrations, run:
|
||||
|
||||
```bash
|
||||
pip install langchain[all]
|
||||
```
|
||||
|
||||
Note that if you are using `zsh`, you'll need to quote square brackets when passing them as an argument to a command, for example:
|
||||
|
||||
```bash
|
||||
pip install 'langchain[all]'
|
||||
```
|
||||
|
||||
## From source
|
||||
|
||||
If you want to install from source, you can do so by cloning the repo and running:
|
||||
|
||||
```bash
|
||||
pip install -e .
|
||||
```
|
13
docs/snippets/get_started/quickstart/import_llms.mdx
Normal file
13
docs/snippets/get_started/quickstart/import_llms.mdx
Normal file
|
@ -0,0 +1,13 @@
|
|||
```python
|
||||
from langchain.llms import OpenAI
|
||||
from langchain.chat_models import ChatOpenAI
|
||||
|
||||
llm = OpenAI()
|
||||
chat_model = ChatOpenAI()
|
||||
|
||||
llm.predict("hi!")
|
||||
>>> "Hi"
|
||||
|
||||
chat_model.predict("hi!")
|
||||
>>> "Hi"
|
||||
```
|
12
docs/snippets/get_started/quickstart/input_messages.mdx
Normal file
12
docs/snippets/get_started/quickstart/input_messages.mdx
Normal file
|
@ -0,0 +1,12 @@
|
|||
```python
|
||||
from langchain.schema import HumanMessage
|
||||
|
||||
text = "What would be a good company name for a company that makes colorful socks?"
|
||||
messages = [HumanMessage(content=text)]
|
||||
|
||||
llm.predict_messages(messages)
|
||||
# >> Feetful of Fun
|
||||
|
||||
chat_model.predict_messages(messages)
|
||||
# >> Socks O'Color
|
||||
```
|
9
docs/snippets/get_started/quickstart/input_string.mdx
Normal file
9
docs/snippets/get_started/quickstart/input_string.mdx
Normal file
|
@ -0,0 +1,9 @@
|
|||
```python
|
||||
text = "What would be a good company name for a company that makes colorful socks?"
|
||||
|
||||
llm.predict(text)
|
||||
# >> Feetful of Fun
|
||||
|
||||
chat_model.predict(text)
|
||||
# >> Socks O'Color
|
||||
```
|
12
docs/snippets/get_started/quickstart/installation.mdx
Normal file
12
docs/snippets/get_started/quickstart/installation.mdx
Normal file
|
@ -0,0 +1,12 @@
|
|||
import Tabs from '@theme/Tabs';
|
||||
import TabItem from '@theme/TabItem';
|
||||
import CodeBlock from "@theme/CodeBlock";
|
||||
|
||||
<Tabs>
|
||||
<TabItem value="pip" label="Pip" default>
|
||||
<CodeBlock language="bash">pip install langchain</CodeBlock>
|
||||
</TabItem>
|
||||
<TabItem value="conda" label="Conda">
|
||||
<CodeBlock language="bash">conda install langchain -c conda-forge</CodeBlock>
|
||||
</TabItem>
|
||||
</Tabs>
|
34
docs/snippets/get_started/quickstart/llm_chain.mdx
Normal file
34
docs/snippets/get_started/quickstart/llm_chain.mdx
Normal file
|
@ -0,0 +1,34 @@
|
|||
```python
|
||||
from langchain.chat_models import ChatOpenAI
|
||||
from langchain.prompts.chat import (
|
||||
ChatPromptTemplate,
|
||||
SystemMessagePromptTemplate,
|
||||
HumanMessagePromptTemplate,
|
||||
)
|
||||
from langchain.chains import LLMChain
|
||||
from langchain.schema import BaseOutputParser
|
||||
|
||||
class CommaSeparatedListOutputParser(BaseOutputParser):
|
||||
"""Parse the output of an LLM call to a comma-separated list."""
|
||||
|
||||
|
||||
def parse(self, text: str):
|
||||
"""Parse the output of an LLM call."""
|
||||
return text.strip().split(", ")
|
||||
|
||||
template = """You are a helpful assistant who generates comma separated lists.
|
||||
A user will pass in a category, and you should generated 5 objects in that category in a comma separated list.
|
||||
ONLY return a comma separated list, and nothing more."""
|
||||
system_message_prompt = SystemMessagePromptTemplate.from_template(template)
|
||||
human_template = "{text}"
|
||||
human_message_prompt = HumanMessagePromptTemplate.from_template(human_template)
|
||||
|
||||
chat_prompt = ChatPromptTemplate.from_messages([system_message_prompt, human_message_prompt])
|
||||
chain = LLMChain(
|
||||
llm=ChatOpenAI(),
|
||||
prompt=chat_prompt,
|
||||
output_parser=CommaSeparatedListOutputParser()
|
||||
)
|
||||
chain.run("colors")
|
||||
# >> ['red', 'blue', 'green', 'yellow', 'orange']
|
||||
```
|
19
docs/snippets/get_started/quickstart/openai_setup.mdx
Normal file
19
docs/snippets/get_started/quickstart/openai_setup.mdx
Normal file
|
@ -0,0 +1,19 @@
|
|||
First we'll need to install their Python package:
|
||||
|
||||
```bash
|
||||
pip install openai
|
||||
```
|
||||
|
||||
Accessing the API requires an API key, which you can get by creating an account and heading [here](https://platform.openai.com/account/api-keys). Once we have a key we'll want to set it as an environment variable by running:
|
||||
|
||||
```bash
|
||||
export OPENAI_API_KEY="..."
|
||||
```
|
||||
|
||||
If you'd prefer not to set an environment variable you can pass the key in directly via the `openai_api_key` named parameter when initiating the OpenAI LLM class:
|
||||
|
||||
```python
|
||||
from langchain.llms import OpenAI
|
||||
|
||||
llm = OpenAI(openai_api_key="...")
|
||||
```
|
14
docs/snippets/get_started/quickstart/output_parser.mdx
Normal file
14
docs/snippets/get_started/quickstart/output_parser.mdx
Normal file
|
@ -0,0 +1,14 @@
|
|||
```python
|
||||
from langchain.schema import BaseOutputParser
|
||||
|
||||
class CommaSeparatedListOutputParser(BaseOutputParser):
|
||||
"""Parse the output of an LLM call to a comma-separated list."""
|
||||
|
||||
|
||||
def parse(self, text: str):
|
||||
"""Parse the output of an LLM call."""
|
||||
return text.strip().split(", ")
|
||||
|
||||
CommaSeparatedListOutputParser().parse("hi, bye")
|
||||
# >> ['hi', 'bye']
|
||||
```
|
|
@ -0,0 +1,23 @@
|
|||
```python
|
||||
from langchain.prompts.chat import (
|
||||
ChatPromptTemplate,
|
||||
SystemMessagePromptTemplate,
|
||||
HumanMessagePromptTemplate,
|
||||
)
|
||||
|
||||
template = "You are a helpful assistant that translates {input_language} to {output_language}."
|
||||
system_message_prompt = SystemMessagePromptTemplate.from_template(template)
|
||||
human_template = "{text}"
|
||||
human_message_prompt = HumanMessagePromptTemplate.from_template(human_template)
|
||||
|
||||
chat_prompt = ChatPromptTemplate.from_messages([system_message_prompt, human_message_prompt])
|
||||
|
||||
chat_prompt.format_messages(input_language="English", output_language="French", text="I love programming.")
|
||||
```
|
||||
|
||||
```pycon
|
||||
[
|
||||
SystemMessage(content="You are a helpful assistant that translates English to French.", additional_kwargs={}),
|
||||
HumanMessage(content="I love programming.")
|
||||
]
|
||||
```
|
|
@ -0,0 +1,10 @@
|
|||
```python
|
||||
from langchain.prompts import PromptTemplate
|
||||
|
||||
prompt = PromptTemplate.from_template("What is a good name for a company that makes {product}?")
|
||||
prompt.format(product="colorful socks")
|
||||
```
|
||||
|
||||
```pycon
|
||||
What is a good name for a company that makes colorful socks?
|
||||
```
|
Loading…
Add table
Add a link
Reference in a new issue