Skip to content

Commit bde6709

Browse files
author
Piotr Stachaczynski
committed
rag finalize
1 parent cbf4483 commit bde6709

8 files changed

Lines changed: 191 additions & 25 deletions

File tree

Frontend/MainFE/Components/Pages/Rag/RAG.razor

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -176,8 +176,9 @@ else
176176

177177
private async Task InitRagAsync()
178178
{
179+
var filePath = ExtensionMethods.GetWorkingEnvironment() == "Docker" ? "wwwroot/initial_rag_demo_docker.json" : "wwwroot/initial_rag_demo.json";
179180
var agents = JsonSerializer.Deserialize<List<AgentDto>>(
180-
await File.ReadAllTextAsync("wwwroot/initial_rag_demo.json"), new JsonSerializerOptions()
181+
await File.ReadAllTextAsync(filePath), new JsonSerializerOptions()
181182
{
182183
PropertyNamingPolicy = JsonNamingPolicy.CamelCase
183184
});
@@ -197,6 +198,4 @@ else
197198
_selectedChat.Properties.Clear();
198199
_selectedChat.Messages = _selectedChat.Messages.Take(1).ToList();
199200
}
200-
201-
private string GetRoleLabel(string role) => role == Role.User.ToString() ? "User" : "\ud83d\udc7e Assistant";
202201
}
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
{
2+
"Logging": {
3+
"LogLevel": {
4+
"Default": "Information",
5+
"Microsoft.AspNetCore": "Warning"
6+
}
7+
}
8+
}
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
[
2+
{
3+
"id": "d2f191c7-f08b-4285-b0d6-bb99a045ebde",
4+
"name": "agent_one",
5+
"description": "This is the first RAG agent",
6+
"model": "gemma2:2b",
7+
"context":
8+
{
9+
"instruction": "You are shop assistant in a GeekITStuff store. You have to help the customer in finding the right product",
10+
"source":
11+
{
12+
"type": 1,
13+
"details":
14+
{
15+
"url": "http://demo:8080/items",
16+
"method": "Get",
17+
"query": "",
18+
"payload": ""
19+
}
20+
},
21+
"steps": ["FETCH_DATA*","ANSWER", "REDIRECT+f29211e9-9xe8-45f4-bdbb-054cb835d0d6+AS_Output+REPLACE"],
22+
"relations":
23+
[
24+
"ac243657-5ab1-4727-b4be-1ea5ae2e76d3",
25+
"f29211e9-9xe8-45f4-bdbb-054cb835d0d6"
26+
]
27+
}
28+
},
29+
{
30+
"id": "f29211e9-9xe8-45f4-bdbb-054cb835d0d6",
31+
"name": "agent_three",
32+
"description": "This is the third RAG agent",
33+
"model": "gemma2:2b",
34+
"context":
35+
{
36+
"instruction": "Adjust previous response to be better for marketing purposes. Dont include any introduction, just pure content",
37+
"steps": ["ANSWER"]
38+
}
39+
}
40+
]

docker-compose.yml

Lines changed: 16 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,7 @@ services:
99
- mongo-data:/data/db
1010

1111
backend:
12-
build:
13-
context: ./src
14-
dockerfile: ./Dockerfile
12+
image: inza124/main-backend:latest
1513
container_name: backend
1614
restart: always
1715
ports:
@@ -23,18 +21,29 @@ services:
2321
LocalHost: http://host.docker.internal
2422

2523
blazor:
26-
build:
27-
context: ./Frontend/MainFE
28-
dockerfile: ./Dockerfile
24+
image: inza124/main-blazor:latest
2925
container_name: blazor
3026
restart: always
3127
ports:
3228
- "5001:8080"
3329
depends_on:
3430
- backend
3531
environment:
36-
ASPNETCORE_ENVIRONMENT: Development
32+
ASPNETCORE_ENVIRONMENT: Docker
3733
API_URL: http://backend:8080
34+
DEMO_API_URL: http://demo:8080
35+
36+
demo:
37+
image: inza124/main-demo
38+
container_name: demo
39+
restart: always
40+
ports:
41+
- "5002:8080"
42+
depends_on:
43+
- blazor
44+
environment:
45+
ASPNETCORE_ENVIRONMENT: Docker
46+
LocalHost: http://host.docker.internal
3847

3948
volumes:
4049
mongo-data:

src/Dockerfile.demo

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
FROM mcr.microsoft.com/dotnet/sdk:8.0 AS build
2+
WORKDIR /app
3+
4+
COPY MaIN.RAG.Demo/*.csproj ./MaIN.RAG.Demo/
5+
6+
RUN dotnet restore ./MaIN.RAG.Demo/MaIN.RAG.Demo.csproj
7+
8+
COPY . ./
9+
RUN dotnet publish ./MaIN.RAG.Demo/MaIN.RAG.Demo.csproj -c Release -o /app/out
10+
11+
FROM mcr.microsoft.com/dotnet/aspnet:8.0 AS runtime
12+
WORKDIR /app
13+
COPY --from=build /app/out .
14+
ENTRYPOINT ["dotnet", "MaIN.RAG.Demo.dll"]

src/MaIN.Services/Services/OllamaService.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -45,8 +45,8 @@ public async Task<List<string>> GetCurrentModels()
4545
throw new Exception($"Failed to fetch models from Ollama, status code {response.StatusCode}");
4646
}
4747

48-
var result = JsonSerializer.Deserialize<ModelsOllamaResponse>(
49-
await response.Content.ReadAsStringAsync());
48+
var stringResponse = await response.Content.ReadAsStringAsync();
49+
var result = JsonSerializer.Deserialize<ModelsOllamaResponse>(stringResponse);
5050

5151
return result!.Models.Select(x => x.Name).ToList();
5252
}

start.ps1

Lines changed: 40 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,28 @@
1-
# Stop and remove Docker containers, networks, images, and volumes
2-
Write-Host "Stopping and removing Docker containers, networks, images, and volumes..."
3-
docker-compose down -v
1+
# Initialize variables
2+
$hard = $false
3+
$models = @()
4+
5+
# Manually parse the command-line arguments for double-dash parameters
6+
foreach ($arg in $args) {
7+
if ($arg -eq '--hard') {
8+
$hard = $true
9+
} elseif ($arg -like '--models=*') {
10+
# Extract the models from the argument
11+
$modelsString = $arg -replace '--models=', ''
12+
# Split the models string into an array, assuming comma-separated models
13+
$models = $modelsString -split ','
14+
}
15+
}
16+
17+
# Stop and remove Docker containers, networks, images (and volumes if --hard is provided)
18+
if ($hard) {
19+
Write-Host "Stopping and removing Docker containers, networks, images, and volumes..."
20+
docker-compose down -v
21+
} else {
22+
Write-Host "Stopping and removing Docker containers, networks, and images (volumes retained)..."
23+
docker-compose down
24+
}
25+
426
# Start Docker containers in detached mode
527
Write-Host "Starting Docker containers in detached mode..."
628
docker-compose up -d
@@ -9,25 +31,32 @@ docker-compose up -d
931
Write-Host "Waiting for 5 seconds to ensure the containers are up and running..."
1032
Start-Sleep -Seconds 5
1133

12-
1334
Write-Host "Running the Ollama serve."
1435
# Start-Job -ScriptBlock { ollama serve }
1536

1637
Start-Sleep -Seconds 15
1738

18-
# Read the .models file and pull each model, ignoring comments
19-
Write-Host "Reading .models file and pulling models..."
20-
$models = Get-Content ".models"
39+
# Determine models to pull: from parameter if provided, otherwise from file
40+
if ($models.Count -gt 0) {
41+
Write-Host "Using provided models list..."
42+
} else {
43+
Write-Host "No models provided as parameter, reading from .models file..."
44+
$models = Get-Content ".models"
45+
}
46+
47+
# Pull each model, ignoring comments if reading from file
2148
foreach ($model in $models) {
22-
# Ignore lines that are empty or start with '#'
23-
if ($model.Trim() -eq "" -or $model.Trim().StartsWith("#")) {
24-
continue
25-
}
49+
# Ignore lines that are empty or start with '#' if reading from file
50+
if ($model.Trim() -eq "" -or $model.Trim().StartsWith("#")) {
51+
continue
52+
}
53+
2654
Write-Host "Pulling model: $model"
2755
ollama pull $model
2856
}
2957

3058
Start-Sleep -Seconds 5
59+
3160
# Wait for all background jobs to complete
3261
Write-Host "Listening on http://localhost:5001 - happy travels"
3362
Get-Job | Wait-Job

start.sh

Lines changed: 69 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,70 @@
1-
docker compose up -d
1+
#!/bin/bash
2+
3+
# Initialize variables
4+
HARD=false
5+
MODELS=()
6+
7+
# Function to parse command-line arguments
8+
parse_args() {
9+
while [[ "$#" -gt 0 ]]; do
10+
case $1 in
11+
--hard) HARD=true ;;
12+
--models=*) IFS=',' read -r -a MODELS <<< "${1#*=}" ;;
13+
*) echo "Unknown parameter passed: $1"; exit 1 ;;
14+
esac
15+
shift
16+
done
17+
}
18+
19+
# Parse the command-line arguments
20+
parse_args "$@"
21+
22+
# Stop and remove Docker containers, networks, images (and volumes if --hard is provided)
23+
if [ "$HARD" = true ]; then
24+
echo "Stopping and removing Docker containers, networks, images, and volumes..."
25+
docker-compose down -v
26+
else
27+
echo "Stopping and removing Docker containers, networks, and images (volumes retained)..."
28+
docker-compose down
29+
fi
30+
31+
# Start Docker containers in detached mode
32+
echo "Starting Docker containers in detached mode..."
33+
docker-compose up -d
34+
35+
# Wait for 5 seconds to ensure the containers are up and running
36+
echo "Waiting for 5 seconds to ensure the containers are up and running..."
237
sleep 5
3-
docker compose exec ollama sh /root/.ollama/scripts/pull_gemma_2b.sh
38+
39+
echo "Running the Ollama serve..."
40+
# You may need to uncomment and adjust the following line depending on your setup
41+
# nohup ollama serve &
42+
43+
sleep 15
44+
45+
# Determine models to pull: from parameter if provided, otherwise from file
46+
if [ ${#MODELS[@]} -gt 0 ]; then
47+
echo "Using provided models list..."
48+
else
49+
echo "No models provided as parameter, reading from .models file..."
50+
if [ -f ".models" ]; then
51+
# Read the .models file into an array, ignoring comments and empty lines
52+
while IFS= read -r line || [ -n "$line" ]; do
53+
[[ "$line" =~ ^#.*$ ]] || [[ -z "$line" ]] && continue
54+
MODELS+=("$line")
55+
done < ".models"
56+
else
57+
echo ".models file not found."
58+
exit 1
59+
fi
60+
fi
61+
62+
# Pull each model
63+
for model in "${MODELS[@]}"; do
64+
echo "Pulling model: $model"
65+
ollama pull "$model"
66+
done
67+
68+
# Wait for all background jobs to complete
69+
echo "Listening on http://localhost:5001 - happy travels"
70+
wait

0 commit comments

Comments
 (0)