Skip to content

Commit

Permalink
さらに小型のモデルに変更、環境変数に切り出し
Browse files Browse the repository at this point in the history
  • Loading branch information
yuiseki committed Nov 2, 2024
1 parent a816cd7 commit 3e9191b
Show file tree
Hide file tree
Showing 7 changed files with 30 additions and 10 deletions.
6 changes: 5 additions & 1 deletion .env.example
Original file line number Diff line number Diff line change
@@ -1,2 +1,6 @@
OPENAI_API_KEY=
CLOUDFLARE_AI_GATEWAY=
CLOUDFLARE_AI_GATEWAY=
OLLAMA_BASE_URL=http://localhost:11434
OLLAMA_CHAT_MODEL=smollm:135m
OLLAMA_EMBED_MODEL=all-minilm:l6-v2
OLLAMA_ENABLED=true
6 changes: 6 additions & 0 deletions .env.test
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
OPENAI_API_KEY=
CLOUDFLARE_AI_GATEWAY=
OLLAMA_BASE_URL=http://localhost:11434
OLLAMA_CHAT_MODEL=smollm:135m
OLLAMA_EMBED_MODEL=all-minilm:l6-v2
OLLAMA_ENABLED=true
4 changes: 2 additions & 2 deletions .github/workflows/test-with-ollama.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,12 @@ jobs:
- uses: actions/checkout@v4
with:
fetch-depth: 1
- name: Run Ollama Docker image and pull models
- name: Launch Ollama Docker image and pull models
run: |
mkdir -p ~/.ollama/models
docker run -d -v ollama:/home/runner/.ollama -p 11434:11434 --name ollama ollama/ollama
sleep 20
docker exec ollama ollama pull gemma2:2b
docker exec ollama ollama pull smollm:135m
docker exec ollama ollama pull all-minilm:l6-v2
sleep 20
time curl -i http://localhost:11434
Expand Down
2 changes: 1 addition & 1 deletion scripts/agent.ts
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ let llm;
if (process.env.OLLAMA_BASE_URL && process.env.OLLAMA_ENABLED === "true") {
llm = new ChatOllama({
baseUrl: process.env.OLLAMA_BASE_URL,
model: process.env.OLLAMA_MODEL,
model: process.env.OLLAMA_CHAT_MODEL,
temperature: 0.0,
});
} else {
Expand Down
4 changes: 2 additions & 2 deletions scripts/instruct.ts
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,7 @@ const setupCharitesAiDynamicPrompt = async (
if (process.env.OLLAMA_BASE_URL && process.env.OLLAMA_ENABLED === "true") {
embeddings = new OllamaEmbeddings({
baseUrl: process.env.OLLAMA_BASE_URL,
model: "all-minilm:l6-v2",
model: process.env.OLLAMA_EMBED_MODEL,
});
} else {
if (!process.env.OPENAI_API_KEY) {
Expand Down Expand Up @@ -341,7 +341,7 @@ export const initializeCharitesAiChain = async (): Promise<
if (process.env.OLLAMA_BASE_URL && process.env.OLLAMA_ENABLED === "true") {
llm = new ChatOllama({
baseUrl: process.env.OLLAMA_BASE_URL,
model: process.env.OLLAMA_MODEL,
model: process.env.OLLAMA_CHAT_MODEL,
temperature: 0.0,
});
} else {
Expand Down
9 changes: 7 additions & 2 deletions test/ollamaEmbeddings.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,15 @@ import { MemoryVectorStore } from "langchain/vectorstores/memory";
import type { Document } from "@langchain/core/documents";
import { expect, test } from "vitest";

// process.env を .env.test から読み込む
import process from "node:process";
import { config } from "dotenv";
config({ path: ".env.test" });

test("ollama embedding", async () => {
const embeddings = new OllamaEmbeddings({
baseUrl: "http://localhost:11434",
model: "all-minilm:l6-v2",
baseUrl: process.env.OLLAMA_BASE_URL,
model: process.env.OLLAMA_EMBED_MODEL,
});

const vectorStore = new MemoryVectorStore(embeddings);
Expand Down
9 changes: 7 additions & 2 deletions test/ollamaInvoke.test.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,15 @@
import { Ollama } from "@langchain/ollama";
import { expect, test } from "vitest";

// process.env を .env.test から読み込む
import process from "node:process";
import { config } from "dotenv";
config({ path: ".env.test" });

test("ollama invoke", async () => {
const llm = new Ollama({
baseUrl: "http://localhost:11434",
model: "gemma2:2b",
baseUrl: process.env.OLLAMA_BASE_URL,
model: process.env.OLLAMA_CHAT_MODEL,
temperature: 0.0,
});

Expand Down

0 comments on commit 3e9191b

Please sign in to comment.