This repository contains a Python script (chatgpt_integration.py) that allows you to interact with OpenAI's ChatGPT model using the OpenAI API. You can ask ChatGPT anything by providing a prompt, and the script will return the model's response.
(Values below can be manually adjusted while calling the function)
model: "gpt-3.5-turbo"
assistant: "You are a helpful assistant."
max tokens: 100
-
API Key Setup: Obtain your OpenAI API key and replace the placeholder
YOUR_API_KEYwith your actual API key in theCHATGPT_API_KEYvariable. -
Code Integration: Import the
ChatGPTclass into your project or script. -
Asking Questions: Use the
askmethod of theChatGPTclass to interact with the ChatGPT model. Provide a prompt, and the method will return the model's response.response = ChatGPT.ask(prompt="What is the meaning of life?") print(response)
You can also customize the assistant's prompt, choose the model version, and set the maximum number of tokens in the response.
response = ChatGPT.ask(prompt="Tell me a joke.", assistant_prompt="You are a funny assistant.", model="gpt-3.5-turbo", max_tokens_response=50)
print(response)- Python 3.x
- Needed libraries can be automatically installed by opening
dependencies.baton Windows computer
# Example Usage
import chatgpt_integration
# Replace 'YOUR_API_KEY' with your actual API key
CHATGPT_API_KEY = "YOUR_API_KEY"
# Set your API key
chatgpt_integration.CHATGPT_API_KEY = CHATGPT_API_KEY
# Ask a question
response = chatgpt_integration.ChatGPT.ask("What is the capital of France?")
print(response)- Programmer: Ondrej Tomasek
- LinkedIn: linkedin.com/in/ondrat
Feel free to reach out if you have any questions or feedback!