-
Notifications
You must be signed in to change notification settings - Fork 0
/
promptinterface.py
37 lines (29 loc) · 1012 Bytes
/
promptinterface.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
import openai
# Set your API key
openai.api_key = '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'
# Function to list available engines
def list_engines():
engines = openai.Engine.list()
#for engine in engines.data:
#print(f"Engine: {engine['id']}")
# Function to generate text
def generate_text(prompt, max_tokens=100, temperature=0.7):
response = openai.ChatCompletion.create(
model="gpt-3.5-turbo",
messages=[
{"role": "system", "content": "You are a helpful assistant."},
{"role": "user", "content": prompt}
],
max_tokens=max_tokens,
temperature=temperature
)
return response['choices'][0]['message']['content'].strip()
# Example of listing engines
list_engines()
# Example prompt
prompt = "dialogue between batman and superman"
# Generate text using the selected engine
generated_text = generate_text(prompt)
generated_text = generated_text.split('\n\n')
print("Generated Text:")
print(generated_text)