maclenn77 commited on
Commit
4299b71
·
unverified ·
1 Parent(s): 5065960

Update project (#32)

Browse files

* Update and add specific requirements

* Update agent

* Update requirements for HF

* Apply pylint suggestions

.python-version CHANGED
@@ -1 +1 @@
1
- 3.10.14
 
1
+ 3.11.9
GnosisPages.py CHANGED
@@ -1,18 +1,19 @@
1
  # pylint: disable=invalid-name
2
  """ A Streamlit app for GnosisPages. """
3
  import os
4
- import streamlit as st
 
5
  import openai
 
6
  from dotenv import load_dotenv
 
7
  from gnosis.chroma_client import ChromaDB
8
  import gnosis.gui_messages as gm
9
  from gnosis import settings
10
  from gnosis.components.sidebar import sidebar
11
  from gnosis.components.main import main
12
 
13
-
14
- load_dotenv()
15
-
16
 
17
  openai.api_key = os.getenv("OPENAI_API_KEY")
18
 
 
1
  # pylint: disable=invalid-name
2
  """ A Streamlit app for GnosisPages. """
3
  import os
4
+ from pathlib import Path
5
+
6
  import openai
7
+ import streamlit as st
8
  from dotenv import load_dotenv
9
+
10
  from gnosis.chroma_client import ChromaDB
11
  import gnosis.gui_messages as gm
12
  from gnosis import settings
13
  from gnosis.components.sidebar import sidebar
14
  from gnosis.components.main import main
15
 
16
+ load_dotenv(Path(__file__).parent / ".env")
 
 
17
 
18
  openai.api_key = os.getenv("OPENAI_API_KEY")
19
 
gnosis/agent.py CHANGED
@@ -14,7 +14,7 @@ class PDFExplainer:
14
  self.tools = [
15
  Tool.from_function(
16
  func=search.run,
17
- name="Search on ChromaDB",
18
  description="Useful when you need more context for answering a question.",
19
  handle_parsing_errors=True,
20
  )
@@ -26,7 +26,8 @@ class PDFExplainer:
26
  self.agent = initialize_agent(
27
  self.tools,
28
  llm,
29
- agent=AgentType.ZERO_SHOT_REACT_DESCRIPTION,
 
30
  verbose=False,
31
  handle_parsing_errors=True,
32
  )
 
14
  self.tools = [
15
  Tool.from_function(
16
  func=search.run,
17
+ name="Search_on_ChromaDB",
18
  description="Useful when you need more context for answering a question.",
19
  handle_parsing_errors=True,
20
  )
 
26
  self.agent = initialize_agent(
27
  self.tools,
28
  llm,
29
+ #agent=AgentType.ZERO_SHOT_REACT_DESCRIPTION,
30
+ agent=AgentType.OPENAI_FUNCTIONS, # ← uses OpenAI's native function calling
31
  verbose=False,
32
  handle_parsing_errors=True,
33
  )
gnosis/builder.py CHANGED
@@ -1,24 +1,34 @@
1
  """Module for building the Langchain Agent"""
 
 
2
  import streamlit as st
 
3
  from langchain_openai import ChatOpenAI
4
- from gnosis.agent import PDFExplainer
5
 
 
6
 
7
  def build(key, client):
8
  """An Agent builder"""
9
  # Build Agent
10
  try:
 
11
  llm = ChatOpenAI(
12
  temperature=st.session_state.temperature,
13
  model="gpt-4o-mini",
14
- api_key=key,
15
- )
16
  agent = PDFExplainer(
17
  llm,
18
  client,
19
  extra_tools=st.session_state.wk_button,
20
  ).agent
21
- except Exception: # pylint: disable=broad-exception-caught
22
- st.warning("Missing OpenAI API Key.")
 
 
 
 
 
 
23
 
24
  return agent
 
1
  """Module for building the Langchain Agent"""
2
+ import os
3
+
4
  import streamlit as st
5
+ from openai import AuthenticationError, APIConnectionError, BadRequestError
6
  from langchain_openai import ChatOpenAI
 
7
 
8
+ from gnosis.agent import PDFExplainer
9
 
10
  def build(key, client):
11
  """An Agent builder"""
12
  # Build Agent
13
  try:
14
+ key = os.environ.get("OPENAI_API_KEY") or key
15
  llm = ChatOpenAI(
16
  temperature=st.session_state.temperature,
17
  model="gpt-4o-mini",
18
+ api_key=key
19
+ )
20
  agent = PDFExplainer(
21
  llm,
22
  client,
23
  extra_tools=st.session_state.wk_button,
24
  ).agent
25
+ except AuthenticationError:
26
+ st.warning("Invalid OpenAI API Key. Check your credentials.")
27
+ except APIConnectionError:
28
+ st.warning("Could not connect to OpenAI. Check your network connection.")
29
+ except BadRequestError as e:
30
+ st.warning(f"Bad request: {e}")
31
+ except ValueError as e:
32
+ st.warning(f"Configuration error: {e}")
33
 
34
  return agent
requirements.txt CHANGED
@@ -1,8 +1,161 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
  chromadb==0.5.7
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
2
  langchain-community==0.3.0
3
- langchain_openai==0.2.0
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
4
  openai==1.47.1
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
5
  python-dotenv==1.0.1
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
6
  streamlit==1.38.0
 
7
  tiktoken==0.7.0
8
- PyMuPDF==1.24.10
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ aiohappyeyeballs==2.6.2
2
+ aiohttp==3.14.1
3
+ aiosignal==1.4.0
4
+ altair==5.5.0
5
+ annotated-doc==0.0.4
6
+ annotated-types==0.7.0
7
+ anyio==4.13.0
8
+ appnope==0.1.4
9
+ asgiref==3.11.1
10
+ asttokens==3.0.0
11
+ attrs==25.3.0
12
+ backoff==2.2.1
13
+ bcrypt==5.0.0
14
+ blinker==1.9.0
15
+ build==1.5.0
16
+ cachetools==5.5.2
17
+ certifi==2025.4.26
18
+ charset-normalizer==3.4.2
19
+ chroma-hnswlib==0.7.6
20
  chromadb==0.5.7
21
+ click==8.4.1
22
+ comm==0.2.3
23
+ contourpy==1.3.3
24
+ cycler==0.12.1
25
+ dataclasses-json==0.6.7
26
+ debugpy==1.8.17
27
+ decorator==5.2.1
28
+ distro==1.9.0
29
+ durationpy==0.10
30
+ executing==2.2.1
31
+ fastapi==0.136.3
32
+ ffmpeg==1.4
33
+ filelock==3.29.4
34
+ flatbuffers==25.12.19
35
+ fonttools==4.60.0
36
+ frozenlist==1.8.0
37
+ fsspec==2026.4.0
38
+ gitdb==4.0.12
39
+ GitPython==3.1.44
40
+ googleapis-common-protos==1.75.0
41
+ grpcio==1.81.1
42
+ h11==0.16.0
43
+ hf-xet==1.5.1
44
+ httpcore==1.0.9
45
+ httptools==0.8.0
46
+ httpx==0.28.1
47
+ huggingface_hub==1.19.0
48
+ idna==3.10
49
+ importlib_resources==7.1.0
50
+ ipykernel==6.30.1
51
+ ipython==9.5.0
52
+ ipython_pygments_lexers==1.1.1
53
+ jedi==0.19.2
54
+ Jinja2==3.1.6
55
+ jiter==0.15.0
56
+ jsonpatch==1.33
57
+ jsonpointer==3.1.1
58
+ jsonschema==4.23.0
59
+ jsonschema-specifications==2025.4.1
60
+ jupyter_client==8.6.3
61
+ jupyter_core==5.8.1
62
+ kiwisolver==1.4.9
63
+ kubernetes==36.0.2
64
+ langchain==0.3.25
65
  langchain-community==0.3.0
66
+ langchain-core==0.3.63
67
+ langchain-openai==0.2.0
68
+ langchain-text-splitters==0.3.8
69
+ langsmith==0.1.147
70
+ markdown-it-py==4.2.0
71
+ MarkupSafe==3.0.2
72
+ marshmallow==3.26.2
73
+ matplotlib==3.10.6
74
+ matplotlib-inline==0.1.7
75
+ mdurl==0.1.2
76
+ mmh3==5.2.1
77
+ multidict==6.7.1
78
+ mypy_extensions==1.1.0
79
+ narwhals==1.40.0
80
+ nest-asyncio==1.6.0
81
+ numpy==1.26.4
82
+ oauthlib==3.3.1
83
+ onnxruntime==1.26.0
84
  openai==1.47.1
85
+ opentelemetry-api==1.42.1
86
+ opentelemetry-exporter-otlp-proto-common==1.42.1
87
+ opentelemetry-exporter-otlp-proto-grpc==1.42.1
88
+ opentelemetry-instrumentation==0.63b1
89
+ opentelemetry-instrumentation-asgi==0.63b1
90
+ opentelemetry-instrumentation-fastapi==0.63b1
91
+ opentelemetry-proto==1.42.1
92
+ opentelemetry-sdk==1.42.1
93
+ opentelemetry-semantic-conventions==0.63b1
94
+ opentelemetry-util-http==0.63b1
95
+ orjson==3.11.9
96
+ overrides==7.7.0
97
+ packaging==24.2
98
+ pandas==2.2.3
99
+ parso==0.8.5
100
+ pexpect==4.9.0
101
+ pillow==10.4.0
102
+ platformdirs==4.4.0
103
+ posthog==7.18.3
104
+ prompt_toolkit==3.0.52
105
+ propcache==0.5.2
106
+ protobuf==5.29.6
107
+ psutil==7.1.0
108
+ ptyprocess==0.7.0
109
+ pure_eval==0.2.3
110
+ pyarrow==20.0.0
111
+ pydantic==2.13.4
112
+ pydantic-settings==2.14.1
113
+ pydantic_core==2.46.4
114
+ pydeck==0.9.1
115
+ Pygments==2.19.2
116
+ PyMuPDF==1.24.10
117
+ PyMuPDFb==1.24.10
118
+ pyparsing==3.2.5
119
+ PyPika==0.51.1
120
+ pyproject_hooks==1.2.0
121
+ python-dateutil==2.9.0.post0
122
  python-dotenv==1.0.1
123
+ pytz==2025.2
124
+ PyYAML==6.0.3
125
+ pyzmq==27.1.0
126
+ referencing==0.36.2
127
+ regex==2026.5.9
128
+ requests==2.32.3
129
+ requests-oauthlib==2.0.0
130
+ requests-toolbelt==1.0.0
131
+ rich==13.9.4
132
+ rpds-py==0.25.1
133
+ shellingham==1.5.4
134
+ six==1.17.0
135
+ smmap==5.0.2
136
+ sniffio==1.3.1
137
+ SQLAlchemy==2.0.50
138
+ stack-data==0.6.3
139
+ starlette==1.3.1
140
  streamlit==1.38.0
141
+ tenacity==8.5.0
142
  tiktoken==0.7.0
143
+ tokenizers==0.23.1
144
+ toml==0.10.2
145
+ tornado==6.5.1
146
+ tqdm==4.68.2
147
+ traitlets==5.14.3
148
+ typer==0.25.1
149
+ typing-inspect==0.9.0
150
+ typing-inspection==0.4.2
151
+ typing_extensions==4.15.0
152
+ tzdata==2025.2
153
+ urllib3==2.4.0
154
+ uvicorn==0.49.0
155
+ uvloop==0.22.1
156
+ watchfiles==1.2.0
157
+ wcwidth==0.2.13
158
+ websocket-client==1.9.0
159
+ websockets==16.0
160
+ wrapt==2.2.1
161
+ yarl==1.24.2
wk_flow_requirements.txt CHANGED
@@ -1,8 +1,161 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
  chromadb==0.5.7
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
2
  langchain-community==0.3.0
3
- langchain_openai==0.2.0
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
4
  openai==1.47.1
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
5
  python-dotenv==1.0.1
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
6
  streamlit==1.38.0
 
7
  tiktoken==0.7.0
8
- PyMuPDF==1.24.10
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ aiohappyeyeballs==2.6.2
2
+ aiohttp==3.14.1
3
+ aiosignal==1.4.0
4
+ altair==5.5.0
5
+ annotated-doc==0.0.4
6
+ annotated-types==0.7.0
7
+ anyio==4.13.0
8
+ appnope==0.1.4
9
+ asgiref==3.11.1
10
+ asttokens==3.0.0
11
+ attrs==25.3.0
12
+ backoff==2.2.1
13
+ bcrypt==5.0.0
14
+ blinker==1.9.0
15
+ build==1.5.0
16
+ cachetools==5.5.2
17
+ certifi==2025.4.26
18
+ charset-normalizer==3.4.2
19
+ chroma-hnswlib==0.7.6
20
  chromadb==0.5.7
21
+ click==8.4.1
22
+ comm==0.2.3
23
+ contourpy==1.3.3
24
+ cycler==0.12.1
25
+ dataclasses-json==0.6.7
26
+ debugpy==1.8.17
27
+ decorator==5.2.1
28
+ distro==1.9.0
29
+ durationpy==0.10
30
+ executing==2.2.1
31
+ fastapi==0.136.3
32
+ ffmpeg==1.4
33
+ filelock==3.29.4
34
+ flatbuffers==25.12.19
35
+ fonttools==4.60.0
36
+ frozenlist==1.8.0
37
+ fsspec==2026.4.0
38
+ gitdb==4.0.12
39
+ GitPython==3.1.44
40
+ googleapis-common-protos==1.75.0
41
+ grpcio==1.81.1
42
+ h11==0.16.0
43
+ hf-xet==1.5.1
44
+ httpcore==1.0.9
45
+ httptools==0.8.0
46
+ httpx==0.28.1
47
+ huggingface_hub==1.19.0
48
+ idna==3.10
49
+ importlib_resources==7.1.0
50
+ ipykernel==6.30.1
51
+ ipython==9.5.0
52
+ ipython_pygments_lexers==1.1.1
53
+ jedi==0.19.2
54
+ Jinja2==3.1.6
55
+ jiter==0.15.0
56
+ jsonpatch==1.33
57
+ jsonpointer==3.1.1
58
+ jsonschema==4.23.0
59
+ jsonschema-specifications==2025.4.1
60
+ jupyter_client==8.6.3
61
+ jupyter_core==5.8.1
62
+ kiwisolver==1.4.9
63
+ kubernetes==36.0.2
64
+ langchain==0.3.25
65
  langchain-community==0.3.0
66
+ langchain-core==0.3.63
67
+ langchain-openai==0.2.0
68
+ langchain-text-splitters==0.3.8
69
+ langsmith==0.1.147
70
+ markdown-it-py==4.2.0
71
+ MarkupSafe==3.0.2
72
+ marshmallow==3.26.2
73
+ matplotlib==3.10.6
74
+ matplotlib-inline==0.1.7
75
+ mdurl==0.1.2
76
+ mmh3==5.2.1
77
+ multidict==6.7.1
78
+ mypy_extensions==1.1.0
79
+ narwhals==1.40.0
80
+ nest-asyncio==1.6.0
81
+ numpy==1.26.4
82
+ oauthlib==3.3.1
83
+ onnxruntime==1.26.0
84
  openai==1.47.1
85
+ opentelemetry-api==1.42.1
86
+ opentelemetry-exporter-otlp-proto-common==1.42.1
87
+ opentelemetry-exporter-otlp-proto-grpc==1.42.1
88
+ opentelemetry-instrumentation==0.63b1
89
+ opentelemetry-instrumentation-asgi==0.63b1
90
+ opentelemetry-instrumentation-fastapi==0.63b1
91
+ opentelemetry-proto==1.42.1
92
+ opentelemetry-sdk==1.42.1
93
+ opentelemetry-semantic-conventions==0.63b1
94
+ opentelemetry-util-http==0.63b1
95
+ orjson==3.11.9
96
+ overrides==7.7.0
97
+ packaging==24.2
98
+ pandas==2.2.3
99
+ parso==0.8.5
100
+ pexpect==4.9.0
101
+ pillow==10.4.0
102
+ platformdirs==4.4.0
103
+ posthog==7.18.3
104
+ prompt_toolkit==3.0.52
105
+ propcache==0.5.2
106
+ protobuf==5.29.6
107
+ psutil==7.1.0
108
+ ptyprocess==0.7.0
109
+ pure_eval==0.2.3
110
+ pyarrow==20.0.0
111
+ pydantic==2.13.4
112
+ pydantic-settings==2.14.1
113
+ pydantic_core==2.46.4
114
+ pydeck==0.9.1
115
+ Pygments==2.19.2
116
+ PyMuPDF==1.24.10
117
+ PyMuPDFb==1.24.10
118
+ pyparsing==3.2.5
119
+ PyPika==0.51.1
120
+ pyproject_hooks==1.2.0
121
+ python-dateutil==2.9.0.post0
122
  python-dotenv==1.0.1
123
+ pytz==2025.2
124
+ PyYAML==6.0.3
125
+ pyzmq==27.1.0
126
+ referencing==0.36.2
127
+ regex==2026.5.9
128
+ requests==2.32.3
129
+ requests-oauthlib==2.0.0
130
+ requests-toolbelt==1.0.0
131
+ rich==13.9.4
132
+ rpds-py==0.25.1
133
+ shellingham==1.5.4
134
+ six==1.17.0
135
+ smmap==5.0.2
136
+ sniffio==1.3.1
137
+ SQLAlchemy==2.0.50
138
+ stack-data==0.6.3
139
+ starlette==1.3.1
140
  streamlit==1.38.0
141
+ tenacity==8.5.0
142
  tiktoken==0.7.0
143
+ tokenizers==0.23.1
144
+ toml==0.10.2
145
+ tornado==6.5.1
146
+ tqdm==4.68.2
147
+ traitlets==5.14.3
148
+ typer==0.25.1
149
+ typing-inspect==0.9.0
150
+ typing-inspection==0.4.2
151
+ typing_extensions==4.15.0
152
+ tzdata==2025.2
153
+ urllib3==2.4.0
154
+ uvicorn==0.49.0
155
+ uvloop==0.22.1
156
+ watchfiles==1.2.0
157
+ wcwidth==0.2.13
158
+ websocket-client==1.9.0
159
+ websockets==16.0
160
+ wrapt==2.2.1
161
+ yarl==1.24.2