Skip to content

Instantly share code, notes, and snippets.

@philschmid
Last active December 19, 2024 19:47
Show Gist options
  • Save philschmid/140baac6de103c49c9d910e17bf6d8d3 to your computer and use it in GitHub Desktop.
Save philschmid/140baac6de103c49c9d910e17bf6d8d3 to your computer and use it in GitHub Desktop.

Revisions

  1. philschmid renamed this gist Dec 19, 2024. 1 changed file with 0 additions and 0 deletions.
    File renamed without changes.
  2. philschmid revised this gist Dec 19, 2024. 1 changed file with 26 additions and 0 deletions.
    26 changes: 26 additions & 0 deletions gistfile1.txt
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,26 @@
    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)
  3. philschmid created this gist Dec 19, 2024.
    24 changes: 24 additions & 0 deletions gemini_flash_thinking.py
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,24 @@
    # 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.