|
| 1 | +import json |
| 2 | +import re |
| 3 | + |
| 4 | +from llmebench.datasets import SpokenNativQADataset |
| 5 | +from llmebench.models import OpenAIModel |
| 6 | +from llmebench.tasks import MultiNativQATask |
| 7 | + |
| 8 | + |
| 9 | +def metadata(): |
| 10 | + return { |
| 11 | + "author": "Arabic Language Technologies, QCRI, HBKU", |
| 12 | + "model": "GPT4-o", |
| 13 | + "description": "Deployed on Azure.", |
| 14 | + "scores": {}, |
| 15 | + } |
| 16 | + |
| 17 | + |
| 18 | +def config(): |
| 19 | + return { |
| 20 | + "dataset": SpokenNativQADataset, |
| 21 | + "task": MultiNativQATask, |
| 22 | + "model": OpenAIModel, |
| 23 | + "general_args": {"test_split": "arabic_qa_azure"}, |
| 24 | + } |
| 25 | + |
| 26 | + |
| 27 | +def prompt(input_sample): |
| 28 | + # Define the question prompt |
| 29 | + base64_wav = input_sample["wav"] |
| 30 | + |
| 31 | + question_prompt = f""" |
| 32 | + Please use your expertise to answer the following Arabic question. Answer in Arabic and rate your confidence level from 1 to 10. Provide your response in the following JSON format: {{"answer": "your answer", "score": your confidence score}}. Please provide JSON output only. No additional text. Answer should be limited to less or equal to {input_sample['length']} words. |
| 33 | +
|
| 34 | + Question: {input_sample['question']} |
| 35 | + |
| 36 | + """ |
| 37 | + # Define the assistant prompt |
| 38 | + assistant_prompt = """ |
| 39 | + You are an Arabic AI assistant specialized in providing detailed and accurate answers across various fields. Your task is to deliver clear, concise, and relevant information. |
| 40 | + """ |
| 41 | + return [ |
| 42 | + { |
| 43 | + "role": "user", |
| 44 | + "content": [ |
| 45 | + { |
| 46 | + "type": "text", |
| 47 | + "text": question_prompt, |
| 48 | + }, |
| 49 | + { |
| 50 | + "type": "input_audio", |
| 51 | + "input_audio": {"data": base64_wav, "format": "wav"}, |
| 52 | + }, |
| 53 | + ], |
| 54 | + } |
| 55 | + ] |
| 56 | + |
| 57 | + |
| 58 | +def post_process(response): |
| 59 | + content = response["choices"][0]["message"]["content"].strip() |
| 60 | + content = content.replace("\n", "").strip() |
| 61 | + if "```json" in content: |
| 62 | + content = re.search(r"```json(.*)```", content).group(1) |
| 63 | + return json.loads(content)["answer"] |
0 commit comments