Skip to content

Commit 861514a

Browse files
committed
Update model and prompt
1 parent 41a0062 commit 861514a

3 files changed

Lines changed: 19 additions & 13 deletions

File tree

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -130,3 +130,4 @@ dist
130130
.pnp.*
131131

132132
.yalc
133+
.DS_Store

predictGender/index.js

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
export default {
2-
async fetch(request, env, ctx) {
2+
async fetch(request, env) {
33
// Handle CORS for browser requests
44
if (request.method === 'OPTIONS') {
55
return new Response(null, {
@@ -26,19 +26,25 @@ export default {
2626
}
2727

2828
// Use env.AI directly - no import needed in dashboard editor
29-
const systemPrompt = `You are a helpful assistant that always responds with valid JSON.
30-
Follow this exact schema: { "gender": "string (M|F|CF|X|NB)", "confidence": "number (decimal between 0 and 1)" }
29+
const systemPrompt = `You are a helpful assistant that always responds with valid JSON.
30+
Follow this exact schema: { "gender": "string (M|F|CF|X|NB)" }
3131
3232
Rules:
3333
- Always return valid JSON
3434
- Follow the provided schema exactly
3535
- Do not include any text outside the JSON object
3636
- Ensure all required fields are present
37-
- Consider Latin American and Spanish naming conventions when analyzing names`;
37+
- Consider Latin American and Spanish naming conventions when analyzing names
38+
- Use 'M' if it is a male name.
39+
- Use 'F' if it is a female name.
40+
- Use 'CF' if it is a list of names in spanish, either comma separated or separated by 'y' and at least one of the names is female.
41+
- Use 'F' if it is a list of names in spanish and all of them are female names.
42+
- Use 'NB' if it is a traditionally non binary name or you know this person is non binary.
43+
- Use 'X' if it is an organization or entity that is not a person and has no gender.`;
3844

39-
const userPrompt = `JSON with the format { gender: 'M'|'F'|'CF'|'X'|'NB', confidence: number } where gender is the probable gender of a person with the name "${name}" and confidence is the decimal percentage of gender certainty. 'M' is for male, 'F' for female, 'CF' for a list of people where at least one is female, 'NB' for non-binary person, and 'X' for an organization or entity that is not a person and has no gender. Consider Latin American naming conventions.`;
45+
const userPrompt = `JSON with the format { gender: 'M'|'F'|'CF'|'X'|'NB' } where gender is the probable gender of a person with the name "${name}".`;
4046

41-
const response = await env.AI.run('@cf/meta/llama-3.1-8b-instruct', {
47+
const response = await env.AI.run('@cf/meta/llama-4-scout-17b-16e-instruct', {
4248
messages: [
4349
{ role: 'system', content: systemPrompt },
4450
{ role: 'user', content: userPrompt }
@@ -69,7 +75,7 @@ export default {
6975
}
7076

7177
// Validate the response structure
72-
if (!jsonResponse.gender || typeof jsonResponse.confidence !== 'number') {
78+
if (!jsonResponse.gender) {
7379
return new Response(JSON.stringify({
7480
error: 'Invalid response structure',
7581
received: jsonResponse

scripts/sendDms.js

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -79,8 +79,8 @@ export const sendDms = async (conn, token, ignoreDmSent = false) => {
7979
name
8080
});
8181
llmResponse = response.data;
82-
const { gender, confidence } = llmResponse;
83-
chooseLlmResponse = (gender === 'M' || gender === 'F') && confidence >= 0.95;
82+
const { gender } = llmResponse;
83+
chooseLlmResponse = (gender === 'M' || gender === 'F');
8484
if (chooseLlmResponse) {
8585
await conn.query('UPDATE columnistos.author SET gender = ? WHERE id = ?',
8686
[gender, id]
@@ -90,11 +90,10 @@ export const sendDms = async (conn, token, ignoreDmSent = false) => {
9090
llmError = error;
9191
}
9292
const genderResponse = llmResponse?.gender || '?';
93-
const percentageResponse = (llmResponse?.confidence || 0) * 100
9493
await sendPrivateWoot(`
9594
${adminHandlesString}
9695
Nuevo autor: ${id} ${name}
97-
Predicción: ${genderResponse} Confianza: ${percentageResponse}%
96+
Predicción: ${genderResponse}
9897
La predicción fue guardada: ${chooseLlmResponse === true ? 'Sí' : 'No' }${llmError ? `
9998
Error: ${llmError}` : ''}
10099
Buscar: https://duckduckgo.com/?q=${encodeURI(name)}&iax=images&ia=images
@@ -104,8 +103,8 @@ export const sendDms = async (conn, token, ignoreDmSent = false) => {
104103
Si es un grupo de co autores con al menos una mujer: ${id} CF
105104
Si es editorial o una organización: ${id} X`, { token });
106105
console.log(`Requested gender for author ${id} ${name}`);
107-
if (chooseLlmResponse) console.log(` Saved author gender ${genderResponse} with ${percentageResponse}% confidence`);
108-
else console.log(` Did not save author gender ${genderResponse} with ${percentageResponse}% confidence`);
106+
if (chooseLlmResponse) console.log(` Saved author gender ${genderResponse}`);
107+
else console.log(` Did not save author gender ${genderResponse}`);
109108
await conn.query('UPDATE columnistos.author SET dm_sent = 1 WHERE id = ?', [id]);
110109
}
111110
};

0 commit comments

Comments
 (0)