Skip to content

Commit

Permalink
clean up chat_models
Browse files Browse the repository at this point in the history
  • Loading branch information
bhancockio committed Jun 15, 2024
1 parent 75bd6f1 commit e070f8f
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 10 deletions.
8 changes: 3 additions & 5 deletions 1_chat_models/3_chat_model_alternatives.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
from langchain_google_genai import ChatGoogleGenerativeAI
from langchain_anthropic import ChatAnthropic
from langchain_openai import ChatOpenAI
from dotenv import load_dotenv
from langchain_core.messages import HumanMessage, SystemMessage

# Setup environment variables and messages

load_dotenv()

messages = [
Expand All @@ -12,7 +14,6 @@


# ---- LangChain OpenAI Chat Model Example ----
from langchain_openai import ChatOpenAI

# Create a ChatOpenAI model
model = ChatOpenAI(model="gpt-4o")
Expand All @@ -23,7 +24,6 @@


# ---- Anthropic Chat Model Example ----
from langchain_anthropic import ChatAnthropic

# Create a Anthropic model
# Anthropic models: https://docs.anthropic.com/en/docs/models-overview
Expand All @@ -36,8 +36,6 @@
# ---- Google Chat Model Example ----

# https://console.cloud.google.com/gen-app-builder/engines
from langchain_google_genai import ChatGoogleGenerativeAI

# https://ai.google.dev/gemini-api/docs/models/gemini
model = ChatGoogleGenerativeAI(model="gemini-1.5-flash")

Expand Down
4 changes: 2 additions & 2 deletions 1_chat_models/4_chat_model_conversation_with_user.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
from dotenv import load_dotenv
from langchain.chat_models import ChatOpenAI
from langchain_openai import ChatOpenAI
from langchain.schema import AIMessage, HumanMessage, SystemMessage

# Load environment variables from .env
Expand All @@ -23,7 +23,7 @@
chat_history.append(HumanMessage(content=query)) # Add user message

# Get AI response using history
result = model(chat_history)
result = model.invoke(chat_history)
response = result.content
chat_history.append(AIMessage(content=response)) # Add AI message

Expand Down
7 changes: 4 additions & 3 deletions 1_chat_models/5_chat_model_save_message_history_firebase.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
# Example Source: https://python.langchain.com/v0.2/docs/integrations/memory/google_firestore/

from dotenv import load_dotenv
from google.auth import compute_engine
from google.cloud import firestore
from langchain_google_firestore import FirestoreChatMessageHistory
from langchain_openai import ChatOpenAI
Expand All @@ -17,14 +16,15 @@
- Authenticate the Google Cloud CLI with your Google account
- https://cloud.google.com/docs/authentication/provide-credentials-adc#local-dev
- Set your default project to the new Firebase project you created
5.
5. Enable the Firestore API in the Google Cloud Console:
- https://console.cloud.google.com/apis/enableflow?apiid=firestore.googleapis.com&project=crewai-automation
"""

load_dotenv()

# Setup Firebase Firestore
PROJECT_ID = "langchain-demo-abf48"
SESSION_ID = "user1_session" # This could be a username or a unique ID
SESSION_ID = "user_session_new" # This could be a username or a unique ID
COLLECTION_NAME = "chat_history"

# Initialize Firestore Client
Expand All @@ -39,6 +39,7 @@
client=client,
)
print("Chat History Initialized.")
print("Current Chat History:", chat_history.messages)

# Initialize Chat Model
model = ChatOpenAI()
Expand Down

0 comments on commit e070f8f

Please sign in to comment.