-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
37e47c4
commit c18e4cd
Showing
35 changed files
with
444 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
# Licensed to the Apache Software Foundation (ASF) under one | ||
# | ||
# or more contributor license agreements. See the NOTICE file | ||
# distributed with this work for additional information | ||
# regarding copyright ownership. The ASF licenses this file | ||
# to you under the Apache License, Version 2.0 (the | ||
# "License"); you may not use this file except in compliance | ||
# with the License. You may obtain a copy of the License at | ||
# | ||
# http://www.apache.org/licenses/LICENSE-2.0 | ||
# | ||
# Unless required by applicable law or agreed to in writing, | ||
# software distributed under the License is distributed on an | ||
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY | ||
# KIND, either express or implied. See the License for the | ||
# specific language governing permissions and limitations | ||
# under the License. | ||
# | ||
.DS_Store | ||
.*-version | ||
__pycache__/ | ||
**/lab/deploy/ | ||
.vscode/ | ||
*/addr/ | ||
node_modules/ | ||
.git-hooks |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
#--kind python:default | ||
#--param OPENAI_API_KEY $OPENAI_API_KEY | ||
#--param OPENAI_API_HOST $OPENAI_API_HOST | ||
|
||
import chat | ||
|
||
def main(args): | ||
#print(args) | ||
ai = chat.Chat(args) | ||
inp = args.get("input", "") | ||
out = "Please provide some input" | ||
if inp != "": | ||
out = ai.ask(inp) | ||
|
||
res = { | ||
"output": out | ||
} | ||
|
||
html = f"<h1>{inp}</h1><p>{out}</p>" | ||
res['html'] = html | ||
return { | ||
"body": res | ||
} | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
from openai import AzureOpenAI | ||
|
||
ROLE = "You are an helpful assistant" | ||
MODEL = "gpt-35-turbo" | ||
|
||
class Chat: | ||
|
||
def __init__(self, args): | ||
key = args.get("OPENAI_API_KEY") | ||
host = args.get("OPENAI_API_HOST") | ||
self.ai = AzureOpenAI(api_version="2023-12-01-preview", api_key=key, azure_endpoint=host) | ||
|
||
def req(self, inp, role): | ||
system = {"role": "system", "content": role } | ||
user = {"role": "user", "content": inp} | ||
request = [system, user] | ||
return request | ||
|
||
def ask(self, input, role=ROLE): | ||
request = self.req(input, role) | ||
comp = self.ai.chat.completions.create(model=MODEL, messages=request) | ||
content = "ERROR" | ||
if len(comp.choices) > 0: | ||
content = comp.choices[0].message.content | ||
return content |
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,170 @@ | ||
--- | ||
marp: true | ||
theme: gaia | ||
_class: lead | ||
paginate: true | ||
backgroundColor: #fff | ||
backgroundImage: url('https://marp.app/assets/hero-background.jpg') | ||
html: true | ||
style: | | ||
.columns { | ||
diplay: grid; | ||
grid-template-columns: repeat(2, minmax(0,1fr)); | ||
gap: 1rem; | ||
} | ||
--- | ||
|
||
![bg left:40% 80%](./image/logo-full-transparent.png) | ||
|
||
# **Building a Serverless LLM application** | ||
|
||
### using Nuvolaris and MastroGPT | ||
|
||
[email protected] | ||
|
||
--- | ||
# Agenda | ||
|
||
- #### Nuvolaris & MastroGPT | ||
- #### Some Pyhton and VSCode tricks | ||
- #### Adding a new chat | ||
- #### Accessing to OpenAI | ||
- #### Interacting with a website | ||
|
||
![bg right:50% 90%](image/overview.png) | ||
|
||
--- | ||
![bg](https://fakeimg.pl/1600x800/fff/000/?text=Architecture) | ||
|
||
--- | ||
![bg](image/nuvolaris-architecture.png) | ||
|
||
--- | ||
![bg 90%](image/nuvolaris-admin.png) | ||
|
||
--- | ||
|
||
![bg 85%](image/nuvolaris-ide.png) | ||
|
||
--- | ||
|
||
![bg 80%](image/nuvolaris-mastrogpt.png) | ||
|
||
|
||
--- | ||
|
||
![bg](https://fakeimg.pl/1600x800/fff/000/?text=Python+Tricks) | ||
|
||
|
||
--- | ||
|
||
# The Python Cli | ||
|
||
Using `ipython` with the required libraries | ||
|
||
``` | ||
nuv -login https://nuvolaris.dev msciabarra | ||
nuv ide python cli | ||
``` | ||
|
||
Use the env vars for the app: | ||
|
||
```python | ||
import os | ||
args = os.environ | ||
``` | ||
|
||
--- | ||
# VScode Keybinding `^+enter` | ||
|
||
- Open "keyboad shortcuts" | ||
- search **runSelectedTextInActiveTerminal** | ||
- assign `ˆ+Enter` | ||
|
||
|
||
--- | ||
|
||
![bg](https://fakeimg.pl/1600x800/fff/000/?text=Adding+a+new+chat) | ||
|
||
--- | ||
|
||
# Create a new chat | ||
|
||
- copy "examples/withreqs" | ||
|
||
- put `html-sanitizer` in `requirements` | ||
|
||
--- | ||
# The new chat | ||
|
||
```python | ||
inp = args.get("input", "") | ||
out = "Please provide some input" | ||
if inp != "": | ||
out = inp[::-1] | ||
res = { | ||
"output": out | ||
} | ||
return { | ||
"body": res | ||
} | ||
``` | ||
|
||
--- | ||
# Adding to `mastrogpt/index.py` | ||
|
||
Adding the new chat to the index | ||
|
||
```python | ||
{ | ||
"name": "Search", | ||
"url": "search/website" | ||
}, | ||
``` | ||
--- | ||
|
||
# HTML Output | ||
|
||
``` | ||
html = f"<h1>{inp}</h1><p>{out}</p>" | ||
res['html'] = html | ||
``` | ||
|
||
--- | ||
|
||
![bg](https://fakeimg.pl/1600x800/fff/000/?text=Accessing+OpenAI) | ||
|
||
--- | ||
|
||
# class `Chat` | ||
|
||
```python | ||
from openai import AzureOpenAI | ||
|
||
ROLE = "You are an helpful assistant" | ||
MODEL = "gpt-35-turbo" | ||
|
||
class Chat: | ||
|
||
def __init__(self, args): | ||
key = args.get("OPENAI_API_KEY") | ||
host = args.get("OPENAI_API_HOST") | ||
self.ai = AzureOpenAI(api_version="2023-12-01-preview", api_key=key, azure_endpoint=host) | ||
|
||
``` | ||
--- | ||
|
||
# `Chat.ask` | ||
|
||
```python | ||
def ask(self, inp, role=ROLE): | ||
system = {"role": "system", "content": role } | ||
user = {"role": "user", "content": inp} | ||
request = [system, user] | ||
comp = self.ai.chat.completions.create(model=MODEL, messages=request) | ||
content = "ERROR" | ||
if len(comp.choices) > 0: | ||
content = comp.choices[0].message.content | ||
return content | ||
``` | ||
|
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
<!-- | ||
~ Licensed to the Apache Software Foundation (ASF) under one | ||
~ or more contributor license agreements. See the NOTICE file | ||
~ distributed with this work for additional information | ||
~ regarding copyright ownership. The ASF licenses this file | ||
~ to you under the Apache License, Version 2.0 (the | ||
~ "License"); you may not use this file except in compliance | ||
~ with the License. You may obtain a copy of the License at | ||
~ | ||
~ http://www.apache.org/licenses/LICENSE-2.0 | ||
~ | ||
~ Unless required by applicable law or agreed to in writing, | ||
~ software distributed under the License is distributed on an | ||
~ "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY | ||
~ KIND, either express or implied. See the License for the | ||
~ specific language governing permissions and limitations | ||
~ under the License. | ||
~ | ||
--> | ||
# nuvolaris-training | ||
|
||
You need to | ||
|
||
- Install the SF Mono font | ||
- Install the Slides Extension | ||
- Associate the command "Terminal: Run Selected Text in Active Terminal" to "control-enter" | ||
- Open the folder | ||
|
||
You are ready. | ||
|
||
Remember those keys: | ||
|
||
- `control-shift-p` to enter in presentation mode | ||
- `control-shift-forward` and `control-shift-backward` to move | ||
- `control-j` to open/close the terminal | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
# Build script for presentations | ||
|
||
- Marp CLI: `npm install --save-dev @marp-team/marp-cli` | ||
- IPython: `pip3 install ipython` | ||
|
||
# Presentation | ||
|
||
You can present with the VSCode Slides plugin. | ||
|
||
You need: | ||
|
||
- Install VS Code | ||
- Install on VS Code: Slides, 'GitHub Clean White' theme | ||
- Install the SF Mono font | ||
- Associate the command "Terminal: Run Selected Text in Active Terminal" to "control-enter" | ||
|
||
Now, open the `pres` folder and enter in presentation mode. | ||
|
||
Remember those keys: | ||
|
||
- `control-shift-p` to enter in presentation mode | ||
- `control-shift-forward` and `control-shift-backward` to move | ||
- `control-j` to open/close the terminal | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
CUR=${1:?target file} | ||
if ! test -f "$CUR" | ||
then echo "$CUR does not exist" ; exit 1 | ||
fi | ||
DIR=$(dirname "$CUR") | ||
rm -Rvf $DIR/pres | ||
rm -f $DIR/pres.pdf | ||
if ! test -e ~/.local/bin/ipython | ||
then python3 -m pip install ipython | ||
fi | ||
if ! test -e ~/node_modules/bin/marp | ||
then cd ~ ; npm install @marp-team/marp-cli ; cd - | ||
fi | ||
export PATH=~/.local/bin:~/node_modules/.bin:$PATH | ||
ipython convert.ipy $CUR |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
import re, sys, tempfile | ||
import random | ||
if len(sys.argv) < 2: | ||
print("usage: <input>") | ||
sys.exit() | ||
input = sys.argv[1] | ||
file = input.split("/")[-1] | ||
dir = input[0:-len(file)] | ||
name = file[0:-3] | ||
tmpdir = f"/tmp/convert{random.randint(1000,10000)}" | ||
outdir = f"{dir}/pres" | ||
!mkdir -p {tmpdir} {outdir} | ||
!marp --allow-local-files -o {tmpdir}/{name} --images png {input} | ||
!marp --allow-local-files {input} -o {dir}/{name}.pdf --pdf | ||
|
||
def copy(src, dst): | ||
!cp {src} {dst} | ||
#pass | ||
|
||
def slurp_file(f, dst): | ||
print("*** slurp_file") | ||
with open(dst, "w") as out: | ||
while True: | ||
line = f.readline() | ||
if line.rstrip() == '```': return | ||
out.write(line) | ||
#print(">>>", line) | ||
|
||
count = -1 | ||
line = "" | ||
f = open(input, "r") | ||
|
||
while True: | ||
line = f.readline() | ||
if not line: break | ||
line = line.rstrip() | ||
if line != "---": | ||
continue | ||
count +=1 | ||
if count < 1: continue | ||
prefix = f"{tmpdir}/{name}.%03d." % count | ||
curr = "%spng" % prefix | ||
#print(prefix) | ||
line = f.readline() | ||
if not line: break | ||
if line.find("<!--!-->") != -1: | ||
line = f.readline() | ||
line = line.rstrip() | ||
if line.startswith("![") and not line.find("(http"): | ||
m = re.search('\((.*/(.*))\)', line) | ||
src = f"{dir}/{m.group(1)}" | ||
dst = f"{outdir}/{name}.%03d.png" % count | ||
print("copy_img", src, dst) | ||
copy(src,dst) | ||
elif line.startswith('```'): | ||
ext = line[3:] | ||
dst = f"{outdir}/{name}.%03d.%s" % (count,ext) | ||
print("slurp_file", dst ) | ||
slurp_file(f, dst) | ||
else: | ||
dst = f"{outdir}/{name}.%03d.png" % count | ||
print("copy_file",curr,dst) | ||
copy(curr[0:-4],dst) |
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Oops, something went wrong.