https://discord.gg/botpress logo
Visi贸n Agent Transcription in Spanish
# 馃help
b
Hello guys! 馃憢馃徎 Currently I鈥檓 using the vision agent to transcribe the text from some receipts that are in Spanish. My problem is that sometimes the vision agent translates some of the text automatically to English. For example, if the image of the receipt says: Hola, como est谩? The vision agent will extract: Hello, como est谩? Anybody knows how could I fix this? Is there any setting to define the vision agent language to Spanish? Thank you very much!!!馃槂馃馃徎馃槂
w
hi gabriel! can you send some screenshots of what's returned in the {{turn.VisionAgent.content}} variable?
i tried replicating it in portuguese but it extracted correctly
b
w
yeah unfortunately it seems like it's a problem on botpress's end. maybe an instruction like "keep the original language" or something is missing from the "vision agent" prompt
if you'd like i can whip up a workaround using the "execute code" card
you'll even be able to edit the prompt yourself to get a more desirable result
b
That would be great! I didn't know you can use execute code cards to modify the vision agent prompt, that's really interesting
w
we won't be modifying the vision agent unfortunately haha we'll be making our own
@better-judge-10532 do you have a preference between gemini or gpt for the vision agent?
since you'll be querying them using your own api key
b
Im scared 馃え hahaha
gpt is ok馃憤
w
Copy code
javascript
const url = 'https://api.openai.com/v1/chat/completions';

const headers = {
  'Authorization': 'Bearer YOUR-KEY-HERE', // replace with your OpenAI API key
  'Content-Type': 'application/json',
};

const imageUrl = `${event.payload.imageUrl}`;

const userPrompt = `Please transcribe or describe the text content visible in this image. If the image contains text in another language, keep the original language.`;

const data = {
  "model": "gpt-4o-mini", 
  "messages": [
    {
      "role": "user", 
      "content": [
        {
          "type": "text",
          "text": userPrompt
        },
        {
          "type": "image_url",
          "image_url": {
            "url": imageUrl 
          }
        }
      ]
    }
  ],
  "max_tokens": 1000
};

// Retry function for 429 errors
const retryRequest = async (requestFn, maxRetries = 3) => {
  for (let i = 0; i <= maxRetries; i++) {
    const response = await requestFn();
    if (response.status !== 429 || i === maxRetries) {
      return response;
    }
    const delay = Math.pow(2, i) * 1000; 
    await new Promise(resolve => setTimeout(resolve, delay));
  }
};


const response = await retryRequest(() => axios.post(url, data, { headers }));


const generatedMessage = response.data.choices[0].message.content;
workflow.transcription = generatedMessage;
there you go
it automatically grabs the image from the last event and transcribes it, then saves it to "workflow.transcription"
feel free to change the model, prompt, max tokens and the final variable
b
Hello Shen. Thank you very much for the code!!
3 Views