# DiscourseAI를 위한 오픈소스 LLM 셀프호스팅

**URL:** https://meta.discourse.org/t/self-hosting-an-opensource-llm-for-discourseai/290923
**Category:** Self-Hosting
**Tags:** ai
**Created:** [1월 8, 2024, 8:39오후 UTC](https://meta.discourse.org/t/self-hosting-an-opensource-llm-for-discourseai/290923 "2024-01-08T20:39:55Z")
**Posts on this page:** 1
**Showing post:** 1

<div class="post-metadata">

### Author: ![Discourse](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/discourse/32/148734_2.png) [@Discourse](https://meta.discourse.org/u/Discourse)
#### Post date: [1월 8, 2024, 8:39오후 UTC](https://meta.discourse.org/t/self-hosting-an-opensource-llm-for-discourseai/290923/1 "2024-01-08T20:39:55Z")

</div>

[Discourse AI](https://meta.discourse.org/t/discourse-ai/259214) 플러그인은 요약, AI 헬퍼, AI 검색, AI 봇과 같이 LLM이 활성화되어야 하는 여러 기능을 제공합니다. [OpenAI API 키 설정](https://meta.discourse.org/t/configure-api-keys-for-openai/280783)이나 [Anthropic API 키 설정](https://meta.discourse.org/t/configure-api-keys-for-anthropic/280936)과 같은 제3자 API를 사용할 수는 있지만, Discourse AI는 처음부터 이러한 서비스에 종속되지 않도록 설계되었습니다.

### HuggingFace TGI로 실행하기

HuggingFace는 빠르게 실행 환경을 구축할 수 있는 훌륭한 컨테이너 이미지를 제공합니다.

예를 들어:

```plaintext
mkdir -p /opt/tgi-cache
docker run --rm --gpus all --shm-size 1g -p 8080:80 \
  -v /opt/tgi-cache:/data \
  ghcr.io/huggingface/text-generation-inference:latest \
  --model-id mistralai/Mistral-7B-Instruct-v0.2

```

이 명령어를 실행하면 로컬호스트의 포트 8080에서 Mistral 7B Instruct의 로컬 인스턴스가 실행되며, 다음으로 테스트할 수 있습니다.

```bash
curl http://localhost:8080/ \
    -X POST \
    -H 'Content-Type: application/json' \
    -d '{"inputs":"<s>[INST] What is your favourite condiment? [/INST] Well, I'm quite partial to a good squeeze of fresh lemon juice. It adds just the right amount of zesty flavour to whatever I'm cooking up in the kitchen!</s> [INST] Do you have mayonnaise recipes? [/INST]","parameters":{"max_new_tokens":500, "temperature":0.5,"top_p": 0.9}}'

```

### vLLM으로 실행하기

Discourse AI가 지원하는 LLM 자체 호스팅의 또 다른 옵션은 vLLM입니다. vLLM은 Apache 라이선스 하에 제공되는 매우 인기 있는 프로젝트입니다.

모델로 시작하는 방법은 다음과 같습니다:

```plaintext
mkdir -p /opt/vllm-cache
docker run --gpus all \
  -v /opt/vllm-cache:/root/.cache/huggingface \
  -e "MODEL=mistralai/Mistral-7B-Instruct-v0.2" \
  -p 8080:8000 --ipc=host vllm/vllm-openai:latest

```

다음으로 테스트할 수 있습니다.

```bash
curl -X POST http://localhost:8080/v1/completions \
-H "Content-Type: application/json" \
-d '{
"model": "mistralai/Mistral-7B-Instruct-v0.2",
"prompt": "<s> [INST] What was the latest released hero for Dota 2? [/INST] The latest released hero for Dota 2 was", "max_tokens": 200}'

```

### Ollama로 실행하기

[Ollama](https://ollama.com)는 오픈소스 모델을 로컬에서 실행하기 위한 또 다른 인기 있는 옵션입니다. 모델 관리를 단순화하고 OpenAI 호환 API를 제공합니다.

```plaintext
ollama pull mistral
ollama serve

```

이것은 `http://localhost:11434`에서 로컬 서버를 시작하며, Discourse AI는 **Ollama** 제공자를 사용하여 이 서버에 연결할 수 있습니다.

### Discourse 인스턴스에서 사용 가능하게 만들기

GPU 요구 사항으로 인해 대부분 이 서비스를 전용 서버에서 실행하게 됩니다. 이렇게 할 경우, 리버스 프록시를 실행하고 TLS 종단을 처리하며, 해당 엔드포인트가 Discourse 인스턴스에 의해만 연결되도록 보안 설정을 하는 것을 권장합니다.

### Discourse AI 설정

LLM 연결은 이제 사이트 설정이 아닌 관리자 UI를 통해 구성됩니다. `/admin/plugins/discourse-ai/ai-llms`로 이동하여 새 LLM을 추가하세요:

1. 모델을 추가하려면 **New** (새로 만들기)를 클릭합니다.
2. **Provider** (제공자)를 선택합니다 — 추론 서버에 따라 **vLLM** , **Hugging Face** , 또는 **Ollama** 중 하나를 선택합니다.
3. 추론 엔드포인트의 **URL** 을 입력합니다 (예: `http://your-server:8080`).
4. 엔드포인트가 API 키를 요구하는 경우 **API key** (API 키)를 입력합니다.
5. **model name** (모델 이름), **tokenizer** (토크나이저), **max prompt tokens** (최대 프롬프트 토큰 수) 및 기타 모델 세부 정보를 입력합니다.

LLM이 추가되면 **ai\_default\_llm\_model** 사이트 설정을 통해 기본값으로 설정하거나, `/admin/plugins/discourse-ai/ai-features`의 에이전트 구성을 통해 특정 기능에 할당할 수 있습니다.

---

_[View the full topic](https://meta.discourse.org/t/self-hosting-an-opensource-llm-for-discourseai/290923)._
