Skip to content

Commit 83a3b66

Browse files
author
Herve Tribouilloy
committed
Added new workflow to deploy node backend + fixes to ensure the Attribute data are filtering systems attributes to node service
1 parent 26ad1bd commit 83a3b66

6 files changed

Lines changed: 43 additions & 109 deletions

File tree

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
name: Deploy OpenAI Backend
2+
3+
on:
4+
push:
5+
tags:
6+
- "intent-discovery*"
7+
workflow_dispatch:
8+
9+
jobs:
10+
deploy:
11+
runs-on: ubuntu-latest
12+
13+
steps:
14+
- name: Checkout repository
15+
uses: actions/checkout@v4
16+
17+
- name: Deploy backend via rsync
18+
uses: burnett01/rsync-deployments@7.0
19+
with:
20+
switches: -avzr --delete
21+
path: node-backend/
22+
remote_path: /var/www/openai-express/
23+
remote_host: ${{ secrets.SERVER_HOST }}
24+
remote_user: ${{ secrets.SERVER_USER }}
25+
remote_key: ${{ secrets.SERVER_SSH_KEY }}
26+
27+
- name: Install backend dependencies
28+
run: |
29+
ssh -o StrictHostKeyChecking=no \
30+
${{ secrets.SERVER_USER }}@${{ secrets.SERVER_HOST }} \
31+
"cd /var/www/openai-express && npm install --omit=dev"
32+
33+
- name: Restart backend
34+
run: |
35+
ssh -o StrictHostKeyChecking=no \
36+
${{ secrets.SERVER_USER }}@${{ secrets.SERVER_HOST }} \
37+
"pm2 restart openai-express || pm2 start /var/www/openai-express/ecosystem.config.js"

vite_project/package-lock.json

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

vite_project/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"name": "widget-intent-discovery",
33
"private": true,
4-
"version": "0.4.0",
4+
"version": "0.4.2",
55
"type": "module",
66
"scripts": {
77
"dev": "vite",

vite_project/src/components/IntentDiscovery/IntentMessage.tsx

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ type Props = {
1212
intent: IntentControllerState,
1313
attributeLayerData: MagentoProducts
1414
};
15-
export const IntentMessage = ({intent, attributeLayerData}: Props) => {
15+
export const IntentMessage = ({intent, attributeLayerData, config}: Props) => {
1616
const { intentState, setIntentText, setPreference, intentApiClient } = useSystemState()
1717
const optionLabelMap = useOptionLabelMap(attributeLayerData?.aggregations);
1818

@@ -24,7 +24,8 @@ export const IntentMessage = ({intent, attributeLayerData}: Props) => {
2424
intentState,
2525
attributeLayerData?.aggregations,
2626
intent.text,
27-
optionLabelMap
27+
optionLabelMap,
28+
config
2829
)
2930

3031
const json = await intentApiClient.interpret(payload)

vite_project/src/hooks/domain/useEvaluateMessageIntent.tsx

Lines changed: 0 additions & 25 deletions
This file was deleted.
Lines changed: 0 additions & 79 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,3 @@
1-
import {useCallback, useEffect, useState} from "react";
2-
import {activity} from "../../activity";
3-
import {useSystemState} from "../../state/System/useSystemState.ts";
4-
import type {MagentoAggregation} from "./useProductAttributeLayer.tsx";
5-
import {buildAiInterpretationPayload} from "../../lib/ai-recommendations.ts";
6-
import {useOptionLabelMap} from "../domain/useOptionLabelMap.ts";
7-
import type {IntentControllerState} from "../../domain/intent.types.ts";
8-
import type {IntentDiscoveryDataConfig} from "../../domain/intent-discovery.types.ts";
9-
101
export type AiInterpretationRequest = {
112
intent: {
123
text: string
@@ -25,74 +16,4 @@ export type AiInterpretationRequest = {
2516

2617
export type AiInterpretationResponse = {
2718
filters: Record<string, string>
28-
}
29-
30-
export function useAiInterpreter(
31-
attributeData: MagentoAggregation[],
32-
intent: IntentControllerState,
33-
config: IntentDiscoveryDataConfig
34-
) {
35-
36-
const { intentState, setIntentText, setPreference, intentApiClient } = useSystemState()
37-
38-
const [data, setData] = useState<AiInterpretationResponse | null>(null)
39-
const [loading, setLoading] = useState(false)
40-
const [error, setError] = useState<Error | null>(null)
41-
const optionLabelMap = useOptionLabelMap(attributeData);
42-
43-
const load = useCallback(async () => {
44-
if (intentState.status === 'idle' || loading) return
45-
46-
setLoading(true)
47-
setError(null)
48-
49-
try {
50-
const payload = buildAiInterpretationPayload(
51-
intentState,
52-
attributeData,
53-
intent.text,
54-
optionLabelMap,
55-
config
56-
)
57-
58-
const json = await intentApiClient.interpret(payload)
59-
//const json = await intentApiClient.dummy(payload)
60-
61-
activity('ai-interpretation', 'AI interpretation API ran', json)
62-
63-
setData(json)
64-
65-
if (json?.filters) {
66-
setIntentText(intent.text)
67-
68-
for (const [attribute, value] of Object.entries(json?.filters)) {
69-
setPreference(attribute, value)
70-
}
71-
}
72-
73-
} catch (err: unknown) {
74-
75-
activity('ai-interpretation', 'AI Interpretation Error', {
76-
error: (err as Error).message
77-
}, 'error')
78-
79-
setError(err instanceof Error ? err : new Error("Unknown error"))
80-
81-
} finally {
82-
setLoading(false)
83-
}
84-
85-
}, [intent.text, attributeData, optionLabelMap, intentState.status])
86-
87-
useEffect(() => {
88-
activity('ai-interpretation', 'Triggering interpretation')
89-
load()
90-
}, [load])
91-
92-
return {
93-
data,
94-
loading,
95-
error,
96-
refetch: load,
97-
}
9819
}

0 commit comments

Comments
 (0)