Skip to content

Commit

Permalink
Merge branch 'main' of https://github.com/ShinChven/git-gpt
Browse files Browse the repository at this point in the history
  • Loading branch information
ShinChven committed Dec 29, 2023
2 parents 4cabf21 + 31be23e commit e65b285
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 10 deletions.
2 changes: 1 addition & 1 deletion git_gpt/__init__.py
Original file line number Diff line number Diff line change
@@ -1 +1 @@
__version__ = '0.1.4'
__version__ = '0.2.1'
21 changes: 12 additions & 9 deletions git_gpt/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

import click
import git
import openai
from openai import OpenAI

from git_gpt import __version__

Expand Down Expand Up @@ -81,9 +81,9 @@ def commit(lang, model, run_dry):
repo.git.add('--all')
diffs = repo.git.diff('--staged') # Get textual representation of staged diffs

openai.api_key = config['api_key']
if 'base' in config:
openai.api_base = f"{config['base']}/v1"
base_url = config.get('base', 'https://api.openai.com')

client = OpenAI(api_key=config['api_key'], base_url=f"{base_url}/v1")

# print loading animation
click.echo(f"Generating commit message with {model} in {lang}...")
Expand All @@ -97,7 +97,7 @@ def commit(lang, model, run_dry):
# replace [insert_language] with the target language
prompt = prompt.replace('[insert_language]', lang)

response = openai.ChatCompletion.create(
response = client.chat.completions.create(
model=model,
messages=[
{"role": "system", "content": f"You are a copilot programmer."},
Expand All @@ -108,6 +108,7 @@ def commit(lang, model, run_dry):
stop=None
)

response = json.loads(response.model_dump_json())
commit_message = response['choices'][0]['message']['content'].strip()

if run_dry:
Expand Down Expand Up @@ -164,14 +165,13 @@ def issue(lang, model, max_tokens, commit_range):
# if max tokens is not provided, use the default value
max_tokens = max_tokens or config.get('issue_max_tokens', 1000)

openai.api_key = config['api_key']
if 'base' in config:
openai.api_base = f"{config['base']}/v1"
base_url = config.get('base', 'https://api.openai.com')
client = OpenAI(api_key=config['api_key'], base_url=f"{base_url}/v1")

# print loading animation
click.echo(f"Generating issue using {model} in {lang}...")

response = openai.ChatCompletion.create(
response = client.chat.completions.create(
model=model,
messages=[
{"role": "system", "content": f"You are a copilot programmer."},
Expand All @@ -181,6 +181,9 @@ def issue(lang, model, max_tokens, commit_range):
stop=None
)

response = json.loads(response.model_dump_json())
commit_message = response['choices'][0]['message']['content'].strip()

issue = response['choices'][0]['message']['content'].strip()

click.echo(f"Issue created successfully:\n\n{issue}")
Expand Down

0 comments on commit e65b285

Please sign in to comment.