Skip to content

Commit ae06665

Browse files
author
mike dupont
committed
Kinda working
1 parent 9dc496c commit ae06665

File tree

5 files changed

+114
-84
lines changed

5 files changed

+114
-84
lines changed

doit.sh

+1-2
Original file line numberDiff line numberDiff line change
@@ -13,9 +13,8 @@ popd
1313
pushd scripts/jsdoc-automation
1414
pnpm install --no-frozen-lockfile
1515
pnpm build
16+
popd
1617

1718
pushd node_modules/.pnpm/better-sqlite3@11.8.1/node_modules/better-sqlite3/
1819
pnpm rebuild
19-
20-
popd
2120
popd

packages/core/src/roles.ts

+4
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,10 @@ export async function findWorldForOwner(
7777

7878
// Find world where the user is the owner
7979
for (const world of worlds) {
80+
console.log('world name:', world.name);
81+
console.log('world id:', world.id);
82+
console.log('world agent:', world.agentId);
83+
console.log('world metadata:', world.metadata);
8084
if (world.metadata?.ownership?.ownerId === entityId) {
8185
return world;
8286
}

packages/plugin-groq/src/index.ts

+98-81
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import { createGroq } from '@ai-sdk/groq';
2+
//import Groq from "groq-sdk";
23
import type {
34
ImageDescriptionParams,
45
ModelTypeName,
@@ -234,87 +235,103 @@ export const groqPlugin: Plugin = {
234235
params: TextEmbeddingParams | string | null
235236
): Promise<number[]> => {
236237
// Handle null input (initialization case)
237-
if (params === null) {
238-
logger.debug('Creating test embedding for initialization');
239-
// Return a consistent vector for null input
240-
const testVector = Array(1536).fill(0);
241-
testVector[0] = 0.1; // Make it non-zero
242-
return testVector;
243-
}
244-
245-
// Get the text from whatever format was provided
246-
let text: string;
247-
if (typeof params === 'string') {
248-
text = params; // Direct string input
249-
} else if (typeof params === 'object' && params.text) {
250-
text = params.text; // Object with text property
251-
} else {
252-
logger.warn('Invalid input format for embedding');
253-
// Return a fallback for invalid input
254-
const fallbackVector = Array(1536).fill(0);
255-
fallbackVector[0] = 0.2; // Different value for tracking
256-
return fallbackVector;
257-
}
258-
259-
// Skip API call for empty text
260-
if (!text.trim()) {
261-
logger.warn('Empty text for embedding');
262-
const emptyVector = Array(1536).fill(0);
263-
emptyVector[0] = 0.3; // Different value for tracking
264-
return emptyVector;
265-
}
266-
267-
// truncate
268-
console.log('PROMPT', text);
269-
if (text.length > 8000) {
270-
text = text.substring(0, 8000);
271-
console.log('TRUNCATED PROMPT', text);
272-
}
273-
274-
try {
275-
const baseURL = getCloudflareGatewayBaseURL(runtime, 'groq');
276-
const model = runtime.getSetting('EMBEDDING_GROQ_MODEL') ?? 'text-embedding-3-small';
277-
278-
// Call the OpenAI API
279-
const response = await fetch(`${baseURL}/embeddings`, {
280-
method: 'POST',
281-
headers: {
282-
Authorization: `Bearer ${process.env.GROQ_API_KEY}`,
283-
'Content-Type': 'application/json',
284-
},
285-
body: JSON.stringify({
286-
model: model,
287-
input: text,
288-
}),
289-
});
290-
291-
if (!response.ok) {
292-
logger.error(`OpenAI API error: ${response.status} - ${response.statusText}`);
293-
const errorVector = Array(1536).fill(0);
294-
errorVector[0] = 0.4; // Different value for tracking
295-
return errorVector;
296-
}
297-
298-
const data = (await response.json()) as {
299-
data: [{ embedding: number[] }];
300-
};
301-
302-
if (!data?.data?.[0]?.embedding) {
303-
logger.error('API returned invalid structure');
304-
const errorVector = Array(1536).fill(0);
305-
errorVector[0] = 0.5; // Different value for tracking
306-
return errorVector;
307-
}
308-
309-
const embedding = data.data[0].embedding;
310-
logger.log(`Got valid embedding with length ${embedding.length}`);
311-
return embedding;
312-
} catch (error) {
313-
logger.error('Error generating embedding:', error);
314-
const errorVector = Array(1536).fill(0);
315-
errorVector[0] = 0.6; // Different value for tracking
316-
return errorVector;
317-
}
238+
//if (params === null) {
239+
//logger.debug('Creating test embedding for initialization');
240+
// Return a consistent vector for null input
241+
const testVector = Array(1536).fill(0);
242+
testVector[0] = 0.1; // Make it non-zero
243+
return testVector;
244+
//}
245+
246+
// // Get the text from whatever format was provided
247+
// let text: string;
248+
// if (typeof params === 'string') {
249+
// text = params; // Direct string input
250+
// } else if (typeof params === 'object' && params.text) {
251+
// text = params.text; // Object with text property
252+
// } else {
253+
// logger.warn('Invalid input format for embedding');
254+
// // Return a fallback for invalid input
255+
// const fallbackVector = Array(1536).fill(0);
256+
// fallbackVector[0] = 0.2; // Different value for tracking
257+
// return fallbackVector;
258+
// }
259+
260+
// // Skip API call for empty text
261+
// if (!text.trim()) {
262+
// logger.warn('Empty text for embedding');
263+
// const emptyVector = Array(1536).fill(0);
264+
// emptyVector[0] = 0.3; // Different value for tracking
265+
// return emptyVector;
266+
// }
267+
268+
// // truncate
269+
// console.log('INPUT PROMPT:', text);
270+
// if (text.length > 8000) {
271+
// text = text.substring(0, 8000);
272+
// console.log('TRUNCATED PROMPT', text);
273+
// }
274+
275+
// const baseURL = getCloudflareGatewayBaseURL(runtime, 'groq');
276+
// const data4 = {
277+
// method: 'GET',
278+
// headers: {
279+
// Authorization: `Bearer ${process.env.GROQ_API_KEY}`,
280+
// 'Content-Type': 'application/json',
281+
// }
282+
// };
283+
// const response2 = await fetch(`${baseURL}/models`, data4);
284+
// if (!response2.ok) {
285+
// logger.error(`GROQ error: ${response2.status} - ${response2.statusText}`);
286+
// const errorVector = Array(1536).fill(0);
287+
// errorVector[0] = 0.4; // Different value for tracking
288+
// return errorVector;
289+
// }
290+
// const models = (await response2.json()) as { data: { id: string }[] }
291+
// console.log(models);
292+
// console.log('MODELS:', models);
293+
// //getModels().then((models) =>
294+
295+
// //console.log(models);
296+
// models.data.forEach(async (model) => {
297+
// console.log("MODEL", model);
298+
// console.log(model.id)
299+
// const data1 = {
300+
// method: 'POST',
301+
// headers: {
302+
// Authorization: `Bearer ${process.env.GROQ_API_KEY}`,
303+
// 'Content-Type': 'application/json',
304+
// },
305+
// body: JSON.stringify({
306+
// model: model.id,
307+
// input: text,
308+
// }),
309+
// };
310+
// console.log('DATA', data1);
311+
// const response = await fetch(`${baseURL}/embeddings`, data1);
312+
// if (!response.ok) {
313+
// console.log("response", response)
314+
// logger.error(`GROQ error: ${response.status} - ${response.statusText}`);
315+
// const errorVector = Array(1536).fill(0);
316+
// errorVector[0] = 0.4; // Different value for tracking
317+
// return errorVector;
318+
// }
319+
// const data = (await response.json()) as {
320+
// data: [{ embedding: number[] }];
321+
// };
322+
// if (!data?.data?.[0]?.embedding) {
323+
// logger.error('API returned invalid structure');
324+
// const errorVector = Array(1536).fill(0);
325+
// errorVector[0] = 0.5; // Different value for tracking
326+
// return errorVector;
327+
// }
328+
// const embedding = data.data[0].embedding;
329+
// logger.log(`Got valid embedding with length ${embedding.length}`);
330+
// return embedding;
331+
// })
332+
//const errorVector = Array(1536).fill(0);
333+
//errorVector[0] = 0.6; // Different value for tracking
334+
//return errorVector;
318335
},
319336
[ModelType.TEXT_TOKENIZER_ENCODE]: async (
320337
_runtime,

packages/plugin-telegram/src/messageManager.ts

+8-1
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,9 @@ export class MessageManager {
7575
try {
7676
let imageUrl: string | null = null;
7777

78-
logger.info(`Telegram Message: ${message}`);
78+
logger.info(`Telegram Message id: ${message.message_id}`);
79+
logger.info(`Telegram Message chat: ${message.chat}`);
80+
logger.info(`Telegram Message from : ${message.from}`);
7981

8082
if ('photo' in message && message.photo?.length > 0) {
8183
const photo = message.photo[message.photo.length - 1];
@@ -360,6 +362,11 @@ export class MessageManager {
360362

361363
// Create callback for handling responses
362364
const callback: HandlerCallback = async (content: Content, _files?: string[]) => {
365+
console.log('Telegram callback 1', content.url);
366+
console.log('Telegram callback 2', content.text);
367+
console.log('Telegram callback 3', content.providers);
368+
console.log('Telegram callback 4', content.thought);
369+
console.log('Telegram callback 5', message);
363370
try {
364371
const sentMessages = await this.sendMessageInChunks(ctx, content, message.message_id);
365372

packages/plugin-telegram/src/utils.ts

+3
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,9 @@ export function escapeMarkdown(text: string): string {
4141
* @returns {string[]} An array containing the text message split into chunks.
4242
*/
4343
export function splitMessage(text: string, maxLength = 4096): string[] {
44+
if (text == undefined) {
45+
return [];
46+
}
4447
const chunks: string[] = [];
4548
let currentChunk = '';
4649

0 commit comments

Comments
 (0)