Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Code! Api key #1

Open
Lokeiy opened this issue Dec 5, 2023 · 0 comments
Open

Code! Api key #1

Lokeiy opened this issue Dec 5, 2023 · 0 comments

Comments

@Lokeiy
Copy link
Owner

Lokeiy commented Dec 5, 2023

import openai
import requests

Set your OpenAI GPT-3 API key

openai.api_key = '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'

def generate_chatgpt_response(prompt):
# Use the OpenAI GPT-3 API to generate a response
response = openai.Completion.create(
engine="text-davinci-002", # Choose the appropriate engine
prompt=prompt,
max_tokens=150, # Adjust as needed
temperature=0.7, # Adjust as needed
stop=None # Add custom stopping criteria if desired
)

# Extract and return the generated response
return response.choices[0].text.strip()

def interact_with_characters_ai(user_input):
# Generate response from ChatGPT
chatgpt_response = generate_chatgpt_response(user_input)

# Send the response to characters.ai (replace URL with the actual API endpoint)
characters_ai_url = 'https://characters.ai/api'
payload = {'user_input': user_input, 'chatgpt_response': chatgpt_response}
characters_ai_response = requests.post(characters_ai_url, json=payload)

# Extract and return characters.ai's response
return characters_ai_response.text

Example usage

user_input = "Tell me a joke"
characters_ai_response = interact_with_characters_ai(user_input)
print(characters_ai_response)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant