Skip to content

Commit c22221e

Browse files
committed
feat: setting embedding url and model in .env
1 parent 52c7296 commit c22221e

File tree

4 files changed

+28
-9
lines changed

4 files changed

+28
-9
lines changed

.env.example

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# OPENAI or OLLAMA
1+
# LLM OPENAI or OLLAMA
22
LLM_TYPE='OLLAMA'
33

44
OPENAI_MODEL='gpt-4o-mini'
@@ -7,4 +7,9 @@ OPENAI_API_KEY=''
77
OLLAMA_URL='http://localhost:11434'
88
OLLAMA_MODEL='gemma3:27b'
99

10+
# Embedding
11+
OLLAMA_EMBEDDING_URL='http://localhost:11434'
12+
OLLAMA_EMBEDDING_MODEL='llama3.1:70b-instruct-q2_K'
13+
14+
# Database
1015
DB_URL='postgresql://user:password@host:5432/database'

README-CH.md

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,15 +13,20 @@
1313
可以選擇 OpenAI 或 Ollama 作為 LLM,並設置所選擇 LLM 的環境變數。如果使用 OpenAI,則需要從 [OpenAI](https://platform.openai.com/) 獲取 API 金鑰(可能需要付費訂閱)。
1414

1515
```
16-
# OPENAI OLLAMA
16+
# LLM OPENAI or OLLAMA
1717
LLM_TYPE='OLLAMA'
1818
1919
OPENAI_MODEL='gpt-4o-mini'
2020
OPENAI_API_KEY=''
2121
2222
OLLAMA_URL='http://localhost:11434'
23-
OLLAMA_MODEL='llama3.1:70b-instruct-q2_K'
23+
OLLAMA_MODEL='gemma3:27b'
2424
25+
# Embedding
26+
OLLAMA_EMBEDDING_URL='http://localhost:11434'
27+
OLLAMA_EMBEDDING_MODEL='llama3.1:70b-instruct-q2_K'
28+
29+
# Database
2530
DB_URL='postgresql://user:password@host:5432/database'
2631
```
2732

README.md

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,15 +14,20 @@ Use LangChain to integrate with OpenAI or Ollama and connect to the database, en
1414
Able to choose OpenAI or Ollama as the LLM, and set the environment variables for the selected LLM. If using OpenAI, an API key must be obtained from [OpenAI](https://platform.openai.com/) (a paid subscription may be required).
1515

1616
```
17-
# OPENAI or OLLAMA
17+
# LLM OPENAI or OLLAMA
1818
LLM_TYPE='OLLAMA'
1919
2020
OPENAI_MODEL='gpt-4o-mini'
2121
OPENAI_API_KEY=''
2222
2323
OLLAMA_URL='http://localhost:11434'
24-
OLLAMA_MODEL='llama3.1:70b-instruct-q2_K'
24+
OLLAMA_MODEL='gemma3:27b'
2525
26+
# Embedding
27+
OLLAMA_EMBEDDING_URL='http://localhost:11434'
28+
OLLAMA_EMBEDDING_MODEL='llama3.1:70b-instruct-q2_K'
29+
30+
# Database
2631
DB_URL='postgresql://user:password@host:5432/database'
2732
```
2833

rag_util.py

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -20,12 +20,16 @@
2020
# 讀取 .env 變數
2121
load_dotenv()
2222

23-
2423
def get_vector_store():
2524
# embedding
26-
# TODO: 環境變數讀取
27-
OLLAMA_URL = os.getenv("OLLAMA_URL")
28-
embeddings = OllamaEmbeddings(model="llama3.1:70b-instruct-q2_K", base_url=OLLAMA_URL)
25+
OLLAMA_EMBEDDING_URL = os.getenv("OLLAMA_EMBEDDING_URL")
26+
if not OLLAMA_EMBEDDING_URL:
27+
raise Exception("未在 .env 檔案中找到 OLLAMA_EMBEDDING_URL。")
28+
OLLAMA_EMBEDDING_MODEL = os.getenv("OLLAMA_EMBEDDING_MODEL")
29+
if not OLLAMA_EMBEDDING_MODEL:
30+
raise Exception("未在 .env 檔案中找到 OLLAMA_EMBEDDING_MODEL。")
31+
32+
embeddings = OllamaEmbeddings(model=OLLAMA_EMBEDDING_MODEL, base_url=OLLAMA_EMBEDDING_URL)
2933

3034
vector_store = InMemoryVectorStore(embeddings)
3135

0 commit comments

Comments
 (0)