Skip to content

Instantly share code, notes, and snippets.

@jamesmurdza
Created February 11, 2025 15:43
Show Gist options
  • Select an option

  • Save jamesmurdza/32f0e99c28c65c705b433109f2d41384 to your computer and use it in GitHub Desktop.

Select an option

Save jamesmurdza/32f0e99c28c65c705b433109f2d41384 to your computer and use it in GitHub Desktop.

Revisions

  1. jamesmurdza created this gist Feb 11, 2025.
    52 changes: 52 additions & 0 deletions Providers.md
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,52 @@
    # OpenAI

    ```python
    from openai import OpenAI

    client = OpenAI()

    tools = [{
    "type": "function",
    "function": {
    "name": "get_weather",
    "description": "Get current temperature for a given location.",
    "parameters": {
    "type": "object",
    "properties": {
    "location": {
    "type": "string",
    "description": "City and country e.g. Bogotá, Colombia"
    }
    },
    "required": [
    "location"
    ],
    "additionalProperties": False
    },
    "strict": True
    }
    }]

    completion = client.chat.completions.create(
    model="gpt-4o",
    messages=[
    {
    "role": "user",
    "content": [
    {
    "type": "text",
    "text": "What is in this image? What is the weather like in Paris today?",
    },
    {
    "type": "image_url",
    "image_url": {"url": f"data:image/jpeg;base64,{base64_image}"},
    },
    ],
    }
    ],
    tools=tools
    )

    print(response.choices[0])
    print(completion.choices[0].message.tool_calls)
    ```