fix (templates): llm-server almost OK.
This commit is contained in:
parent
22141095f0
commit
bf9886e763
4 changed files with 74 additions and 83 deletions
|
@ -66,7 +66,7 @@ import puppeteer from 'puppeteer';
|
||||||
* Default check interval for user replay
|
* Default check interval for user replay
|
||||||
*/
|
*/
|
||||||
const DEFAULT_HEAR_POLL_INTERVAL = 500;
|
const DEFAULT_HEAR_POLL_INTERVAL = 500;
|
||||||
const API_RETRIES = 120;
|
const POOLING_COUNT = 120;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Base services of conversation to be called by BASIC.
|
* Base services of conversation to be called by BASIC.
|
||||||
|
@ -1314,11 +1314,9 @@ export class DialogKeywords {
|
||||||
GBLogEx.info(min, `MESSAGE BOT: ${text}.`);
|
GBLogEx.info(min, `MESSAGE BOT: ${text}.`);
|
||||||
|
|
||||||
const { conversation, client } = min['apiConversations'][pid];
|
const { conversation, client } = min['apiConversations'][pid];
|
||||||
|
|
||||||
await client.apis.Conversations.Conversations_PostActivity({
|
await client.apis.Conversations.Conversations_PostActivity({
|
||||||
conversationId: conversation.conversationId,
|
conversationId: conversation.conversationId,
|
||||||
activity: {
|
activity: {
|
||||||
pid: pid,
|
|
||||||
textFormat: 'plain',
|
textFormat: 'plain',
|
||||||
text: text,
|
text: text,
|
||||||
type: 'message',
|
type: 'message',
|
||||||
|
@ -1332,7 +1330,7 @@ export class DialogKeywords {
|
||||||
let messages = [];
|
let messages = [];
|
||||||
GBLogEx.info(min, `MessageBot: Starting message polling ${conversation.conversationId}).`);
|
GBLogEx.info(min, `MessageBot: Starting message polling ${conversation.conversationId}).`);
|
||||||
|
|
||||||
let count = API_RETRIES;
|
let count = POOLING_COUNT;
|
||||||
while (count--) {
|
while (count--) {
|
||||||
await GBUtil.sleep(DEFAULT_HEAR_POLL_INTERVAL);
|
await GBUtil.sleep(DEFAULT_HEAR_POLL_INTERVAL);
|
||||||
|
|
||||||
|
@ -1345,28 +1343,23 @@ export class DialogKeywords {
|
||||||
let activities = response.obj.activities;
|
let activities = response.obj.activities;
|
||||||
|
|
||||||
if (activities && activities.length) {
|
if (activities && activities.length) {
|
||||||
activities = activities.filter(m => m.from.id === min.botId && m.type === 'message');
|
activities = activities.filter(m => m.from.id !== user.userSystemId && m.type === 'message');
|
||||||
if (activities.length) {
|
if (activities.length) {
|
||||||
activities.forEach(activity => {
|
activities.forEach(activity => {
|
||||||
messages.push(activity.text);
|
messages.push(activity.text);
|
||||||
GBLogEx.info(min, `MESSAGE BOT answer from bot: ${activity.text}`);
|
GBLogEx.info(min, `MESSAGE BOT answer from bot: ${activity.text}`);
|
||||||
});
|
});
|
||||||
}
|
|
||||||
return messages.join('\n');
|
return messages.join('\n');
|
||||||
}
|
}
|
||||||
|
}
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
GBLog.error(
|
GBLog.error(`API Message Pooling error: ${GBUtil.toYAML(err)}`);
|
||||||
`Error calling printMessages in messageBot API ${err.data === undefined ? err : err.data} ${
|
|
||||||
err.errObj ? err.errObj.message : ''
|
|
||||||
}`
|
|
||||||
);
|
|
||||||
return err;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
public async start({ botId, botApiKey, userSystemId, text }) {
|
public async start({ botId, botApiKey, userSystemId, text }) {
|
||||||
|
|
||||||
let min: GBMinInstance = GBServer.globals.minInstances.filter(p => p.instance.botId === botId)[0];
|
let min: GBMinInstance = GBServer.globals.minInstances.filter(p => p.instance.botId === botId)[0];
|
||||||
let sec = new SecService();
|
let sec = new SecService();
|
||||||
let user = await sec.getUserFromSystemId(userSystemId);
|
let user = await sec.getUserFromSystemId(userSystemId);
|
||||||
|
|
|
@ -84,7 +84,7 @@ export const getRouter = (
|
||||||
});
|
});
|
||||||
|
|
||||||
// Gets activities from store (local history array for now)
|
// Gets activities from store (local history array for now)
|
||||||
router.get(`/directline/${botId}/conversations/:conversationId/activities`, (req, res) => {
|
router.get(`/api/messages/${botId}/v3/directline/conversations/:conversationId/activities`, (req, res) => {
|
||||||
const watermark = req.query.watermark && req.query.watermark !== 'null' ? Number(req.query.watermark) : 0;
|
const watermark = req.query.watermark && req.query.watermark !== 'null' ? Number(req.query.watermark) : 0;
|
||||||
|
|
||||||
const conversation = getConversation(req.params.conversationId, conversationInitRequired);
|
const conversation = getConversation(req.params.conversationId, conversationInitRequired);
|
||||||
|
@ -147,12 +147,10 @@ export const getRouter = (
|
||||||
console.warn('/v3/conversations not implemented');
|
console.warn('/v3/conversations not implemented');
|
||||||
});
|
});
|
||||||
|
|
||||||
router.post('/v3/conversations/:conversationId/activities', (req, res) => {
|
router.post(`/api/messages/${botId}/v3/directline/conversations/:conversationId/activities`, (req, res) => {
|
||||||
let activity: IActivity;
|
let activity: IActivity;
|
||||||
|
|
||||||
activity = req.body;
|
activity = req.body;
|
||||||
activity.id = uuidv4.v4();
|
|
||||||
activity.from = { id: 'id', name: 'Bot' };
|
|
||||||
|
|
||||||
const conversation = getConversation(req.params.conversationId, conversationInitRequired);
|
const conversation = getConversation(req.params.conversationId, conversationInitRequired);
|
||||||
if (conversation) {
|
if (conversation) {
|
||||||
|
@ -164,7 +162,7 @@ export const getRouter = (
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
router.post('/v3/conversations/:conversationId/activities/:activityId', (req, res) => {
|
router.post(`/api/messages/${botId}/v3/conversations/:conversationId/activities/:activityId`, (req, res) => {
|
||||||
let activity: IActivity;
|
let activity: IActivity;
|
||||||
|
|
||||||
activity = req.body;
|
activity = req.body;
|
||||||
|
|
36
src/util.ts
36
src/util.ts
|
@ -75,22 +75,26 @@ export class GBUtil {
|
||||||
}
|
}
|
||||||
|
|
||||||
public static async getDirectLineClient(min) {
|
public static async getDirectLineClient(min) {
|
||||||
let config = {
|
let config;
|
||||||
spec: JSON.parse(await fs.readFile('directline-3.0.json', 'utf8')),
|
if (!GBConfigService.get('STORAGE_NAME')) {
|
||||||
|
config = {
|
||||||
|
spec: JSON.parse(await fs.readFile('directline-v2.json', 'utf8')),
|
||||||
requestInterceptor: req => {
|
requestInterceptor: req => {
|
||||||
req.headers['Authorization'] = `Bearer ${min.instance.webchatKey}`;
|
req.headers['Authorization'] = `Bearer ${min.instance.webchatKey}`;
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
if (!GBConfigService.get('STORAGE_NAME')) {
|
config.spec['host'] = `127.0.0.1:${GBConfigService.getServerPort()}`;
|
||||||
(config['spec'].url = `http://127.0.0.1:${GBConfigService.getServerPort()}/api/messages/${min.botId}`),
|
config.spec['basePath'] = `/api/messages/${min.botId}`;
|
||||||
(config['spec'].servers = [
|
config.spec['schemes'] = ["http"];
|
||||||
{ url: `http://127.0.0.1:${GBConfigService.getServerPort()}/api/messages/${min.botId}` }
|
|
||||||
]);
|
|
||||||
config['spec'].openapi = '3.0.0';
|
|
||||||
delete config['spec'].host;
|
|
||||||
delete config['spec'].swagger;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
} else {
|
||||||
|
config = {
|
||||||
|
spec: JSON.parse(await fs.readFile('directline-v2.json', 'utf8')),
|
||||||
|
requestInterceptor: req => {
|
||||||
|
req.headers['Authorization'] = `Bearer ${min.instance.webchatKey}`;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
}
|
||||||
return await new SwaggerClient(config);
|
return await new SwaggerClient(config);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -126,13 +130,11 @@ export class GBUtil {
|
||||||
}
|
}
|
||||||
|
|
||||||
// Helper function to convert property names to lowercase
|
// Helper function to convert property names to lowercase
|
||||||
const lowercase = key => typeof key === 'string' ? key.toLowerCase() : key;
|
const lowercase = key => (typeof key === 'string' ? key.toLowerCase() : key);
|
||||||
|
|
||||||
// Create a proxy that maps property accesses to lowercase property names
|
// Create a proxy that maps property accesses to lowercase property names
|
||||||
const createCaseInsensitiveProxy = obj => {
|
const createCaseInsensitiveProxy = obj => {
|
||||||
const propertiesMap = new Map(
|
const propertiesMap = new Map(Object.keys(obj).map(propKey => [lowercase(propKey), obj[propKey]]));
|
||||||
Object.keys(obj).map(propKey => [lowercase(propKey), obj[propKey]])
|
|
||||||
);
|
|
||||||
|
|
||||||
const caseInsensitiveGetHandler = {
|
const caseInsensitiveGetHandler = {
|
||||||
get: (target, property) => propertiesMap.get(lowercase(property))
|
get: (target, property) => propertiesMap.get(lowercase(property))
|
||||||
|
@ -143,9 +145,7 @@ export class GBUtil {
|
||||||
|
|
||||||
// Handle arrays by mapping each element to a case-insensitive proxy
|
// Handle arrays by mapping each element to a case-insensitive proxy
|
||||||
if (Array.isArray(listOrRow)) {
|
if (Array.isArray(listOrRow)) {
|
||||||
return listOrRow.map(row =>
|
return listOrRow.map(row => (typeof row === 'object' && row !== null ? createCaseInsensitiveProxy(row) : row));
|
||||||
typeof row === 'object' && row !== null ? createCaseInsensitiveProxy(row) : row
|
|
||||||
);
|
|
||||||
} else {
|
} else {
|
||||||
return createCaseInsensitiveProxy(listOrRow);
|
return createCaseInsensitiveProxy(listOrRow);
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Reference in a new issue