Using Gemini with the OpenAI Library
Using Gemini with the OpenAI Library Based on this article , we can now use Gemini with the OpenAI Library. So, I decided to give it a try in this article Currently, only the Chat Completion API and Embedding API are available. In this article, I tried using both Python and JavaScript. Python First, let’s set up the environment. pip install openai python-dotenv Next, let’s run the following code. import os from dotenv import load_dotenv from openai import OpenAI load_dotenv ( ) GOOGLE_API_KEY = os . getenv ( "GOOGLE_API_KEY" ) client = OpenAI ( api_key = GOOGLE_API_KEY , base_url = "https://generativelanguage.googleapis.com/v1beta/" ) response = client . chat . completions . create ( model = "gemini-1.5-flash" , n = 1 , messages = [ { "role" : "system" , "content" : "You are a helpful assistant." } , { ...