semioz commited on
Commit
69578a4
·
1 Parent(s): 7f4fddc
Files changed (3) hide show
  1. agent.py +8 -7
  2. app.py +2 -1
  3. pyproject.toml +0 -2
agent.py CHANGED
@@ -1,4 +1,9 @@
1
  import logging
 
 
 
 
 
2
  from langchain_groq import ChatGroq
3
  from langchain_huggingface import (
4
  ChatHuggingFace,
@@ -7,13 +12,9 @@ from langchain_huggingface import (
7
  )
8
  from langgraph.graph import START, MessagesState, StateGraph
9
  from langgraph.prebuilt import ToolNode, tools_condition
10
- from langchain_community.vectorstores import SupabaseVectorStore
11
- from langchain.tools.retriever import create_retriever_tool
12
  from supabase.client import Client, create_client
13
- from langchain_core.messages import HumanMessage, SystemMessage
14
 
15
  from tools import tools
16
- import os
17
 
18
  logger = logging.getLogger(__name__)
19
 
@@ -31,7 +32,7 @@ embeddings = HuggingFaceEmbeddings(
31
  )
32
 
33
  supabase: Client = create_client(
34
- os.environ.get("SUPABASE_URL"),
35
  os.environ.get("SUPABASE_SERVICE_KEY"))
36
  vector_store = SupabaseVectorStore(
37
  client=supabase,
@@ -61,14 +62,14 @@ def build_graph(provider: str = "groq"):
61
  )
62
  else:
63
  raise ValueError("Invalid provider. Choose 'groq' or 'huggingface'.")
64
- llm_with_tools = llm.bind_tools(tools)
65
 
66
  # Node
67
  def assistant(state: MessagesState):
68
  """Assistant node"""
69
  return {"messages": [llm_with_tools.invoke(state["messages"])]}
70
 
71
-
72
  def retriever(state: MessagesState):
73
  """Retriever node"""
74
  similar_question = vector_store.similarity_search(state["messages"][0].content)
 
1
  import logging
2
+ import os
3
+
4
+ from langchain.tools.retriever import create_retriever_tool
5
+ from langchain_community.vectorstores import SupabaseVectorStore
6
+ from langchain_core.messages import HumanMessage, SystemMessage
7
  from langchain_groq import ChatGroq
8
  from langchain_huggingface import (
9
  ChatHuggingFace,
 
12
  )
13
  from langgraph.graph import START, MessagesState, StateGraph
14
  from langgraph.prebuilt import ToolNode, tools_condition
 
 
15
  from supabase.client import Client, create_client
 
16
 
17
  from tools import tools
 
18
 
19
  logger = logging.getLogger(__name__)
20
 
 
32
  )
33
 
34
  supabase: Client = create_client(
35
+ os.environ.get("SUPABASE_URL"),
36
  os.environ.get("SUPABASE_SERVICE_KEY"))
37
  vector_store = SupabaseVectorStore(
38
  client=supabase,
 
62
  )
63
  else:
64
  raise ValueError("Invalid provider. Choose 'groq' or 'huggingface'.")
65
+ llm_with_tools = llm.bind_tools(tools)
66
 
67
  # Node
68
  def assistant(state: MessagesState):
69
  """Assistant node"""
70
  return {"messages": [llm_with_tools.invoke(state["messages"])]}
71
 
72
+
73
  def retriever(state: MessagesState):
74
  """Retriever node"""
75
  similar_question = vector_store.similarity_search(state["messages"][0].content)
app.py CHANGED
@@ -1,9 +1,10 @@
1
  import os
2
 
3
- from langchain_core.messages import HumanMessage
4
  import gradio as gr
5
  import pandas as pd
6
  import requests
 
 
7
  from agent import build_graph
8
 
9
  DEFAULT_API_URL = "https://agents-course-unit4-scoring.hf.space"
 
1
  import os
2
 
 
3
  import gradio as gr
4
  import pandas as pd
5
  import requests
6
+ from langchain_core.messages import HumanMessage
7
+
8
  from agent import build_graph
9
 
10
  DEFAULT_API_URL = "https://agents-course-unit4-scoring.hf.space"
pyproject.toml CHANGED
@@ -18,11 +18,9 @@ dependencies = [
18
  extend-select = [
19
  "F", # Pyflakes rules
20
  "W", # PyCodeStyle warnings
21
- "E", # PyCodeStyle errors
22
  "I", # Sort imports properly
23
  "UP", # Warn if certain things can changed due to newer Python versions
24
  "C4", # Catch incorrect use of comprehensions, dict, list, etc
25
- "FA", # Enforce from __future__ import annotations
26
  "ISC", # Good use of string concatenation
27
  "ICN", # Use common import conventions
28
  "RET", # Good return practices
 
18
  extend-select = [
19
  "F", # Pyflakes rules
20
  "W", # PyCodeStyle warnings
 
21
  "I", # Sort imports properly
22
  "UP", # Warn if certain things can changed due to newer Python versions
23
  "C4", # Catch incorrect use of comprehensions, dict, list, etc
 
24
  "ISC", # Good use of string concatenation
25
  "ICN", # Use common import conventions
26
  "RET", # Good return practices