Text Generation with Gemini API

Generating Text with Gemini API

Like OpenAI’s ChatGPT, Google Gemini is a powerful tool for text generation. You can create your own scripts in your local environment by leveraging the API. You can clearly see all the details from the response, including the safety parameters.

Comparing OpenAI and ChatGPT’s Text Generation Features

OpenAI and ChatGPT are both very good at text generation. Gemini leverages real-time information, which is a big advantage for certain applications. Gemini is also very strong at synthesizing information from different sources, including multi-modal input. On the other hand, ChatGPT has a great conversational flow and is good at maintaining contextual history. Here’s a fun tool to compare multiple AIs so you can see side-by-side responses. One thing they both have in common is the need for safety in regard to prompts.

Understanding Safety Settings

When generating text, it’s important to consider the safety settings of the conversation. Google Gemini utilizes filters to adjust the safety across four categories:

  • Harassment: Negative comments that target identity and/or protected attributes.
  • Hate speech: Content that’s inconsiderate or inappropriate.
  • Sexually explicit: Contains lewd content.
  • Dangerous: Encourages or facilitates harmful acts.

Depending on how the filters are set, different prompts may not be allowed. It’s important to note that safety is calculated on the probability and not the severity.

Degrees of Safety

You can filter each category based on degree:

  • BLOCK_NONE: Always show regardless of probability.
  • BLOCK_ONLY_HIGH: Block when the probability of unsafe content is high.
  • BLOCK_MEDIUM_AND_ABOVE: Block when the probability of unsafe content is medium or higher.
  • BLOCK_LOW_AND_ABOVE: Block when the probability of unsafe content is low or above.
  • HARM_BLOCK_THRESHOLD_UNSPECIFIED: When the threshold is unspecified, Gemini will use the default.
See forum comments
Download course materials from Github
Previous: Introduction Next: Demo: Text Generation with Gemini API