Last active
March 16, 2023 16:12
-
-
Save laurentperrinet/94fbcc0dab15736cd66c9ffc669b625b to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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']) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
outputs
on my machine.