Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

github.com/masacento/langchaingo/examples/googleai-completion-example

Package Overview
Dependencies
Alerts
File Explorer
Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

github.com/masacento/langchaingo/examples/googleai-completion-example

  • v0.0.0-20240918114649-3eddfb5f6be7
  • Source
  • Go
  • Socket score

Version published
Created
Source

Google AI Completion Example

Welcome to the Google AI Completion Example! This simple Go program demonstrates how to use the Google AI API to generate text completions using the langchaingo library.

What This Example Does

This example:

  1. Sets up a connection to the Google AI API using your API key.
  2. Sends a prompt to the API asking "Who was the second person to walk on the moon?"
  3. Receives and prints the generated response.

How It Works

  1. The program starts by setting up the context and retrieving your Google AI API key from the API_KEY environment variable.

  2. It then initializes a new Google AI language model client using the googleai.New() function.

  3. A prompt is defined: "Who was the second person to walk on the moon?"

  4. The program sends this prompt to the Google AI model using llms.GenerateFromSinglePrompt().

  5. Finally, it prints the generated answer to the console.

Running the Example

To run this example:

  1. Make sure you have Go installed on your system.

  2. Set your Google AI API key as an environment variable:

    export API_KEY=your_api_key_here
    
  3. Run the program:

    go run googleai-completion-example.go
    
  4. The program will output the AI-generated answer to the question about the second person to walk on the moon.

This example showcases how easy it is to integrate Google AI's powerful language models into your Go applications using the langchaingo library. Happy coding!

FAQs

Package last updated on 18 Sep 2024

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc