Code Monkey home page Code Monkey logo

openai-gpt-turorial's Introduction

OpenAI GPT API Client

This library provides an easy-to-use Python interface for interacting with OpenAI's GPT models, including both the Assistant API and the Completion endpoint.

Features

  • Interactive GPT with Assistant
  • gpt request with Completions api
  • Cost calculation for api requests and responses from openai

Getting Started

  1. Clone the Repository: Clone this repository to your local machine:
git clone https://github.com/thedev-junyoung/GoogleDrivePyManager.git
  1. To get started with this library, you'll need to install it via pip and set up your OpenAI API key.
pip install openai python-dotenv
  1. create a .env file at the root of your project and include your OpenAI API key:
OPENAI_API_KEY='your-api-key-here'

Example Usage

This library supports both text completions using the Completion API and structured conversations with the Assistant API. Below are examples of how to use each feature.

Using the Completion API for Text Generation

To generate text completions, such as answering a trivia question, use the following code:

from dotenv import load_dotenv
from openai_api_client import OpenAICompletion  # Ensure you have this module in your project
import os

if __name__ == "__main__":
    # Load environment variables from the .env file
    load_dotenv()
    
    # Retrieve your OpenAI API key from the .env file
    OPENAI_API_KEY = os.getenv("OPENAI_API_KEY")
    
    # Initialize the completion service with the specified model
    service = OpenAICompletion(model_name="gpt-3.5-turbo", open_ai_key=OPENAI_API_KEY)
    
    # Provide the system prompt and user input
    system_prompt = "You are a helpful assistant designed to output JSON."
    user_input = "Who won the world series in 2020?"
    
    # Call the generate function to get the result
    result = service.generate(system_prompt, user_input)
    
    # Print the resulting text completion
    print(result)

Using the Completion API

The Completion API can be used to generate text completions for a variety of tasks.

from dotenv import load_dotenv
from legal_document_service import OpenAICompletion
import os

if __name__ == "__main__":
    # Load environment variables from the .env file
    load_dotenv()
    # Get API key from the .env file
    OPENAI_API_KEY = os.getenv("OPENAI_API_KEY")
    OpenAICompletion
    # Initialize the service with the chosen model
    service = OpenAICompletion(model_name="gpt-3.5-turbo", open_ai_key=OPENAI_API_KEY)
    
    # System prompt and user input for generating a legal document
    system_prompt = "You are a helpful assistant designed to output JSON."
    user_input = "Who won the world series in 2020?"
    
    # Generate the legal document
    result = service.generate(system_prompt, user_input)
    
    # Print the result
    print(result)

이미지 대체 텍스트

References

openai-gpt-turorial's People

Contributors

thedev-junyoung avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.