├── LICENSE ├── README.md ├── gptintegration ├── __init__.py └── gpt_integration.py └── setup.py /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2024 Eugene Evstafiev 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | [![PyPI version](https://badge.fury.io/py/GPTIntegration.svg)](https://badge.fury.io/py/GPTIntegration) 2 | [![License: MIT](https://img.shields.io/badge/License-MIT-green.svg)](https://opensource.org/licenses/MIT) 3 | [![Downloads](https://static.pepy.tech/badge/gptintegration)](https://pepy.tech/project/gptintegration) 4 | 5 | # GPTIntegration 6 | 7 | `GPTIntegration` is a Python module for integrating GPT models from OpenAI into your projects. It simplifies querying GPT models by handling the setup, communication, and response parsing with the OpenAI API, enabling easy integration and efficient interaction with GPT models. 8 | 9 | ## Installation 10 | 11 | To install `GPTIntegration`, you can use pip: 12 | 13 | ```bash 14 | pip install GPTIntegration 15 | ``` 16 | 17 | ## Usage 18 | 19 | ### As a Python Module 20 | 21 | You can use `GPTIntegration` as a module in your Python scripts. 22 | 23 | Example: 24 | 25 | ```python 26 | from gptintegration import GPTIntegration 27 | 28 | # Initialize the integration with your OpenAI API key 29 | gpt_integration = GPTIntegration('your-openai-api-key') 30 | 31 | # Prepare messages 32 | system_message = "Your system message goes here." 33 | user_message = "Your prompt or user message goes here." 34 | 35 | # Query GPT and get the response 36 | response = gpt_integration.query_gpt(system_message, user_message) 37 | print(response) 38 | ``` 39 | 40 | ### Customizing Your Query 41 | 42 | You can customize your query by adjusting the initialization parameters of the `GPTIntegration` class, such as model, temperature, max tokens, and others to fit the specific needs of your application or to tweak the behavior of the GPT model. 43 | 44 | ## Output Example 45 | 46 | When you query GPT using `GPTIntegration`, it sends the system and user messages to the specified GPT model and returns the model's response. Here is an example output: 47 | 48 | ``` 49 | { 50 | "id": "example-response-id", 51 | "object": "text_completion", 52 | "created": 123456789, 53 | "model": "gpt-3.5-turbo", 54 | ..., 55 | "choices": [ 56 | { 57 | "text": "Response from the GPT model based on the provided messages...", 58 | "index": 0, 59 | "logprobs": null, 60 | "finish_reason": "length" 61 | } 62 | ] 63 | } 64 | ``` 65 | 66 | ## Contributing 67 | 68 | Contributions, issues, and feature requests are welcome! Feel free to check [issues page](https://github.com/chigwell/gptintegration/issues). 69 | 70 | ## License 71 | 72 | [MIT](https://choosealicense.com/licenses/mit/) 73 | -------------------------------------------------------------------------------- /gptintegration/__init__.py: -------------------------------------------------------------------------------- 1 | from .gpt_integration import GPTIntegration 2 | -------------------------------------------------------------------------------- /gptintegration/gpt_integration.py: -------------------------------------------------------------------------------- 1 | import openai 2 | 3 | class GPTIntegration: 4 | def __init__(self, api_key, model="gpt-3.5-turbo", temperature=0.7, max_tokens=150, top_p=1.0, frequency_penalty=0.0, presence_penalty=0.0): 5 | """ 6 | Initializes the GPT Integration with necessary parameters. 7 | Args: 8 | api_key (str): Your OpenAI API key. 9 | model (str): Identifier for the model to be used. Default is "gpt-3.5-turbo". 10 | temperature (float): Controls randomness. Lower is more deterministic. 11 | max_tokens (int): Maximum length of the token output. 12 | top_p (float): Controls diversity. 13 | frequency_penalty (float): Decreases the likelihood of previously used tokens. 14 | presence_penalty (float): Increases the likelihood of new tokens. 15 | """ 16 | self.api_key = api_key 17 | self.model = model 18 | self.temperature = temperature 19 | self.max_tokens = max_tokens 20 | self.top_p = top_p 21 | self.frequency_penalty = frequency_penalty 22 | self.presence_penalty = presence_penalty 23 | self.client = openai.OpenAI(api_key=self.api_key) 24 | 25 | def query_gpt(self, system_message, user_message): 26 | """ 27 | Sends a message to the GPT model and returns the response. 28 | Args: 29 | system_message (str): The system's message, instructions for the GPT model. 30 | user_message (str): The user's message or prompt to be sent to the model. 31 | Returns: 32 | str: The GPT model's response. 33 | """ 34 | chat_completion = self.client.chat.completions.create( 35 | messages=[ 36 | { 37 | "role": "system", 38 | "content": system_message 39 | }, 40 | { 41 | "role": "user", 42 | "content": user_message 43 | } 44 | ], 45 | model=self.model 46 | ) 47 | return chat_completion 48 | 49 | # You can now import this module and use the GPTIntegration class in your applications. 50 | -------------------------------------------------------------------------------- /setup.py: -------------------------------------------------------------------------------- 1 | from setuptools import setup, find_packages 2 | 3 | # Reading long description from README.md 4 | with open('README.md', encoding='utf-8') as f: 5 | long_description = f.read() 6 | 7 | setup( 8 | name='GPTIntegration', 9 | version='0.0.2', 10 | description='A module for integrating various GPT models for diverse tasks.', 11 | long_description=long_description, 12 | long_description_content_type='text/markdown', 13 | author='Eugene Evstafev', 14 | author_email='chigwel@gmail.com', 15 | url='https://github.com/chigwell/GPTIntegration', 16 | packages=find_packages(), 17 | install_requires=[ 18 | 'openai', 19 | ], 20 | classifiers=[ 21 | "Programming Language :: Python :: 3", 22 | "License :: OSI Approved :: MIT License", 23 | "Operating System :: OS Independent", 24 | ], 25 | python_requires='>=3.6', 26 | ) 27 | --------------------------------------------------------------------------------