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

github.com/ayush6624/go-chatgpt

Package Overview
Dependencies
Alerts
File Explorer
Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

github.com/ayush6624/go-chatgpt

  • v0.3.0
  • Source
  • Go
  • Socket score

Version published
Created
Source

Go-ChatGPT

Go-ChatGPT is an open-source GoLang client for ChatGPT, a large language model trained by OpenAI. With Go-ChatGPT, you can quickly and easily integrate ChatGPT's language processing capabilities into your Go applications.

Features

  • Easy-to-use GoLang client for ChatGPT
  • Sends text to ChatGPT and receives a response
  • Support custom model and parameters
  • Supports GPT3.5 and GPT4 models

Installation

You can install ChatGPT-Go using Go modules:

go get github.com/ayush6624/go-chatgpt

Getting Started

Get your API key from the OpenAI Dashboard - https://platform.openai.com/account/api-keys and export this either as an environment variable, or put this your .bashrc or .zshrc

export OPENAI_KEY=sk...

  1. In your Go code, import the ChatGPT-Go package:

    import (
        "github.com/ayush6624/go-chatgpt"
    )
    
  2. Create a new ChatGPT client with your API key

    key := os.Getenv("OPENAI_KEY")
    
    client, err := chatgpt.NewClient(key)
    if err != nil {
    	log.Fatal(err)
    }
    
  3. Use the SimpleSend API to send text to ChatGPT and get a response.

     ctx := context.Background()
     
     res, err := c.SimpleSend(ctx, "Hello, how are you?")
     if err != nil {
     	// handle error
     }
    

    The SimpleSend method sends the specified text to ChatGPT and returns a response. If an error occurs, it returns an error message.

  4. To use a custom model/parameters, use the Send API.

     ctx := context.Background()
     
     res, err = c.Send(ctx, &chatgpt.ChatCompletionRequest{
     	Model: chatgpt.GPT35Turbo,
     	Messages: []chatgpt.ChatMessage{
     		{
     			Role: chatgpt.ChatGPTModelRoleSystem,
     			Content: "Hey, Explain GoLang to me in 2 sentences.",
     		},
     	},
     })
     if err != nil {
     	// handle error
     }
    

Contribute

If you want to contribute to this project, feel free to open a PR or an issue.

License

This package is licensed under MIT license. See LICENSE for details.


codecov Go

FAQs

Package last updated on 20 Jul 2023

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