Langchain Recent Changes 16/02/2024

Version: 1.00 Date: 16/02/202


LangChain.jpg


As Lancghain evolves, we keep seeing ongoing changes; recently, we have seen changes in moving ChatOpenAI to pip show langchain-community. We have also seen a change in how we are calling ChatOpenAI, we now use invoke. Here is a working Python code, you can find the lib version numbers in the code that I am using.

I am using langchain 0.1.7

#I am using langchain-community 0.0.20


#Langchain has moved to use separate community library for ChatOpenAI

from langchain_openai.chat_models import ChatOpenAI


from langchain.prompts import PromptTemplate

from langchain.schema import HumanMessage, AIMessage, SystemMessage


print("Starting application.")


# Your OpenAI API key - replace "your_api_key_here" with your actual API key

openai_api_key = "Put you key here"


chat = ChatOpenAI(model_name="gpt-3.5-turbo", api_key=openai_api_key)


conversation_history = [

    HumanMessage(content="Suggest 3 bday gift for a data scientist."),

    AIMessage(content="What is you price range?"),

    SystemMessage(content="Under 100$$"),


]


#This used to be and is now been deprecated: ret = chat(conversation_history)

ret = chat.invoke(conversation_history)


print(ret.pretty_print())


print("Finished application.")



I will continue to update you with the latest working code snippet.





An error has occurred. This application may no longer respond until reloaded. Reload 🗙