Skip to content

Commit

Permalink
Merge pull request #17 from ChaoticRoman/update-to-openai-api-1.1.1
Browse files Browse the repository at this point in the history
Update core to openAI python lib v1.1.1.
  • Loading branch information
ChaoticRoman authored Nov 9, 2023
2 parents bac9c20 + 09eb496 commit d4bb7ea
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 10 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/code-review.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ jobs:
pull-requests: write
steps:
- uses: actions/checkout@v3
- uses: sshnaidm/gpt-code-review-action@v1.0
- uses: sshnaidm/gpt-code-review-action@v2.0
with:
model: 'gpt-4'
openai-key: ${{ secrets.OPENAI_API_KEY }}
Expand Down
15 changes: 9 additions & 6 deletions core.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,10 @@
MODEL = "gpt-4"
TEMPERATURE = 0.0

api_key_path = os.path.join(os.path.dirname(__file__), '.api_key')
with open(api_key_path, 'r') as f:
openai.api_key = f.read().strip()
if 'OPENAI_API_KEY' not in os.environ:
api_key_path = os.path.join(os.path.dirname(__file__), '.api_key')
with open(api_key_path, 'r') as f:
os.environ['OPENAI_API_KEY'] = f.read().strip()


class GptCore:
Expand All @@ -34,18 +35,20 @@ def __init__(self, input, output):

self.messages = []

self.client = openai.OpenAI()

def main(self):
price = 0
while prompt := self.input():
self.messages.append({"role": "user", "content": prompt})

response = openai.ChatCompletion.create(
response = self.client.chat.completions.create(
model=MODEL, messages=self.messages, temperature=TEMPERATURE)

message = response.choices[0]["message"]
message = response.choices[0].message
self.messages.append(message)

content = message["content"].strip()
content = message.content.strip()

usage = response.usage
prompt_tokens, completion_tokens = (
Expand Down
6 changes: 3 additions & 3 deletions test.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
os.chdir(os.path.dirname(__file__))

with open('.api_key', 'r') as f:
openai.api_key = f.read().strip()
client = openai.OpenAI(api_key=f.read().strip())

prompt = " ".join(sys.argv[1:])

Expand All @@ -23,7 +23,7 @@
# ... And model would proceed with "Orange who?"
]

response = openai.ChatCompletion.create(
response = client.chat.completions.create(
model=MODEL, messages=messages, temperature=0.1)

print(response.choices[0]["message"]["content"].strip())
print(response.choices[0].message.content.strip())

0 comments on commit d4bb7ea

Please sign in to comment.