CaCl2

氯离子

一些有趣的想法,与碎碎念...
x
github
email

在大陸地區優雅地使用Gemini Pro模型

Warning

Providing generative AI services within the territory of the People's Republic of China must comply with the "Interim Measures for the Administration of Generative AI Services".

Introduction#

Recently, Sora, released by OpenAI, has become the hottest topic in the field of GAI (Generative Artificial Intelligence). Coincidentally, Gemini Pro 1.5 was also released on the same day as Sora, but it was overshadowed by Sora.
574e9258d109b3de6690d394d590fd8c810a4cdf
In fact, Google's Gemini Pro 1.5 is also very powerful (see the link above for details). The author has already applied for testing permission for this model. While waiting, let's experience Gemini Pro 1.0.


API Application#

As we all know, due to certain reasons, users in mainland China cannot directly use Gemini. Here is a list of supported countries and regions.

After using a corresponding region's proxy, we can start the process of obtaining an API Key. Visit this link and follow the instructions on the page to obtain an API Key. Be sure to keep your API Key confidential.

Regular users can use the Gemini Pro 1.0 model for free, while the Ultra model requires payment.

Using Cloudflare Workers as Reverse Proxy#

The official API provided by Google cannot be accessed normally in China. Therefore, we can make it accessible in the Chinese environment by using a reverse proxy. To do this, we need a domain and a Cloudflare account, and add them to Cloudflare. The specific steps are not described in this article.

Visit dash.cloudflare.com to access the Cloudflare dashboard and click on the Workers and Pages option in the sidebar.

image

Click on Create Application.

image

Click on Create Worker.

image

You can choose any name or use the default one. Then click on the Deploy button. After deployment, click on the Edit Code button.

image

Now you will enter an editor interface. Delete the preset code and enter the following code:

export default {
  async fetch(request, env) {
    const url = new URL(request.url);
    url.host = 'generativelanguage.googleapis.com';
    return fetch(new Request(url, request))
  }
}

Click on the Save and Deploy button in the upper right corner. Your Gemini API reverse proxy is now ready, and you can use the address of your workers to replace the API address provided by Google. However, since the default address of workers is blocked by the GFW, we need to add our own domain.

On the Workers page, select the Triggers tab and click on the Add Custom Domain button. (Note: The domain added here must be a domain that has already been bound in Cloudflare)

image

After that, we can use our own domain to access the Gemini API.

Frontend Deployment#

Next, we just need to use projects like ChatGPT-Next-Web or GeminiProChat, fill in our API key and the reverse proxy API link, and we can use the Gemini Pro 1.0 model for free. The limit is 60 requests per minute, which is quite generous. Let's take ChatGPT-Next-Web as an example. Visit its code repository and click on Fork in the upper right corner.
image
Just confirm and proceed to the next step.
Then, visit Vercel and log in directly with your GitHub account.
Click on Add New... in the upper right corner and select Project from the dropdown menu. In the Import Git Repository section, select the repository you just forked and click on Import.
image
Under the Environment Variables section, fill in the environment variables according to the project's guide. Here are my environment variables for reference.

image

Google_URL is the link to your reverse proxy API, the second field specifies the displayed model, and the third field is the API Key you obtained from Google.
After confirming, the frontend environment is deployed. To make it more convenient to access, you can add your own domain in the Domain tab of the Settings page.

Mission accomplished#

Now, when you visit the domain assigned to your project, you will see the chat interface ready for conversation.

image

The steps for deploying GeminiProChat are similar.

載入中......
此文章數據所有權由區塊鏈加密技術和智能合約保障僅歸創作者所有。