Skip to content

Commit

Permalink
Merge pull request #1 from oracle-devrel/work
Browse files Browse the repository at this point in the history
Branch Merge
  • Loading branch information
peppertech authored Jan 23, 2024
2 parents 3f4dc12 + ac6b626 commit 7cb8bfd
Show file tree
Hide file tree
Showing 108 changed files with 3,024 additions and 11 deletions.
6 changes: 5 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -30,4 +30,8 @@ Temporary Items
.key
.crt
.csr
.pem
.pem

#temp directory ignore
deploy/
service/python/Dockerfile
1 change: 1 addition & 0 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{}
165 changes: 155 additions & 10 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,31 +2,176 @@

[![License: UPL](https://img.shields.io/badge/license-UPL-green)](https://img.shields.io/badge/license-UPL-green) [![Quality gate](https://sonarcloud.io/api/project_badges/quality_gate?project=oracle-devrel_oci-generative-ai-jet-ui)](https://sonarcloud.io/dashboard?id=oracle-devrel_oci-generative-ai-jet-ui)

## THIS IS A NEW, BLANK REPO THAT IS NOT READY FOR USE YET. PLEASE CHECK BACK SOON!

## Introduction
MISSING

Using Oracle JET, create a user-friendly prompt-led user interface (UI) to interact with Oracle's new Generative AI service. This toolkit will configure your Generative AI Service connection so you can begin your journey with AI, or migrate your existing (local or Cloud) LLMs to the Oracle AppDev ecosystem.

Oracle JET(Preact) allows you to craft pixel-perfect UIs which are fast, lightweight, and engaging. Your code takes centre stage with Oracle JET, while its powerful features enable you to create dynamic user experiences quickly and reliably.

Oracle's Generative AI service allows developers to unlock a better user experience for chat systems, question-and-answer solutions, and much more. This project provides a front end to that service so you can experiment and get a sense of the immense power of Oracle Generative AI. This is an excellent starting point on your AI journey, and experienced developers will be able to quickly port their LLMs to leverage this powerful service.

![alt text here](images/demo.gif)

Check [demo here](https://youtu.be/hpRoQ93YeaQ)

## Getting Started
MISSING

### 0. Set up

Follow the links below to generate a config file and a key pair in your ~/.oci directory

- [SDK config](https://docs.oracle.com/en-us/iaas/Content/API/Concepts/sdkconfig.htm)
- [API signing key](https://docs.oracle.com/en-us/iaas/Content/API/Concepts/apisigningkey.htm)
- [CLI install](https://docs.oracle.com/en-us/iaas/Content/API/SDKDocs/cliinstall.htm#configfile)

After completion, you should have the following 2 things in your `~/.oci directory `

a. A config file(where key file point to private key:key_file=`~/.oci/oci_api_key.pem`)
b. A key pair named `oci_api_key.pem` and `oci_api_key_public.pem`
Now make sure you change the reference of the key file in the config file (where the key file points to private key:key_file=/YOUR_DIR_TO_KEY_FILE/oci_api_key.pem)

- Append OCI Generative-AI service compartment and endpoint URL
`vim service/python/server.py`

```Python
#TODO: Update this section with your tenancy details
compartment_id = "ocid1.compartment.oc1.."
CONFIG_PROFILE = "DEFAULT"
config = oci.config.from_file("~/.oci/config", CONFIG_PROFILE)
endpoint = "https://inference.generativeai.<REGION>.oci.oraclecloud.com"
generative_ai_inference_client = (
oci.generative_ai_inference.GenerativeAiInferenceClient(
config=config,
service_endpoint=endpoint,
retry_strategy=oci.retry.NoneRetryStrategy(),
timeout=(10, 240),
)
)
```

### 1. (Optional) Modify websocket ports

- In the root of the project directory run to edit ports
`vim app/web/components/content/index.tsx`

```Javascript
const gateway = `ws://${window.location.hostname}:1234`;
```

- Update default port in Python websocket server:
`vim service/python/server.py`

```Python
async def start_server():
await websockets.serve(handle_websocket, "localhost", 1234 )
```

### 2. Upload Public Key

- Upload your oci_api_key_public.pem to console:
[API signing key](https://docs.oracle.com/en-us/iaas/Content/API/Concepts/apisigningkey.htm#three)

### 3. Make sure you have Python installed on your machine

- In cli run the following command to validate the Python version
`python --version`

You should see similar output:

```shell
Python 3.8.3
```

### 4. Install all dependencies

We suggest you install dependencies in a virtual environment to avoid conflicts on your system.

- Navigate to the server root folder
`cd service/python`
- Create a virtual environment:
`python3 -m venv venv`
- Activate your virtual environment:
`. venv/bin/activate`
- Upgrade pip:
`pip3 install --upgrade pip`
- Install requirements:
`pip3 install -r requirements.txt`

## 5. Start the websocket server app

Once dependencies are installed and your service credentials are updated you can run server.py

- `python3 server.py`

## 6. Start JET Client

- Open app directory:
`cd ../../app ` or `cd app/` in the root folder
- Install dependencies:
`ojet restore`
- Run local version:
`ojet serve`
- Or package for web deployment
`ojet build web`

Ask question to generate LLM response.
![alt text here](images/QandA.png)

Note that sample app can generate markdown.
![alt text here](images/Markdown.png)

## Appendix: Token-based Authentication

Check [Token-based Authentication for the CLI](https://docs.oracle.com/en-us/iaas/Content/API/SDKDocs/clitoken.htm#Running_Scripts_on_a_Computer_without_a_Browser)

```Python
config = oci.config.from_file('~/.oci/config', profile_name="DEFAULT")

def make_security_token_signer(oci_config):
pk = oci.signer.load_private_key_from_file(oci_config.get("key_file"), None)
with open(oci_config.get("security_token_file")) as f:
st_string = f.read()
return oci.auth.signers.SecurityTokenSigner(st_string, pk)

signer = make_security_token_signer(oci_config=config)
# Service endpoint
endpoint = "https://generativeai.aiservice.<Region>.oci.oraclecloud.com"

generative_ai_client = oci.generative_ai.generative_ai_client.GenerativeAiClient(config=config, service_endpoint=endpoint, retry_strategy=oci.retry.NoneRetryStrategy(), signer=signer)
```

### Prerequisites
MISSING

- OCI Account
- OCI Generative AI Service
- Oracle JET/Node

## Notes/Issues
MISSING

Additional Use Cases like summarization and embedding coming soon.

To change output parameters edit server.py

```Python
cohere_generate_text_request.max_tokens = 500 # choose the number of tokens 1-4000
cohere_generate_text_request.temperature = 0.75 # adjust temperature 0-1
cohere_generate_text_request.top_p = 0.7 # adjust top_p 0-1
cohere_generate_text_request.frequency_penalty = 1.0 # adjust frequency_penalty
```

## URLs
* Nothing at this time

- [Oracle AI](https://www.oracle.com/artificial-intelligence/)
- [AI for Developers](https://developer.oracle.com/technologies/ai.html)

## Contributing
This project is open source. Please submit your contributions by forking this repository and submitting a pull request! Oracle appreciates any contributions that are made by the open source community.
This project is open source. Please submit your contributions by forking this repository and submitting a pull request! Oracle appreciates any contributions that are made by the open-source community.

## License
Copyright (c) 2022 Oracle and/or its affiliates.
Copyright (c) 2024 Oracle and/or its affiliates.

Licensed under the Universal Permissive License (UPL), Version 1.0.

See [LICENSE](LICENSE) for more details.

ORACLE AND ITS AFFILIATES DO NOT PROVIDE ANY WARRANTY WHATSOEVER, EXPRESS OR IMPLIED, FOR ANY SOFTWARE, MATERIAL OR CONTENT OF ANY KIND CONTAINED OR PRODUCED WITHIN THIS REPOSITORY, AND IN PARTICULAR SPECIFICALLY DISCLAIM ANY AND ALL IMPLIED WARRANTIES OF TITLE, NON-INFRINGEMENT, MERCHANTABILITY, AND FITNESS FOR A PARTICULAR PURPOSE. FURTHERMORE, ORACLE AND ITS AFFILIATES DO NOT REPRESENT THAT ANY CUSTOMARY SECURITY REVIEW HAS BEEN PERFORMED WITH RESPECT TO ANY SOFTWARE, MATERIAL OR CONTENT CONTAINED OR PRODUCED WITHIN THIS REPOSITORY. IN ADDITION, AND WITHOUT LIMITING THE FOREGOING, THIRD PARTIES MAY HAVE POSTED SOFTWARE, MATERIAL OR CONTENT TO THIS REPOSITORY WITHOUT ANY REVIEW. USE AT YOUR OWN RISK.
ORACLE AND ITS AFFILIATES DO NOT PROVIDE ANY WARRANTY WHATSOEVER, EXPRESS OR IMPLIED, FOR ANY SOFTWARE, MATERIAL OR CONTENT OF ANY KIND CONTAINED OR PRODUCED WITHIN THIS REPOSITORY, AND IN PARTICULAR SPECIFICALLY DISCLAIM ANY AND ALL IMPLIED WARRANTIES OF TITLE, NON-INFRINGEMENT, MERCHANTABILITY, AND FITNESS FOR A PARTICULAR PURPOSE. FURTHERMORE, ORACLE AND ITS AFFILIATES DO NOT REPRESENT THAT ANY CUSTOMARY SECURITY REVIEW HAS BEEN PERFORMED WITH RESPECT TO ANY SOFTWARE, MATERIAL OR CONTENT CONTAINED OR PRODUCED WITHIN THIS REPOSITORY. IN ADDITION, AND WITHOUT LIMITING THE FOREGOING, THIRD PARTIES MAY HAVE POSTED SOFTWARE, MATERIAL OR CONTENT TO THIS REPOSITORY WITHOUT ANY REVIEW. USE AT YOUR OWN RISK.
22 changes: 22 additions & 0 deletions app/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
/jet_components
/exchange_components
/node_modules
/bower_components
/dist
/web
/staged-themes
/themes
/jaftmp@

/hybrid/node_modules
/hybrid/platforms
/hybrid/www/*

!hybrid/plugins
hybrid/plugins/*
!hybrid/plugins/fetch.json

package-lock.json

.DS_Store
Thumbs.db
23 changes: 23 additions & 0 deletions app/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
FROM nginx:1.23-alpine-slim

RUN apk add --update nodejs npm


WORKDIR /usr/share/build

RUN mkdir -p /usr/share/build/src \
&& mkdir -p /usr/share/build/scripts

COPY src/ /usr/share/build/src/

COPY scripts/ /usr/share/build/scripts/

COPY *.json /usr/share/build/

RUN npm install
RUN npm install -g @oracle/ojet-cli
RUN npx ojet build web --release

EXPOSE 80

RUN cp -R /usr/share/build/web/* /usr/share/nginx/html/
41 changes: 41 additions & 0 deletions app/oraclejafconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
{
"title": [
"+---------------------------------------------------------------------+",
"| OJET Application Audit |",
"+---------------------------------------------------------------------+",
"JAF $jafver - Jet $jetver : ($jafdate, $jaftime)\n"
],
"base": "$jafcwd",
"files": [
"./src/**/*.html",
"./src/**/*.js",
"./src/**/*.ts",
"./src/**/component.json",
"./src/styles/**/*.css"
],
"exclude": [
"./src/**/*-min.js",
"./src/**/*-min.css",
"./src/styles/*",
"./**/node_modules/**/*.*"
],
"components": ["./jet_components/**/component.json"],
"builtinJetRules": true,
"jetVer": "15.1",
"ecmaVer": 14,
"format": "prose",
"severity": "all",
"groups": ["all"],
"theme": "Redwood",
"typescript": {
"tsconfig": "."
},
"options": {
"verbose": false,
"color": true
},
"ojet": {
"update": true,
"md5": "157a41b6c41e0ea3a2cf1220cb184de3"
}
}
28 changes: 28 additions & 0 deletions app/oraclejetconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
{
"paths": {
"source": {
"common": "src",
"web": "src-web",
"javascript": ".",
"typescript": ".",
"styles": "styles",
"themes": "themes",
"components": "components",
"exchangeComponents": "exchange_components"
},
"staging": {
"web": "web",
"themes": "staged-themes"
}
},
"defaultBrowser": "chrome",
"sassVer": "8.0.0",
"defaultTheme": "redwood",
"typescriptLibraries": "[email protected] yargs-parser@~13.1.2",
"webpackLibraries": "[email protected] @types/[email protected] webpack-dev-server style-loader css-loader sass-loader sass [email protected] raw-loader noop-loader html-webpack-plugin html-replace-webpack-plugin copy-webpack-plugin @prefresh/webpack @prefresh/babel-plugin webpack-merge compression-webpack-plugin mini-css-extract-plugin clean-webpack-plugin css-fix-url-loader",
"mochaTestingLibraries": "karma mocha sinon chai coverage [email protected] [email protected] [email protected] [email protected] [email protected] [email protected] [email protected] [email protected] [email protected] @types/[email protected] @types/[email protected] @types/[email protected] @types/[email protected]",
"jestTestingLibraries": "[email protected] @testing-library/[email protected] @types/[email protected] [email protected] @oracle/oraclejet-jest-preset@~15.1.0",
"architecture": "vdom",
"watchInterval": 1000,
"exchange-url": "https://exchange.oraclecorp.com/api/0.2.0/"
}
26 changes: 26 additions & 0 deletions app/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
{
"name": "JETGenAI",
"version": "1.0.0",
"description": "An Oracle JavaScript Extension Toolkit(JET) web app",
"dependencies": {
"@oracle/oraclejet": "~15.1.0",
"@oracle/oraclejet-core-pack": "~15.1.0",
"marked": "^4.3.0",
"uuid": "^9.0.1"
},
"devDependencies": {
"@oracle/ojet-cli": "~15.1.0",
"@oracle/oraclejet-audit": "^15.1.3",
"@types/uuid": "^9.0.7",
"extract-zip": "^1.7.0",
"fs-extra": "^8.1.0",
"glob": "7.2.0",
"typescript": "5.0.4",
"underscore": "^1.10.2",
"yargs-parser": "13.1.2"
},
"engines": {
"node": ">=16.0.0"
},
"private": true
}
Loading

0 comments on commit 7cb8bfd

Please sign in to comment.