Updates docs and cookbooks to import ChatOpenAI, OpenAI, and OpenAI
Embeddings from `langchain_openai`
There are likely more
---------
Co-authored-by: Harrison Chase <hw.chase.17@gmail.com>
"template = \"\"\"Given an input question, convert it to a SQL query. No pre-amble. Based on the table schema below, write a SQL query that would answer the user's question:\n",
" \"You are a planner who is an expert at coming up with a todo list for a given objective. Come up with a todo list for this objective: {objective}\"\n",
"- To use Azure embeddings with OpenAI V1, you'll need to use the new `AzureOpenAIEmbeddings` instead of the existing `OpenAIEmbeddings`. `OpenAIEmbeddings` continue to work when using Azure with `openai<1`.\n",
"template = \"\"\"You are a Postgres expert. Given an input question, first create a syntactically correct Postgres query to run, then look at the results of the query and return the answer to the input question.\n",
"Unless the user specifies in the question a specific number of examples to obtain, query for at most 5 results using the LIMIT clause as per Postgres. You can order the results to return the most informative data in the database.\n",
@ -70,10 +70,10 @@ For this getting started guide, we will provide two options: using OpenAI (a pop
<Tabs>
<TabItem value="openai" label="OpenAI" default>
First we'll need to install their Python package:
First we'll need to the LangChain <> OpenAI integration package.
```shell
pip install openai
pip install langchain_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:
@ -85,7 +85,7 @@ export OPENAI_API_KEY="..."
We can then initialize the model:
```python
from langchain_community.chat_models import ChatOpenAI
from langchain_openai import ChatOpenAI
llm = ChatOpenAI()
```
@ -93,7 +93,7 @@ llm = ChatOpenAI()
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_community.chat_models import ChatOpenAI
from langchain_openai import ChatOpenAI
llm = ChatOpenAI(openai_api_key="...")
```
@ -128,7 +128,7 @@ We can also guide it's response with a prompt template.
Prompt templates are used to convert raw user input to a better input to the LLM.
```python
from langchain.prompts import ChatPromptTemplate
from langchain_core.prompts import ChatPromptTemplate
prompt = ChatPromptTemplate.from_messages([
("system", "You are world class technical documentation writer."),
("user", "{input}")
@ -199,10 +199,10 @@ For embedding models, we once again provide examples for accessing via OpenAI or
<Tabs>
<TabItem value="openai" label="OpenAI" default>
Make sure you have the openai package installed an the appropriate environment variables set (these are the same as needed for the LLM).
Make sure you have the `langchain_openai` package installed an the appropriate environment variables set (these are the same as needed for the LLM).
```python
from langchain_community.embeddings import OpenAIEmbeddings
from langchain_openai import OpenAIEmbeddings
embeddings = OpenAIEmbeddings()
```
@ -416,7 +416,7 @@ pip install langchainhub
Now we can use it to get a predefined prompt
```python
from langchain_community.chat_models import ChatOpenAI
from langchain_openai import ChatOpenAI
from langchain import hub
from langchain.agents import create_openai_functions_agent
from langchain.agents import AgentExecutor
@ -479,15 +479,15 @@ To create a server for our application we'll make a `serve.py` file. This will c
from typing import List
from fastapi import FastAPI
from langchain.prompts import ChatPromptTemplate
from langchain_community.chat_models import ChatOpenAI
from langchain_core.prompts import ChatPromptTemplate
from langchain_openai import ChatOpenAI
from langchain_community.document_loaders import WebBaseLoader
from langchain_community.embeddings import OpenAIEmbeddings
from langchain_openai import OpenAIEmbeddings
from langchain_community.vectorstores import DocArrayInMemorySearch
from langchain.text_splitter import RecursiveCharacterTextSplitter
from langchain.tools.retriever import create_retriever_tool
from langchain_community.tools.tavily_search import TavilySearchResults
from langchain_community.chat_models import ChatOpenAI
from langchain_openai import ChatOpenAI
from langchain import hub
from langchain.agents import create_openai_functions_agent