Spaces:
Sleeping
Sleeping
Update openai_client.py
Browse files10 unmodified lines11121314151617181920212223242526272829303 unmodified lines343536373839404142434445464748493 unmodified lines5354555657585960616266 unmodified lines12913013113213313413513613713813914014110 unmodified linesbase_url=os.getenv("https://api.aimlapi.com"),)# Function to get GPT-4o Mini responsedef get_code_review_response(prompt, max_tokens=1000):try:response = client.chat.completions.create(model="gpt-4o-mini",messages=[{"role": "system","content": "You are an AI assistant who helps users in code reviews by deep thinking in points max 5-6 point shortly.",},{"role": "user", "content": prompt},],max_tokens=max_tokens,)return response.choices[0].message.contentexcept Exception as e:3 unmodified lines# Function to refactor codedef refactor_code(code_snippet):try:response = client.chat.completions.create(model="gpt-4o-2024-08-06",messages=[{"role": "system","content": "You are an expert code refactoring assistant.",},{"role": "user","content": f"Refactor the following code. Do not provide any explanation or comments, just return the refactored code.\n{code_snippet}",},],)3 unmodified linesreturn "Sorry, an error occurred while refactoring your code. Please try again later."# Initialize the Anthropic clientanthropic_client = anthropic.Anthropic(api_key=os.getenv("ANTHROPIC_API_KEY"))# Function to get feedback on code using Anthropicdef code_feedback(code_snippet):try:66 unmodified lines# Function to remove code errorsdef remove_code_errors(code_snippet):try:response = client.chat.completions.create(model="gpt-4o-mini",messages=[{"role": "system","content": "You are an expert in debugging code. Provide concise suggestions to remove errors from the following code snippet.",},{"role": "user","content": f"Identify and suggest fixes for errors in the following code:\n{code_snippet}",10 unmodified lines1112131415161718192021222324252627282930313 unmodified lines353637383940414243444546473 unmodified lines51525354555666 unmodified lines12312412512612712812913013113210 unmodified linesbase_url=os.getenv("https://api.aimlapi.com"),)# Initialize the Anthropic clientanthropic_client = anthropic.Anthropic(api_key=os.getenv("ANTHROPIC_API_KEY"))# Function to get GPT-4o Mini responsedef get_code_review_response(prompt, max_tokens=1000):try:response = anthropic_client.messages.create(model="claude-3-5-sonnet-20240620",max_tokens=1024,messages=[{"role": "user","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}",},],)return response.choices[0].message.contentexcept Exception as e:3 unmodified lines# Function to refactor codedef refactor_code(code_snippet):try:response = anthropic_client.messages.create(model="claude-3-5-sonnet-20240620",max_tokens=1024,messages=[{"role": "user","content": f"Refactor the following code. Do not provide any explanation or comments, just return the refactored code:\n{code_snippet}",},],)3 unmodified linesreturn "Sorry, an error occurred while refactoring your code. Please try again later."# Function to get feedback on code using Anthropicdef code_feedback(code_snippet):try:66 unmodified lines# Function to remove code errorsdef remove_code_errors(code_snippet):try:response = anthropic_client.messages.create(model="claude-3-5-sonnet-20240620",max_tokens=1024,messages=[{"role": "user","content": f"Identify and suggest fixes for errors in the following code:\n{code_snippet}",
openai_client.py+14-23