File size: 830 Bytes
ebed33b
 
 
 
 
 
 
 
 
9ac3eaa
ebed33b
9ac3eaa
 
ebed33b
 
 
 
 
9ac3eaa
 
 
 
 
ebed33b
 
 
 
9ac3eaa
 
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
import os
from dotenv import load_dotenv

from google import genai
from google.genai import types

load_dotenv()


sys_instruct = "Provide the output in JSON format where the key is the topic and the value is a list of relevant contents. Ensure the response is clear, user friendly, structured."


def get_response(prompt, task, temperature=0.75):
    client = genai.Client(api_key=os.getenv("GEMINI_API_KEY"))

    response = client.models.generate_content(
        model="gemini-2.0-flash",
        config=types.GenerateContentConfig(
            system_instruction=task + sys_instruct,
            response_mime_type="application/json",
            temperature=temperature,
        ),
        contents=prompt,
    )
    # print(response.text)
    return response.text


# get_response("What is AI?","explain the given prompt")