김수진 강사님
GPT-35-Turbo 및 GPT-4 모델은 코드와 언어를 함께 이해하고 생성하며, 간단한 명령어부터 복잡한 응요 프로그램 코드까지 작성 가능.
자연어 프롬프트로 요청하면 다양한 프로그래밍 언어로 정확하고 기능적인 함수 코드를 작성.
Python, JavaScript, C#, Java 등 다양한 언어를 지원하며 코드 변환 기능도 포함.
특정 언어로 작성된 코드를 다른 언어로 자동 변환하며, 문법과 기능 구현 차이를 반영.
익숙하지 않은 언어나 복잡한 로직을 분석해 간결하게 풀이하고, 기능 요약 제공.
부분 코드 완료: 코드 문맥을 기반으로 작성.
단위 테스트 생성: 자동으로 테스트 케이스 작성.
주석 및 설명서 생성: 가독성 및 유지보수성을 높이기 위해 설명 추가.
버그 수정: 코드 분석 및 수정 제안.
개발 속도 향상: 반복 작업 최소화.
코드 품질 개선: 유지보수성과 협업 효율성 증대.
충분한 컨텍스트가 없는 경우 정확도가 떨어질 수 있음.
부분 코드 작성과 테스트 생성 기능을 통합해 전체 개발 프로세스 자동화 기능.
주석 추가: 코드의 목적, 매개변수, 반환값 설명.
설명서 생성: 코드의 로직과 사용법을 정리.
가독성과 유지보수성을 향상시키고, 문서화 시간을 절약.
복잡한 코드는 수동 검토 및 추가 작업 필요.
버그 수정: 오류 탐지 및 수정 제안.
코드 개선: 성능 최적화와 가독성 개선.
문제 해결 속도와 코드 품질 향상.
복잡한 오류는 수동 검토와 추가 작업 필요.
중복 제거, 성능 최적화, 가독성 향상, 코드 구조 개선.
import os
from dotenv import load_dotenv
# Add Azure OpenAI package
from openai import AzureOpenAI
os.chdir(os.path.dirname(__file__))
# Set to True to print the full response from OpenAI for each call
printFullResponse = False
def main():
try:
# Get configuration settings
load_dotenv()
azure_oai_endpoint = os.getenv("AZURE_OAI_ENDPOINT")
azure_oai_key = os.getenv("AZURE_OAI_KEY")
azure_oai_deployment = os.getenv("AZURE_OAI_DEPLOYMENT")
# Configure the Azure OpenAI client
client = AzureOpenAI(
azure_endpoint = azure_oai_endpoint,
api_key=azure_oai_key,
api_version="2024-08-01-preview"
)
while True:
print('\n1: Add comments to my function\n' +
'2: Write unit tests for my function\n' +
'3: Fix my Go Fish game\n' +
'4: Refactor and optimise code\n' +
'\"quit\" to exit the program\n')
command = input('Enter a number to select a task:')
if command.lower() == 'quit':
print('Exiting program...')
break
user_input = input('\nEnter a prompt: ')
if command == '1' or command == '2':
file = open(file="../sample-code/function/function.py", encoding="utf8").read()
elif command =='3':
file = open(file="../sample-code/go-fish/go-fish.py", encoding="utf8").read()
elif command =='4':
file = open(file="../sample-code/refactor/refactor.py", encoding="utf8").read()
else :
print("Invalid input. Please try again.")
continue
prompt = user_input + file
call_openai_model(prompt, model=azure_oai_deployment, client=client)
except Exception as ex:
print(ex)
def call_openai_model(prompt, model, client):
# Provide a basic user message, and use the prompt content as the user message
system_message = "You are a helpful AI assistant that helps programmers write code."
user_message = prompt
# Format and send the request to the model
messages = [
{"role": "system", "content": system_message},
{"role": "user", "content": user_message}
]
# Call the Azure OpenAI model
response = client.chat.completions.create(
model=model,
messages=messages,
temperature=0.7,
max_tokens=1000
)
# Print the response to the console, if desired
if printFullResponse:
print(response)
# Write the response to a file
results_file = open(file="result/app.txt", mode="w", encoding="utf8")
results_file.write(response.choices[0].message.content)
print("\nResponse written to result/app.txt\n\n")
if __name__ == '__main__':
main()
DALL-E는 OpenAI에서 개발한 신경망 기반 모델로, 자연어 입력을 바탕으로 이미지를 생성하는 AI이다. 사용자가 원하는 이미지의 설명을 입력하면, DALL-E는 해당 설명에 부합하는 독창적인 그래픽을 생성한다. (출처: ChatGPT)
Requests는 Python에서 HTTP 요청을 손쉽게 처리할 수 있도록 설계된 강력하고 사용하기 쉬운 라이브러리이다. 주로 웹 크롤링, API 호출, 데이터 통신 등에 사용된다. (출처: ChatGPT)
a. HTTP 메서드 지원
- 다양한 HTTP 메서드를 지원: GET
, POST
, PUT
, DELETE
등.
- 간단한 함수 호출로 요청을 보낼 수 있음.
b. JSON 데이터 처리: JSON 데이터를 간단히 요청하거나 응답을 파싱할 수 있음.
c. 인증 및 보안: 다양한 인증 방식 지원 - Basic/Digest 인증, OAuth1, OAuth2 등.
d. 세션 유지: 세션 객체를 사용해 로그인 상태나 쿠키를 유지하며 여러 요청을 보낼 수 있음.
e. 간단한 파일 업로드 및 다운로드