Last active
December 19, 2024 19:47
-
-
Save philschmid/140baac6de103c49c9d910e17bf6d8d3 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# pip install google-genai | |
from google import genai | |
# create client | |
client = genai.Client(api_key='API_KEY') | |
# use Gemini 2.0 with Flash Thinking | |
stream = client.models.generate_content_stream( | |
model='gemini-2.0-flash-thinking-exp-1219', | |
contents=f"""Can you crack the code? | |
9 2 8 5 (One number is correct but in the wrong position) | |
1 9 3 7 (Two numbers are correct but in the wrong positions) | |
5 2 0 1 (one number is correct and in the right position) | |
6 5 0 7 (nothing is correct) | |
8 5 24 (two numbers are correct but in the wrong""" | |
) | |
for chunk in stream: | |
print(chunk.text, end="", flush=True) | |
# Let's break down this code-cracking puzzle step-by-step, simulating a logical thought process. | |
# | |
# **1. Analyze the Clues:** | |
# | |
# I first read through all the clues to get a general sense of the information provided. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from google import genai | |
client = genai.Client( | |
api_key='API_KEY', | |
http_options={ | |
'api_version': 'v1alpha', | |
}) | |
stream = client.models.generate_content_stream( | |
model='gemini-2.0-flash-thinking-exp-1219', | |
contents=f"""What is 2*2-1*4^4""" | |
) | |
thinking = True | |
print("****** Start thinking... ******") | |
for chunk in stream: | |
for candidate in chunk.candidates: | |
for part in candidate.content.parts: | |
if part.thought: | |
is_thinking = True | |
elif is_thinking: # prints "Finished thinking" when transitioning from thinking to not thinking | |
is_thinking = False | |
print("\n") | |
print("****** Finished thinking... ******") | |
print("\n") | |
print(part.text, end="", flush=True) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment