69 أسطر
1.8 KiB
Python
69 أسطر
1.8 KiB
Python
# To run this code you need to install the following dependencies:
|
|
# pip install google-genai
|
|
|
|
import base64
|
|
import os
|
|
from google import genai
|
|
from google.genai import types
|
|
|
|
|
|
def generate(description, instruction):
|
|
client = genai.Client(
|
|
api_key=""
|
|
)
|
|
|
|
model = "gemini-2.5-flash"
|
|
contents = [
|
|
types.Content(
|
|
role="user",
|
|
parts=[
|
|
types.Part.from_text(text=description),
|
|
],
|
|
),
|
|
]
|
|
generate_content_config = types.GenerateContentConfig(
|
|
thinking_config=types.ThinkingConfig(
|
|
thinking_budget=0,
|
|
),
|
|
response_mime_type="application/json",
|
|
response_schema=genai.types.Schema(
|
|
type=genai.types.Type.OBJECT,
|
|
required=[
|
|
"percentage",
|
|
"why I'm I a good fit",
|
|
"what I'm I missing",
|
|
],
|
|
properties={
|
|
"percentage": genai.types.Schema(
|
|
type=genai.types.Type.INTEGER,
|
|
),
|
|
"why I'm I a good fit": genai.types.Schema(
|
|
type=genai.types.Type.STRING,
|
|
),
|
|
"what I'm I missing": genai.types.Schema(
|
|
type=genai.types.Type.STRING,
|
|
),
|
|
},
|
|
),
|
|
system_instruction=[
|
|
types.Part.from_text(text=instruction),
|
|
],
|
|
)
|
|
|
|
# for chunk in client.models.generate_content_stream(
|
|
# model=model,
|
|
# contents=contents,
|
|
# config=generate_content_config,
|
|
# ):
|
|
# print(chunk.text, end="")
|
|
response = client.models.generate_content(
|
|
model=model,
|
|
contents=contents,
|
|
config=generate_content_config,
|
|
)
|
|
return response.text
|
|
|
|
|
|
if __name__ == "__main__":
|
|
generate()
|