harris1 commited on
Commit
3ac9eaa
1 Parent(s): 738cfd2

Update openai_client.py

Browse files
Files changed (1) hide show
  1. openai_client.py +14 -23
openai_client.py CHANGED
@@ -11,20 +11,21 @@ client = OpenAI(
11
  base_url=os.getenv("https://api.aimlapi.com"),
12
  )
13
 
 
 
14
 
15
  # Function to get GPT-4o Mini response
16
  def get_code_review_response(prompt, max_tokens=1000):
17
  try:
18
- response = client.chat.completions.create(
19
- model="gpt-4o-mini",
 
20
  messages=[
21
  {
22
- "role": "system",
23
- "content": "You are an AI assistant who helps users in code reviews by deep thinking in points max 5-6 point shortly.",
24
  },
25
- {"role": "user", "content": prompt},
26
  ],
27
- max_tokens=max_tokens,
28
  )
29
  return response.choices[0].message.content
30
  except Exception as e:
@@ -34,16 +35,13 @@ def get_code_review_response(prompt, max_tokens=1000):
34
  # Function to refactor code
35
  def refactor_code(code_snippet):
36
  try:
37
- response = client.chat.completions.create(
38
- model="gpt-4o-2024-08-06",
 
39
  messages=[
40
- {
41
- "role": "system",
42
- "content": "You are an expert code refactoring assistant.",
43
- },
44
  {
45
  "role": "user",
46
- "content": f"Refactor the following code. Do not provide any explanation or comments, just return the refactored code.\n{code_snippet}",
47
  },
48
  ],
49
  )
@@ -53,10 +51,6 @@ def refactor_code(code_snippet):
53
  return "Sorry, an error occurred while refactoring your code. Please try again later."
54
 
55
 
56
- # Initialize the Anthropic client
57
- anthropic_client = anthropic.Anthropic(api_key=os.getenv("ANTHROPIC_API_KEY"))
58
-
59
-
60
  # Function to get feedback on code using Anthropic
61
  def code_feedback(code_snippet):
62
  try:
@@ -129,13 +123,10 @@ def suggest_best_practices(code_snippet):
129
  # Function to remove code errors
130
  def remove_code_errors(code_snippet):
131
  try:
132
- response = client.chat.completions.create(
133
- model="gpt-4o-mini",
 
134
  messages=[
135
- {
136
- "role": "system",
137
- "content": "You are an expert in debugging code. Provide concise suggestions to remove errors from the following code snippet.",
138
- },
139
  {
140
  "role": "user",
141
  "content": f"Identify and suggest fixes for errors in the following code:\n{code_snippet}",
 
11
  base_url=os.getenv("https://api.aimlapi.com"),
12
  )
13
 
14
+ # Initialize the Anthropic client
15
+ anthropic_client = anthropic.Anthropic(api_key=os.getenv("ANTHROPIC_API_KEY"))
16
 
17
  # Function to get GPT-4o Mini response
18
  def get_code_review_response(prompt, max_tokens=1000):
19
  try:
20
+ response = anthropic_client.messages.create(
21
+ model="claude-3-5-sonnet-20240620",
22
+ max_tokens=1024,
23
  messages=[
24
  {
25
+ "role": "user",
26
+ "content": f"You are an AI assistant who helps users in code reviews by deep thinking in points max 5-6 point shortly:\n{prompt}",
27
  },
 
28
  ],
 
29
  )
30
  return response.choices[0].message.content
31
  except Exception as e:
 
35
  # Function to refactor code
36
  def refactor_code(code_snippet):
37
  try:
38
+ response = anthropic_client.messages.create(
39
+ model="claude-3-5-sonnet-20240620",
40
+ max_tokens=1024,
41
  messages=[
 
 
 
 
42
  {
43
  "role": "user",
44
+ "content": f"Refactor the following code. Do not provide any explanation or comments, just return the refactored code:\n{code_snippet}",
45
  },
46
  ],
47
  )
 
51
  return "Sorry, an error occurred while refactoring your code. Please try again later."
52
 
53
 
 
 
 
 
54
  # Function to get feedback on code using Anthropic
55
  def code_feedback(code_snippet):
56
  try:
 
123
  # Function to remove code errors
124
  def remove_code_errors(code_snippet):
125
  try:
126
+ response = anthropic_client.messages.create(
127
+ model="claude-3-5-sonnet-20240620",
128
+ max_tokens=1024,
129
  messages=[
 
 
 
 
130
  {
131
  "role": "user",
132
  "content": f"Identify and suggest fixes for errors in the following code:\n{code_snippet}",