chatgpt

package module
v0.0.2 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Dec 13, 2023 License: MIT Imports: 6 Imported by: 0

README

chatgpt

chatgpt is a Go package designed to interact with OpenAI's ChatGPT API. It provides a simple and convenient way to integrate ChatGPT functionalities into your Go applications.

Features

  • Easy integration with OpenAI's ChatGPT API.
  • Customizable configuration for API and ChatGPT model.
  • Support for system and user messages in API requests.

Installation

To install the package, run the following command:

go get github.com/Peter-Bird/chatgpt

Usage

Here's a basic example of how to use the chatgpt package:

package main

import (
    "log"

    "github.com/Peter-Bird/chatgpt"
)

func main() {
    client, err := chatgpt.NewChatGPT("path/to/config.json", "your-api-key")
    if err != nil {
        log.Fatal(err)
    }

    response, err := client.GetGPTResponse("Your system message", "Your user message")
    if err != nil {
        log.Fatal(err)
    }

    log.Println("ChatGPT Response:", response)
}

Configuration

Create a JSON file with the following structure for the API and ChatGPT configuration:

{
    "API": {
        "URL": "https://api.openai.com/v1/engines/chatgpt-model-v1/completions",
        "ContentType": "application/json"
    },
    "ChatGPT": {
        "Model": "gpt-3.5-turbo",
        "Temperature": 0,
        "MaxTokens": 100
    }
}

Update the URL, Model, Temperature, and MaxTokens as per your requirements.

Contributing

Contributions are welcome! Feel free to submit pull requests or open issues for bugs, feature requests, or improvements.

License

This project is licensed under the MIT License - see the LICENSE.txt file for details.

Documentation

Overview

Package chatgpt provides functionality to interact with OpenAI's ChatGPT API.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type ChatGPTClient

type ChatGPTClient struct {
	// contains filtered or unexported fields
}

ChatGPTClient holds the configuration and API key for the ChatGPT service.

func NewChatGPT

func NewChatGPT(configPath, apiKey string) (*ChatGPTClient, error)

NewChatGPT initializes a new ChatGPT client with the given configuration file and API key.

func (*ChatGPTClient) GetGPTResponse

func (client *ChatGPTClient) GetGPTResponse(sysMessage, userMessage string) (string, error)

GetGPTResponse interacts with OpenAI's ChatGPT API and returns the response.

type Config

type Config struct {
	API struct {
		URL         string `json:"URL"`
		ContentType string `json:"ContentType"`
	} `json:"API"`
	ChatGPT struct {
		Model       string `json:"Model"`
		Temperature int    `json:"Temperature"`
		MaxTokens   int    `json:"MaxTokens"`
	} `json:"ChatGPT"`
}

Config holds the configuration for the API and ChatGPT.

func LoadConfig

func LoadConfig(path string) (Config, error)

LoadConfig loads the configuration from the given file path.

type Message

type Message struct {
	Role    string `json:"role"`
	Content string `json:"content"`
}

Message represents a chat message.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL