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
|
||||
*/
|
||||
const DEFAULT_HEAR_POLL_INTERVAL = 500;
|
||||
const API_RETRIES = 120;
|
||||
const POOLING_COUNT = 120;
|
||||
|
||||
/**
|
||||
* Base services of conversation to be called by BASIC.
|
||||
|
@ -1314,11 +1314,9 @@ export class DialogKeywords {
|
|||
GBLogEx.info(min, `MESSAGE BOT: ${text}.`);
|
||||
|
||||
const { conversation, client } = min['apiConversations'][pid];
|
||||
|
||||
await client.apis.Conversations.Conversations_PostActivity({
|
||||
conversationId: conversation.conversationId,
|
||||
activity: {
|
||||
pid: pid,
|
||||
textFormat: 'plain',
|
||||
text: text,
|
||||
type: 'message',
|
||||
|
@ -1332,7 +1330,7 @@ export class DialogKeywords {
|
|||
let messages = [];
|
||||
GBLogEx.info(min, `MessageBot: Starting message polling ${conversation.conversationId}).`);
|
||||
|
||||
let count = API_RETRIES;
|
||||
let count = POOLING_COUNT;
|
||||
while (count--) {
|
||||
await GBUtil.sleep(DEFAULT_HEAR_POLL_INTERVAL);
|
||||
|
||||
|
@ -1345,28 +1343,23 @@ export class DialogKeywords {
|
|||
let activities = response.obj.activities;
|
||||
|
||||
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) {
|
||||
activities.forEach(activity => {
|
||||
messages.push(activity.text);
|
||||
GBLogEx.info(min, `MESSAGE BOT answer from bot: ${activity.text}`);
|
||||
});
|
||||
}
|
||||
return messages.join('\n');
|
||||
}
|
||||
}
|
||||
} catch (err) {
|
||||
GBLog.error(
|
||||
`Error calling printMessages in messageBot API ${err.data === undefined ? err : err.data} ${
|
||||
err.errObj ? err.errObj.message : ''
|
||||
}`
|
||||
);
|
||||
return err;
|
||||
GBLog.error(`API Message Pooling error: ${GBUtil.toYAML(err)}`);
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public async start({ botId, botApiKey, userSystemId, text }) {
|
||||
|
||||
let min: GBMinInstance = GBServer.globals.minInstances.filter(p => p.instance.botId === botId)[0];
|
||||
let sec = new SecService();
|
||||
let user = await sec.getUserFromSystemId(userSystemId);
|
||||
|
@ -1546,7 +1539,7 @@ export class DialogKeywords {
|
|||
|
||||
const gbaiName = GBUtil.getGBAIPath(min.botId);
|
||||
const localName = path.join('work', gbaiName, 'cache', `qr${GBAdminService.getRndReadableIdentifier()}.png`);
|
||||
await fs.writeFile(localName, buf, { encoding: null });
|
||||
await fs.writeFile(localName, buf, { encoding: null });
|
||||
const url = urlJoin(GBServer.globals.publicAddress, min.botId, 'cache', path.basename(localName));
|
||||
|
||||
return { data: data, localName: localName, url: url };
|
||||
|
|
|
@ -84,7 +84,7 @@ export const getRouter = (
|
|||
});
|
||||
|
||||
// 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 conversation = getConversation(req.params.conversationId, conversationInitRequired);
|
||||
|
@ -147,12 +147,10 @@ export const getRouter = (
|
|||
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;
|
||||
|
||||
activity = req.body;
|
||||
activity.id = uuidv4.v4();
|
||||
activity.from = { id: 'id', name: 'Bot' };
|
||||
|
||||
const conversation = getConversation(req.params.conversationId, conversationInitRequired);
|
||||
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;
|
||||
|
||||
activity = req.body;
|
||||
|
|
36
src/util.ts
36
src/util.ts
|
@ -75,22 +75,26 @@ export class GBUtil {
|
|||
}
|
||||
|
||||
public static async getDirectLineClient(min) {
|
||||
let config = {
|
||||
spec: JSON.parse(await fs.readFile('directline-3.0.json', 'utf8')),
|
||||
let config;
|
||||
if (!GBConfigService.get('STORAGE_NAME')) {
|
||||
config = {
|
||||
spec: JSON.parse(await fs.readFile('directline-v2.json', 'utf8')),
|
||||
requestInterceptor: req => {
|
||||
req.headers['Authorization'] = `Bearer ${min.instance.webchatKey}`;
|
||||
}
|
||||
};
|
||||
if (!GBConfigService.get('STORAGE_NAME')) {
|
||||
(config['spec'].url = `http://127.0.0.1:${GBConfigService.getServerPort()}/api/messages/${min.botId}`),
|
||||
(config['spec'].servers = [
|
||||
{ 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;
|
||||
}
|
||||
config.spec['host'] = `127.0.0.1:${GBConfigService.getServerPort()}`;
|
||||
config.spec['basePath'] = `/api/messages/${min.botId}`;
|
||||
config.spec['schemes'] = ["http"];
|
||||
|
||||
} 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);
|
||||
}
|
||||
|
||||
|
@ -126,13 +130,11 @@ export class GBUtil {
|
|||
}
|
||||
|
||||
// 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
|
||||
const createCaseInsensitiveProxy = obj => {
|
||||
const propertiesMap = new Map(
|
||||
Object.keys(obj).map(propKey => [lowercase(propKey), obj[propKey]])
|
||||
);
|
||||
const propertiesMap = new Map(Object.keys(obj).map(propKey => [lowercase(propKey), obj[propKey]]));
|
||||
|
||||
const caseInsensitiveGetHandler = {
|
||||
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
|
||||
if (Array.isArray(listOrRow)) {
|
||||
return listOrRow.map(row =>
|
||||
typeof row === 'object' && row !== null ? createCaseInsensitiveProxy(row) : row
|
||||
);
|
||||
return listOrRow.map(row => (typeof row === 'object' && row !== null ? createCaseInsensitiveProxy(row) : row));
|
||||
} else {
|
||||
return createCaseInsensitiveProxy(listOrRow);
|
||||
}
|
||||
|
|
Loading…
Add table
Reference in a new issue