Download agent.py from mhmdabd/Chatbot: direct link, hf CLI and curl.
- Browser
- Download file 827 Bytes
-
https://huggingface.co/spaces/mhmdabd/Chatbot/resolve/main/agent.py
- Command line
-
hf download hf://spaces/mhmdabd/Chatbot/agent.py
-
curl -L -o agent.py https://huggingface.co/spaces/mhmdabd/Chatbot/resolve/main/agent.py
827 Bytes
| from langchain_openai import ChatOpenAI | |
| from dotenv import load_dotenv | |
| from os import getenv | |
| import os | |
| # Initialize OpenAI model | |
| from langchain_groq import ChatGroq | |
| load_dotenv() | |
| groq_api_key = os.environ['GROQ_API_KEY'] | |
| llm = ChatGroq(groq_api_key=groq_api_key, model_name="openai/gpt-oss-20b") | |
| from typing import TypedDict, Annotated | |
| from langgraph.graph import StateGraph, END, add_messages | |
| class BasicChatState(TypedDict): | |
| messages: Annotated[list, add_messages] | |
| def chatbot(state: BasicChatState): | |
| return { | |
| "messages": [llm.invoke(state["messages"])] | |
| } | |
| # Create LangGraph nodes and edges | |
| graph = StateGraph(BasicChatState) | |
| graph.add_node("chatbot", chatbot) | |
| graph.add_edge("chatbot", END) | |
| # Set graph entry point | |
| graph.set_entry_point("chatbot") | |
| # Compile the graph | |
| chat_agent = graph.compile() |