File size: 1,331 Bytes
9f21f05
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
import os
import json
from together import Together

def generate_answer_withContext(question, context):
    together_ai_key = os.getenv("TOGETHER_AI")
    if not together_ai_key:
        raise ValueError("TOGETHER_AI environment variable not found. Please set it before running the script.")


    client = Together(api_key=together_ai_key) 

    prompt = f"""Consider the context and generate a brief 1-2 line answer to the question. Output only the answer.

Context: {context}

Question: {question}
"""
    response = client.chat.completions.create(
        # model="meta-llama/Llama-3-8b-chat-hf",
        model="meta-llama/Meta-Llama-3.1-8B-Instruct-Turbo",
        messages=[{"role": "user", "content": prompt}],
    )

    return response.choices[0].message.content


def generate_answer_zeroShot(question):
    together_ai_key = os.getenv("TOGETHER_AI")
    if not together_ai_key:
        raise ValueError("TOGETHER_AI environment variable not found. Please set it before running the script.")


    client = Together(api_key=together_ai_key)

    prompt = f"""Answer the following question:

Question: {question}
"""
    response = client.chat.completions.create(
        model="meta-llama/Llama-3-8b-chat-hf",
        messages=[{"role": "user", "content": prompt}],
    )

    return response.choices[0].message.content