Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
J
jupyterhub-ai
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Requirements
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Locked files
Build
Pipelines
Jobs
Pipeline schedules
Test cases
Artifacts
Deploy
Releases
Package registry
Container Registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Service Desk
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Code review analytics
Issue analytics
Insights
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Julian Rasch
jupyterhub-ai
Commits
783fe058
Commit
783fe058
authored
11 months ago
by
Julian
Browse files
Options
Downloads
Patches
Plain Diff
removed flake8 due to errors, simplified client
parent
f50deb01
No related branches found
No related tags found
No related merge requests found
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
Dockerfile
+1
-3
1 addition, 3 deletions
Dockerfile
app/callbacks.py
+11
-3
11 additions, 3 deletions
app/callbacks.py
llm_utils/src/llm_utils/client.py
+16
-22
16 additions, 22 deletions
llm_utils/src/llm_utils/client.py
with
28 additions
and
28 deletions
Dockerfile
+
1
−
3
View file @
783fe058
...
...
@@ -9,14 +9,12 @@ RUN conda env update -q -f /tmp/environment.yml && \
conda
env export
-n
"root"
&&
\
jupyter lab build
RUN
pip3
install
--upgrade
pip
RUN
pip
install
jupyterlab_flake8
COPY
dash_proxy /tmp/dash_proxy/
RUN
pip
install
/tmp/dash_proxy/
COPY
llm_utils /llm_utils/
RUN
pip
install
/llm_utils/
ENV
CONFIG_PATH=/home/jovyan/config.txt
COPY
app /dash/app/
RUN
chown
-R
jovyan /dash/app/
...
...
This diff is collapsed.
Click to expand it.
app/callbacks.py
+
11
−
3
View file @
783fe058
import
os
from
datetime
import
datetime
from
dash
import
(
...
...
@@ -10,7 +11,7 @@ from dash.dependencies import (
State
)
from
llm_utils.client
import
ChatGPT
from
llm_utils.client
import
ChatGPT
,
get_openai_client
def
format_chat_messages
(
chat_history
):
...
...
@@ -24,8 +25,15 @@ def format_chat_messages(chat_history):
def
register_callbacks
(
app
:
Dash
):
chat_gpt
=
ChatGPT
(
model
=
"
gpt4
"
)
model
=
"
gpt4
"
client
=
get_openai_client
(
model
=
model
,
config_path
=
os
.
environ
.
get
(
"
CONFIG_PATH
"
)
)
chat_gpt
=
ChatGPT
(
client
=
client
,
model
=
"
gpt4
"
)
@app.callback
(
[
Output
(
'
chat-container
'
,
'
children
'
),
...
...
This diff is collapsed.
Click to expand it.
llm_utils/src/llm_utils/client.py
+
16
−
22
View file @
783fe058
import
os
import
logging
from
openai
import
AzureOpenAI
from
dotenv
import
load_dotenv
from
enum
import
Enum
try
:
found_dotenv
=
load_dotenv
(
"
/home/jovyan/config.txt
"
,
override
=
True
)
except
ValueError
:
logging
.
warn
(
"
Could not detect config.txt in /home/jovyan/. Searching in current folder ...
"
)
found_dotenv
=
load_dotenv
(
"
config.txt
"
,
override
=
True
)
if
not
found_dotenv
:
raise
ValueError
(
"
Could not detect config.txt in /home/jovyan/.
"
)
AZURE_OPENAI_API_KEY
=
os
.
environ
.
get
(
"
AZURE_OPENAI_API_KEY
"
)
AZURE_OPENAI_ENDPOINT
=
os
.
environ
.
get
(
"
AZURE_OPENAI_ENDPOINT
"
)
OPENAI_API_VERSION
=
os
.
environ
.
get
(
"
OPENAI_API_VERSION
"
)
class
OpenAIModels
(
Enum
):
GPT_3
=
"
gpt3
"
...
...
@@ -33,13 +15,25 @@ class OpenAIModels(Enum):
return
[
member
.
value
for
member
in
cls
]
def
get_openai_client
(
model
:
str
)
->
AzureOpenAI
:
def
get_openai_client
(
model
:
str
,
config_path
:
str
)
->
AzureOpenAI
:
if
not
model
in
OpenAIModels
.
get_all_values
():
raise
ValueError
(
f
"
<model> needs to be one of
{
OpenAIModels
.
get_all_values
()
}
.
"
)
load_dotenv
(
dotenv_path
=
config_path
,
override
=
True
)
AZURE_OPENAI_API_KEY
=
os
.
environ
.
get
(
"
AZURE_OPENAI_API_KEY
"
)
AZURE_OPENAI_ENDPOINT
=
os
.
environ
.
get
(
"
AZURE_OPENAI_ENDPOINT
"
)
OPENAI_API_VERSION
=
os
.
environ
.
get
(
"
OPENAI_API_VERSION
"
)
if
any
(
p
is
None
for
p
in
(
AZURE_OPENAI_API_KEY
,
AZURE_OPENAI_API_KEY
,
OPENAI_API_VERSION
)):
raise
ValueError
(
f
"""
None of the following parameters can be
n
one:
f
"""
None of the following parameters can be
N
one:
AZURE_OPENAI_API_KEY:
{
AZURE_OPENAI_API_KEY
}
,
AZURE_OPENAI_API_KEY:
{
AZURE_OPENAI_API_KEY
}
,
OPENAI_API_VERSION:
{
OPENAI_API_VERSION
}
...
...
@@ -56,9 +50,9 @@ def get_openai_client(model: str) -> AzureOpenAI:
class
ChatGPT
:
def
__init__
(
self
,
model
=
"
gpt4
"
):
def
__init__
(
self
,
client
:
AzureOpenAI
,
model
:
str
):
self
.
model
=
model
self
.
client
=
get_openai_client
(
model
=
model
)
self
.
client
=
client
self
.
messages
=
[]
def
chat_with_gpt
(
self
,
user_input
:
str
):
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment