IR-IIITH/MultiAgent-OpenDomain-QnA-System
1
1import os2import json3from together import Together4 5def generate_answer_withContext(question, context):6 together_ai_key = os.getenv("TOGETHER_AI")7 if not together_ai_key:8 raise ValueError("TOGETHER_AI environment variable not found. Please set it before running the script.")9 10 11 client = Together(api_key=together_ai_key) 12 13 prompt = f"""Consider the context and generate a brief 1-2 line answer to the question. Output only the answer.14 15Context: {context}16 17Question: {question}18"""19 response = client.chat.completions.create(20 # model="meta-llama/Llama-3-8b-chat-hf",21 model="meta-llama/Meta-Llama-3.1-8B-Instruct-Turbo",22 messages=[{"role": "user", "content": prompt}],23 )24 25 return response.choices[0].message.content26 27 28def generate_answer_zeroShot(question):29 together_ai_key = os.getenv("TOGETHER_AI")30 if not together_ai_key:31 raise ValueError("TOGETHER_AI environment variable not found. Please set it before running the script.")32 33 34 client = Together(api_key=together_ai_key)35 36 prompt = f"""Answer the following question:37 38Question: {question}39"""40 response = client.chat.completions.create(41 model="meta-llama/Llama-3-8b-chat-hf",42 messages=[{"role": "user", "content": prompt}],43 )44 45 return response.choices[0].message.content46 