Gemini Web Chat 的魔力与自动化挑战

最近,我在使用 Gemini Web Chat 进行创意写作时发现它的效果非常出色。然而,当我尝试通过 Gemini API 实现自动化时,效果却只有一半,这让我感到非常沮丧。 在这篇文章中,我将探讨 Gemini Web Chat 背后的魔力,并探讨如何在不依赖 Gemini API 的情况下实现自动化。让我们开始探索吧。

Gemini Web Chat 的效果

在最近的一项任务中,我需要创建一个电子邮件营销活动。为了使邮件内容更加个性化,我尝试了 Gemini Web Chat。使用 Gemini Pro 模型和相同的提示,我得到了非常好的结果。

尝试 Gemini API

尽管 Web Chat 的效果令人满意,但当我尝试使用 Gemini API 进行同样的任务时,效果却大打折扣。这让我对自动化的可行性产生了疑问。

探索替代方案

面对 Gemini API 的限制,我开始寻找其他方法来实现自动化。以下是一些可能的替代方案:

  1. 本地部署: 考虑将 Gemini 模型部署到本地服务器,以便更灵活地控制和优化。

  2. 第三方工具: 探索是否有其他第三方工具可以提供类似的服务,同时支持自动化。

  3. 自定义脚本: 编写自定义脚本来模拟 Gemini Web Chat 的行为,以实现自动化。

结论

尽管 Gemini API 在自动化方面存在挑战,但通过探索其他方法,我们仍然可以找到实现自动化的途径。让我们继续前进,找到最佳的解决方案。

<span id="d490" data-selectable-paragraph="">Generate cold email.  
Target Audience: Small Startups  
Goal:  Get reply  
Value Propositon: Find best Developers  
Recepient: John Smith, CEO of Acma, Inc.  
Keep it spartan and concise.

Gemini 网络聊天(专业版)返回:

<span id="607e" data-selectable-paragraph="">Subject: Finding Top Talent That Scales Fast, Like Acma  
  
Hi John,  
  
Your success at Acma is inspiring! Did you know finding the right   
developers can be 2x faster with our targeted talent pool &amp; AI matching?  
  
Just a quick question: are you actively growing your dev team?  
  
No pressure, just curious if we could help save you time &amp; land rockstars.  
  
Best,  
[Your Name]

但是当我在 Gemini API 中使用请求做同样的事情时:

<span id="4ed7" data-selectable-paragraph="">POST: https:  
  
{  
     "contents": [  
        {  
         "parts":[{  
           "text": "My Prompt goes here"}]},  
      ]  
}

结果要差得多:

<span id="13ac" data-selectable-paragraph="">Subject: Unlock Your Startup's Potential with Top Talent  
  
Dear John Smith,  
  
As the CEO of Acma, Inc., I understand the importance of finding   
exceptional developers to drive your startup's success.  
  
Our platform connects startups with the best software engineers tailored   
to your specific needs. We leverage AI and a global network to provide a seamless and efficient recruitment experience.  
  
We believe that every startup can access the talent they need to thrive.  
Let us help you find the perfect match for your team.  
  
Schedule a quick call to learn more: [Insert scheduling link]  
  
Best regards,  
[Your Name]

在尝试了Web Chat以及通过API运行相同提示之后,我发现Web Chat提供的结果更加简洁、直接,并且更具有人性化的感觉。然而,当我转向Gemini并使用相同的提示时,API返回的结果并不理想。

随后,我决定尝试ChatGPT。遗憾的是,在这里我也遇到了相似的问题:即通过API获得的结果不如预期。

进一步的研究表明,许多用户在使用ChatGPT时也面临着类似的情况。最常见的建议是采用系统提示符来优化与AI的交互体验。

综上所述,尽管Web Chat提供了更为满意的用户体验,但在使用Gemini和ChatGPT API时却未能达到同样的效果。为改善这种情况,考虑采取最佳实践之一——利用系统提示符来引导对话,可能会有所帮助。

<span id="ac7c" data-selectable-paragraph="">You are ChatGPT, a large language model  
trained by OpenAI, based on the GPT-3.5 architecture.  
Knowledge cutoff: 2021-09  
Current date: {Today's Date}

尽管 ChatGPT 在许多方面表现出色,但对于创意写作来说,Gemini 似乎更具优势。为了实现 Gemini Web Chat 的自动化,我采用了 Puppeteer 和简短的 C# 脚本。

<span id="b545" data-selectable-paragraph="">using PuppeteerSharp;  
  
IBrowser browser;  
IPage page;  
  
  
  
  
browser = await Puppeteer.ConnectAsync(new ConnectOptions  
{  
    BrowserURL = "http://127.0.0.1:9222",  
});  
  
  
var pages = await browser.PagesAsync();  
page = pages[0];  
  
  
if (!page.Url.StartsWith("https://gemini.google.com/app"))  
{  
    Console.WriteLine($"Go to gemini Chat \"https://gemini.google.com\" and login.");  
    return;  
}  
  
  
Console.WriteLine($"Ask Gemini:");  
string prompt = Console.ReadLine();  
  
string responseText = await SendMessage(prompt, page);  
  
Console.WriteLine("\nResponse from Gemini:");  
Console.WriteLine(responseText);  
  
Console.WriteLine("\n\nPress any key to exit");  
Console.ReadKey();  
  
async Task&lt;string&gt; SendMessage(string prompt, IPage page)  
{  
  
      
    var selector = "rich-textarea &gt; div &gt; p";  
    await page.QuerySelectorAsync(selector).EvaluateFunctionAsync("(el, content) =&gt; el.textContent = content", prompt);  
    await Task.Delay(1000);  
  
      
    selector = "div[class*=\"send-button-container\"] &gt; button";  
    var elementHandle = await page.QuerySelectorAsync(selector);  
    await elementHandle.EvaluateFunctionAsync("(el, content) =&gt; el.click()", "nothing");  
  
    selector = "message-content[class*=\"model-response-text\"]";  
      
      
    await page.WaitForSelectorAsync(selector);  
      
      
    await Task.Delay(5000);  
  
      
    elementHandle = await page.QuerySelectorAsync(selector);  
    var response = await elementHandle.GetPropertyAsync("innerText");  
  
    string responseText = null;  
    if (response != null)  
        responseText = response.RemoteObject.Value.ToString();  
  
    return responseText;  
}

包括完整控制台应用程序的完整代码位于此处:

 GitHub 存储库

当您运行此控制台应用程序时,会发生以下情况:

重要提示:在运行控制台应用程序之前,您需要执行以下步骤:

  1. 使用命令行启动 chrome:
<span id="d92f" data-selectable-paragraph="">"C:\Program Files (x86)\Google\Chrome\Application\chrome.exe" --remote-debugging-port=9222 --user-data-dir=/temp

2. 在 Chrome 中,访问:https: //gemini.google.com/

3. 如果尚未登录,请登录 Gemini 聊天。

4. 执行控制台应用程序,它将“操纵”您的 chrome。

使用 Gemini 网络聊天自动生成个性化电子邮件

使用上一节中的代码,我现在可以创建一个使用脚本读取的 Google 工作表,并为每一行调用 Gemini Web Chat API。

 效果很好!