Banana는 AI 모델을 위한 serverless GPU inference, CI/CD build pipeline, 그리고 모델을 서빙하기 위한 간단한 Python framework (Potassium)를 제공합니다.
이 페이지에서는 LangChain 내에서 Banana 생태계를 사용하는 방법을 다룹니다.

Installation and Setup

  • Python 패키지 banana-dev 설치:
pip install banana-dev
  • Banana.dev dashboard에서 Banana API key를 발급받아 환경 변수(BANANA_API_KEY)로 설정하세요
  • 모델 상세 페이지에서 model key와 url slug를 확인하세요.

Define your Banana Template

Banana 앱을 위해 GitHub repo를 설정해야 합니다. 이 가이드를 사용하면 5분 내로 시작할 수 있습니다. 또는, 바로 사용 가능한 LLM 예시로 Banana의 CodeLlama-7B-Instruct-GPTQ GitHub 저장소를 확인해 보세요. 포크한 뒤 Banana에 배포하면 됩니다. 다른 시작용 리포지토리는 여기에서 확인할 수 있습니다.

Build the Banana app

LangChain에서 Banana 앱을 사용하려면 반환되는 json에 outputs 키가 포함되어야 하며, 해당 값은 문자열이어야 합니다.
# Return the results as a dictionary
result = {'outputs': result}
추론 함수 예시는 다음과 같습니다:
@app.handler("/")
def handler(context: dict, request: Request) -> Response:
    """Handle a request to generate code from a prompt."""
    model = context.get("model")
    tokenizer = context.get("tokenizer")
    max_new_tokens = request.json.get("max_new_tokens", 512)
    temperature = request.json.get("temperature", 0.7)
    prompt = request.json.get("prompt")
    prompt_template=f'''[INST] Write code to solve the following coding problem that obeys the constraints and passes the example test cases. Please wrap your code answer using ```:
```python
# 프롬프트 템플릿 일부
    {prompt}
    [/INST]
    '''
    # 입력을 토크나이즈하고 GPU로 이동
    input_ids = tokenizer(prompt_template, return_tensors='pt').input_ids.cuda()
    # 모델에서 텍스트를 생성 (temperature와 max_new_tokens 설정)
    output = model.generate(inputs=input_ids, temperature=temperature, max_new_tokens=max_new_tokens)
    # 토큰을 텍스트로 디코드
    result = tokenizer.decode(output[0])
    # Banana는 outputs 키의 문자열 값을 기대하므로 해당 형태로 응답
    return Response(json={"outputs": result}, status=200)

This example is from the `app.py` file in [CodeLlama-7B-Instruct-GPTQ](https://github.com/bananaml/demo-codellama-7b-instruct-gptq).


## LLM


```python
```python
# LangChain 커뮤니티 Banana LLM import
from langchain_community.llms import Banana
사용 예시를 참고하세요.
Connect these docs programmatically to Claude, VSCode, and more via MCP for real-time answers.
I