Skip to content

Commit 9e8fbae

Browse files
authored
Merge pull request #79 from nemozak1/develop
Add instructions for Opey JWT setup
2 parents c5552c4 + c802460 commit 9e8fbae

File tree

7 files changed

+4938
-5305
lines changed

7 files changed

+4938
-5305
lines changed

README.md

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -142,6 +142,24 @@ proxy_set_header X-Forwarded-Proto $scheme;
142142

143143
so that Node knows that the cookies have been sent securely over https.
144144

145+
# Running Opey
146+
If you want to run Opey locally you'll need to have a local instance running. The repo can be found [here](https://github.com/OpenBankProject/OBP-Opey).
147+
148+
You will need to create a public-private key pair using open ssl (minimum 2048 bits).
149+
1. create the directory ./server/cert
150+
```
151+
mkdir ./server/cert
152+
cd ./server/cert
153+
```
154+
2. Generate the public private key pair inside the ./server/cert directory
155+
```
156+
openssl genrsa -out private_key.pem 2048
157+
openssl rsa -in private_key.pem -pubout -out public_key.pem
158+
```
159+
3. Copy the public key to Opey top level directory
160+
```
161+
cp public_key.pem {path-to-your-opey-install}/
162+
```
145163

146164
# LICENSE
147165

components.d.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,4 +44,7 @@ declare module 'vue' {
4444
RouterView: typeof import('vue-router')['RouterView']
4545
SearchNav: typeof import('./src/components/SearchNav.vue')['default']
4646
}
47+
export interface ComponentCustomProperties {
48+
vLoading: typeof import('element-plus/es')['ElLoadingDirective']
49+
}
4750
}

server/controllers/OpeyController.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -114,7 +114,8 @@ export class OpeyController {
114114
username: obpUsername,
115115
exp: Math.floor(Date.now() / 1000) + (60 * 60),
116116
};
117-
117+
118+
console.log("Generating new token for Opey");
118119
const token = jwt.sign(payload, privateKey, { algorithm: 'RS256' });
119120
session['opeyToken'] = token;
120121

src/components/ChatWidget.vue

Lines changed: 22 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -70,13 +70,16 @@
7070
7171
const { isStreaming, chatMessages, currentMessageSnapshot, lastError } = storeToRefs(chatStore);
7272
73-
return {isStreaming, chatMessages, lastError, currentMessageSnapshot, chatStore, connectionStore}
73+
const { isConnected } = storeToRefs(connectionStore);
74+
75+
return {isStreaming, chatMessages, lastError, currentMessageSnapshot, chatStore, connectionStore, isConnected}
7476
},
7577
data() {
7678
return {
7779
isOpen: false,
7880
userInput: '',
7981
sessionId: uuidv4(),
82+
awaitingConnection: !this.isConnected,
8083
isLoading: false,
8184
obpApiHost: null,
8285
isLoggedIn: null,
@@ -117,18 +120,27 @@
117120
try {
118121
token = await getOpeyJWT()
119122
} catch (error) {
123+
console.log('Error creating JWT for opey: ', error)
120124
this.errorState = true
121125
ElMessage({
122126
message: 'Error getting Opey JWT token',
123127
type: 'error'
124128
});
125-
console.log(error)
126-
token = ''
129+
127130
}
128131
129132
// Establish the WebSocket connection
130133
console.log('Establishing WebSocket connection');
131-
this.connectionStore.connect(token)
134+
try{
135+
this.connectionStore.connect(token)
136+
} catch (error) {
137+
console.log('Error establishing WebSocket connection: ', error)
138+
this.errorState = true
139+
ElMessage({
140+
message: 'Error establishing WebSocket connection',
141+
type: 'error'
142+
});
143+
}
132144
133145
},
134146
async sendMessage() {
@@ -257,7 +269,7 @@
257269
<span>Chat with Opey</span>
258270
<img alt="Powered by OpenAI" src="@/assets/powered-by-openai-badge-outlined-on-dark.svg" height="32">
259271
</div>
260-
<div v-if="this.isLoggedIn" class="chat-messages" ref="messages">
272+
<div v-if="this.isLoggedIn" v-loading="this.awaitingConnection" element-loading-text="Awaiting Connection..." class="chat-messages" ref="messages">
261273
<div v-for="(message, index) in chatMessages" :key="index" :class="['chat-message', message.role]">
262274
<div v-if="(this.isStreaming)&&(index === this.chatMessages.length -1)">
263275
<div v-html="renderMarkdown(this.currentMessageSnapshot)"></div>
@@ -300,6 +312,8 @@
300312
<div class="dot"></div>
301313
<div class="dot"></div>
302314
</div>
315+
316+
303317
</div>
304318
<div v-else class="chat-messages">
305319
<p>Opey is only availabled when logged in. <a v-bind:href="'/api/connect'">Log In</a> </p>
@@ -317,14 +331,14 @@
317331
placeholder="Type your message..."
318332
@keypress="submitEnter"
319333
type="textarea"
320-
:disabled="!isLoggedIn ? '' : disabled"
334+
:disabled="!isLoggedIn || this.awaitingConnection ? '' : disabled"
321335
>
322336
</el-input>
323337
<!--<textarea v-model="userInput" placeholder="Type your message..." @keypress="submitEnter"></textarea>-->
324338
<button
325339
@click="sendMessage"
326-
:disabled="!isLoggedIn ? '' : disabled"
327-
:style="!isLoggedIn ? 'background-color:#929292; cursor:not-allowed' : ''"
340+
:disabled="!isLoggedIn || this.awaitingConnection ? '' : disabled"
341+
:style="!isLoggedIn || this.awaitingConnection ? 'background-color:#929292; cursor:not-allowed' : ''"
328342
>
329343
Send
330344
</button>

src/obp/common-functions.ts

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -74,8 +74,13 @@ export async function getCacheStorageInfo() {
7474

7575
export async function getOpeyJWT() {
7676
const response = await axios.post('/api/opey/token').catch((error) => {
77-
console.log(error)
78-
})
77+
if (error.response) {
78+
throw new Error(`getOpeyJWT returned an error: ${error.toJSON()}`);
79+
80+
} else {
81+
throw new Error(`getOpeyJWT returned an error: ${error.message}`);
82+
}
83+
});
7984
const token = String(response?.data?.token)
8085
return token
8186
}

src/stores/connection.ts

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,13 @@ export const useConnectionStore = defineStore("connection", {
6060
*/
6161
connect(token: string) {
6262
socket.auth = { token };
63-
socket.connect();
63+
console.log("connectionStore says: connecting to websocket")
64+
try {
65+
socket.connect();
66+
} catch (error) {
67+
console.error("connectionStore says: error connecting to websocket", error)
68+
}
69+
6470
}
6571
},
6672
});

0 commit comments

Comments
 (0)