Skip to content

Instantly share code, notes, and snippets.

@laurentperrinet
Last active March 16, 2023 16:12
Show Gist options
  • Save laurentperrinet/94fbcc0dab15736cd66c9ffc669b625b to your computer and use it in GitHub Desktop.
Save laurentperrinet/94fbcc0dab15736cd66c9ffc669b625b to your computer and use it in GitHub Desktop.
#!/usr/bin/env python
# https://gist.github.com/laurentperrinet/94fbcc0dab15736cd66c9ffc669b625b
# install the API using `conda install openai` (MMV)
# setup your API key by including `export OPENAI_API_KEY="sk-xxxxxyyyyyyyzzzz"` in your `.zshrc` (MMV)
import argparse
parser = argparse.ArgumentParser(description='A simple CLI for chat-GPT with my prefered settings')
parser.add_argument('prompt', help="A useful prompt.", default='Demonstrate that the earth is flat.', type=str)
parser.add_argument("--max_tokens", help="Set the maximum tokens number", default=1000, type=int)
parser.add_argument("--temperature", help="Set the temperature", default=.5, type=float)
parser.add_argument("--model_engine", help = "Model engine used.", default="gpt-3.5-turbo", type=str)
args = parser.parse_args()
# print("> prompt: ", args.prompt)
import openai
# Generate a response
completion = openai.ChatCompletion.create(
model=args.model_engine,
messages=[
{"role": "system", "content": "You are a helpful assistant."},
{"role": "user", "content": args.prompt},
],
max_tokens=args.max_tokens,
temperature=args.temperature,
# top_p=1,
# frequency_penalty=0,
# presence_penalty=0
)
# Print the response
print("> Response", completion.choices[0]['message']['content'])
@laurentperrinet
Copy link
Author

outputs

It is impossible to demonstrate that the Earth is flat, as it is a scientifically-proven fact that the Earth is a sphere.

on my machine.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment