forked from phoenix/litellm-mirror
trying to add docs
This commit is contained in:
parent
0fe8799f94
commit
2cf949990e
834 changed files with 0 additions and 161273 deletions
|
@ -1,13 +0,0 @@
|
|||
```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"
|
||||
```
|
|
@ -1,12 +0,0 @@
|
|||
```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
|
||||
```
|
|
@ -1,9 +0,0 @@
|
|||
```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
|
||||
```
|
|
@ -1,12 +0,0 @@
|
|||
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>
|
|
@ -1,34 +0,0 @@
|
|||
```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']
|
||||
```
|
|
@ -1,19 +0,0 @@
|
|||
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="...")
|
||||
```
|
|
@ -1,14 +0,0 @@
|
|||
```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']
|
||||
```
|
|
@ -1,23 +0,0 @@
|
|||
```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.")
|
||||
]
|
||||
```
|
|
@ -1,10 +0,0 @@
|
|||
```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