CodeLlama - Code Infilling

CodeLlama - Code Infilling

이 튜토리얼은 Huggingface PRO Inference Endpoints에 호스팅된 CodeLlama를 호출해 코드를 채우는(fill) 방법을 보여줍니다.

이것은 코드 모델에 특화된 작업이에요. 모델은 기존 접두사(prefix)와 접미사(suffix)에 가장 잘 맞는 코드(주석 포함)를 생성하도록 학습됩니다. 이 작업은 7B13B CodeLlama 모델의 base 변형과 instruction 변형에서 사용할 수 있어요. 34B 모델이나 Python 버전에서는 사용할 수 없습니다.

출처: 문서

본문

사용법

import osfrom litellm import longer_context_model_fallback_dict, ContextWindowExceededError, completionos.environ["HUGGINGFACE_API_KEY"] = "your-hf-token" # https://huggingface.co/docs/hub/security-tokens## CREATE THE PROMPTprompt_prefix = 'def remove_non_ascii(s: str) -> str:\n    """ 'prompt_suffix = "\n    return result"### set

  to indicate the string before and after the part you want codellama to fill prompt = f" {prompt_prefix} {prompt_suffix} "messages = [{"content": prompt, "role": "user"}]model = "huggingface/codellama/CodeLlama-34b-Instruct-hf" # specify huggingface as the provider 'huggingface/'response = completion(model=model, messages=messages, max_tokens=500)

출력

def remove_non_ascii(s: str) -> str:    """ Remove non-ASCII characters from a string.    Args:        s (str): The string to remove non-ASCII characters from.    Returns:        str: The string with non-ASCII characters removed.    """    result = ""    for c in s:        if ord(c)

더 알아보기 (Learn more)