Skip to content

Commit aabae04

Browse files
committed
chore: error logs
1 parent a01e4d6 commit aabae04

2 files changed

Lines changed: 94 additions & 19 deletions

File tree

platforms/dreamsync-api/src/services/MatchingService.ts

Lines changed: 73 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -121,7 +121,7 @@ Use the exact groupId from the table above in the format: "JOIN_EXISTING_GROUP:<
121121
}
122122

123123
return `
124-
You are an AI matching assistant. Analyze ALL the wishlists below and find meaningful connections between users.
124+
You are an AI matching assistant. Your task is to find meaningful connections between users based on their wishlists.
125125
126126
The wishlists are provided as delimiter-separated rows (delimiter: "${delimiter}").
127127
Columns: userId${delimiter}userEname${delimiter}userName${delimiter}wants${delimiter}offers
@@ -134,7 +134,13 @@ ${wishlistRows}
134134
Use ONLY the rows above (not full prose) to infer matches.
135135
Return userIds EXACTLY as provided in the table (no new IDs, no missing IDs).${existingGroupsText}
136136
137-
TASK: Find ALL meaningful matches between these users based on their wishlists.
137+
CRITICAL INSTRUCTIONS:
138+
- You MUST analyze the wishlists above and find matches
139+
- Look for complementary needs: when User A wants something that User B offers, or vice versa
140+
- Look for shared interests: when multiple users want or offer similar things
141+
- Look for skill exchanges: when one can teach what another wants to learn
142+
- You should actively search for connections - do NOT return an empty array unless there are truly ZERO possible connections
143+
- All wishlists provided have valid content - analyze them thoroughly
138144
139145
IMPORTANT RULES:
140146
1. Only suggest matches with confidence > 0.85
@@ -146,8 +152,6 @@ IMPORTANT RULES:
146152
- PRIVATE: Personal services (tutoring, coaching, 1-on-1 lessons, personal projects)
147153
- GROUP: Group activities (sports teams, clubs, workshops, group projects, tournaments)
148154
149-
NOTE: All wishlists provided have been pre-filtered to ensure they contain valid summary data. You should analyze all provided wishlists and find meaningful matches between them. Only return an empty array [] if you genuinely cannot find any meaningful connections between ANY of the provided users.
150-
151155
Return a JSON array of matches with this structure:
152156
[
153157
{
@@ -206,31 +210,81 @@ Be thorough and find ALL potential matches!
206210
console.log(`Number of wishlists: ${wishlists.length}`);
207211
console.log("=".repeat(100) + "\n");
208212

209-
const response = await this.openai.chat.completions.create({
210-
model: "gpt-4",
211-
messages: [
212-
{
213-
role: "system",
214-
content: "You are an AI matching assistant. Your goal is to find meaningful connections between people based on their wishlists. Analyze all wishlists and return ALL matches found as a JSON array. If wishlists are blank, templated with minimal content, or insufficient for meaningful matching, return an empty array []."
215-
},
216-
{
217-
role: "user",
218-
content: prompt,
219-
},
220-
],
221-
temperature: 0.7,
222-
max_tokens: 4000, // Increased token limit for multiple matches
223-
});
213+
let response;
214+
try {
215+
response = await this.openai.chat.completions.create({
216+
model: "gpt-4",
217+
messages: [
218+
{
219+
role: "system",
220+
content: "You are an AI matching assistant. Your goal is to find meaningful connections between people based on their wishlists. You MUST actively search for matches - look for complementary needs, shared interests, and skill exchanges. Return ALL matches found as a JSON array. Only return an empty array if there are genuinely zero possible connections between any users."
221+
},
222+
{
223+
role: "user",
224+
content: prompt,
225+
},
226+
],
227+
temperature: 0.7,
228+
max_tokens: 4000, // Increased token limit for multiple matches
229+
});
230+
} catch (error: any) {
231+
console.error("OpenAI API Error:");
232+
console.error(" Error type:", error?.constructor?.name);
233+
console.error(" Error message:", error?.message);
234+
console.error(" Error code:", error?.code);
235+
console.error(" Error status:", error?.status);
236+
237+
// Check for rate limit errors
238+
if (error?.status === 429 || error?.code === 'rate_limit_exceeded' || error?.message?.includes('rate limit')) {
239+
console.error("RATE LIMIT DETECTED!");
240+
console.error(" Rate limit error details:", JSON.stringify(error, null, 2));
241+
throw new Error("OpenAI rate limit exceeded. Please try again later.");
242+
}
243+
244+
// Check for other API errors
245+
if (error?.status) {
246+
console.error(`OpenAI API returned status ${error.status}`);
247+
console.error(" Full error:", JSON.stringify(error, null, 2));
248+
}
249+
250+
throw error;
251+
}
252+
253+
// Log response headers if available (for rate limit info)
254+
if (response?.headers) {
255+
console.log("OpenAI Response Headers:");
256+
console.log(" x-ratelimit-limit:", response.headers['x-ratelimit-limit']);
257+
console.log(" x-ratelimit-remaining:", response.headers['x-ratelimit-remaining']);
258+
console.log(" x-ratelimit-reset:", response.headers['x-ratelimit-reset']);
259+
}
224260

225261
const content = response.choices[0]?.message?.content;
226262

263+
// Log rate limit information if available
264+
const responseObj = response as any;
265+
if (responseObj?.headers) {
266+
console.log("OpenAI Rate Limit Info:");
267+
console.log(` Limit: ${responseObj.headers['x-ratelimit-limit'] || 'N/A'}`);
268+
console.log(` Remaining: ${responseObj.headers['x-ratelimit-remaining'] || 'N/A'}`);
269+
console.log(` Reset: ${responseObj.headers['x-ratelimit-reset'] || 'N/A'}`);
270+
}
271+
272+
// Check for suspiciously short responses (might indicate rate limiting or errors)
273+
if (content && content.length < 10) {
274+
console.warn("WARNING: Received very short response from AI (might indicate rate limiting or error)");
275+
console.warn(` Response: "${content}"`);
276+
console.warn(` Response length: ${content.length} characters`);
277+
}
278+
227279
console.log("\n" + "=".repeat(100));
228280
console.log("AI RESPONSE DEBUG - FULL RESPONSE FROM AI:");
229281
console.log("=".repeat(100));
230282
console.log(content);
231283
console.log("=".repeat(100));
232284
console.log(`Response length: ${content?.length || 0} characters`);
233285
console.log(`Usage: ${JSON.stringify(response.usage, null, 2)}`);
286+
console.log(`Model: ${response.model || 'N/A'}`);
287+
console.log(`Finish reason: ${response.choices[0]?.finish_reason || 'N/A'}`);
234288
console.log("=".repeat(100) + "\n");
235289

236290
if (!content) {

platforms/dreamsync-api/src/services/WishlistSummaryService.ts

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,28 @@ Rules:
6666
temperature: 0.2,
6767
max_tokens: 500,
6868
response_format: { type: "json_object" },
69+
}).catch((error: any) => {
70+
console.error("WishlistSummaryService OpenAI API Error:");
71+
console.error(" Error type:", error?.constructor?.name);
72+
console.error(" Error message:", error?.message);
73+
console.error(" Error code:", error?.code);
74+
console.error(" Error status:", error?.status);
75+
76+
if (error?.status === 429 || error?.code === 'rate_limit_exceeded' || error?.message?.includes('rate limit')) {
77+
console.error("RATE LIMIT DETECTED in WishlistSummaryService!");
78+
console.error(" Rate limit error details:", JSON.stringify(error, null, 2));
79+
}
80+
81+
throw error;
6982
});
83+
84+
// Log rate limit headers if available
85+
if (response?.headers) {
86+
const remaining = response.headers['x-ratelimit-remaining'];
87+
if (remaining !== undefined && parseInt(remaining) < 10) {
88+
console.warn(`WishlistSummaryService: Low rate limit remaining: ${remaining}`);
89+
}
90+
}
7091

7192
const raw = response.choices[0]?.message?.content || "";
7293
const parsed = this.parseSummary(raw);

0 commit comments

Comments
 (0)