Giter Club home page Giter Club logo

openai-python-integration's Introduction

OpenAI Python Integration

This repository comprises my studies regarding the integration of a Python project with the OpenAI API.

Step 1: API Integration

  • Adjusting Playground parameters such as temperature and maximum length to control the creativity and output of GPT, aiming to generate more coherent and context-adapted responses.
  • Utilizing the OpenAI library to make requests to the API and generate responses from a GPT-3.5 model, learning how to pass system and user messages, as well as safeguarding the API key for security.
  • Hiding identification keys in environment variables to protect sensitive information when performing API integrations.

Step 2: Prompt engineering and prompt template

  • Using the GPT-3 API to categorize products in an e-commerce context, adjusting parameters to obtain multiple responses, and exploring the API documentation to understand its operation and available options.
  • Enhancing the system prompt to guide GPT model responses with strategies such as specifying the desired output format and providing examples.
  • Creating a product categorization function using a prompt template to dynamically insert parameters such as valid categories and product names, enabling a more flexible and organized interaction with the code.

Step 3: Costs, models and token count

  • Selecting the appropriate language model for our tasks, taking into account token limits, context, and cost, and choosing based on the specific needs of the project.
  • Utilizing the TikToken library to count and estimate the number of tokens in a text to assess the usage of language models, understand the internal structure of tokens, and calculate processing costs.
  • Dynamically choosing language models based on the number of input tokens and calculating the expected size of the output to ensure proper functioning of text generation.

Step 4: Batch and error handler

  • Using language models to perform sentiment analysis on product reviews, summarizing the evaluations, determining the overall sentiment (positive, neutral, or negative), identifying strengths and weaknesses, and saving the results in files.
  • Refactoring the code to process sentiment analyses in batches, utilizing a function to perform the analysis for each product in the list, and adding prints to track progress and identify potential errors during batch analysis.
  • Handling exceptions when making batch calls to an API using try and except code blocks to capture and handle different types of errors.
  • Implementing a retry logic, where we attempt the call again after a short interval in case of an error, to address temporary issues.
  • Managing rate limits in the use of the GPT API, which are defined by the number of requests per day (RPD), requests per minute (RPM), and the number of tokens per minute (TPM).

Step 5: Product Recommendation Email Challenge

  • Transform the result of the GPT call into a structured JSON object, allowing iteration for each client and the execution of product recommendation and email writing operations based on the identified profiles.
  • Load a list of products from a text file, create a function to recommend products based on customer purchase profiles, and format the output of recommendations in a readable manner.

openai-python-integration's People

Contributors

lucasviinic avatar

Watchers

Kostas Georgiou avatar  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.