Skip to content

Commit 54b822d

Browse files
Merge pull request #1 from wisedev-code/feat/implement_RAG_demo
Feat/implement rag demo
2 parents ac1f2d7 + bde6709 commit 54b822d

111 files changed

Lines changed: 3333 additions & 294 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

.models

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
1-
gemma:2b
2-
llama3:8b
1+
gemma2:2b
2+
llama3.1:8b
3+
phi3:mini
4+
5+
#Place any new model here and it will be downloaded during start command
36

4-
#Place any new model here and it will be downloaded during start command

Docs/Images/temp/example.json

Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
{
2+
"id": "d2f191c7-f08b-4285-b0d6-bb99a045ebde",
3+
"name": "agent_one",
4+
"description": "This is the first RAG agent",
5+
"model": "gemma:2b",
6+
"context":
7+
{
8+
"instruction": "You are shop assistant in a GeekITStuff store. You have to help the customer in finding the right product",
9+
"source":
10+
{
11+
"type": "api", //can be api/sql/text/file as we know it now
12+
"details":
13+
{
14+
"url": "https://api.example.com/@filter@",
15+
"method": "GET",
16+
"query": "",
17+
"payload": ""
18+
//In future we will also have to add authentication details
19+
}
20+
},
21+
"steps": ["ANSWER"],
22+
//"steps": ["REDIRECT_ac243657-5ab1-4727-b4be-1ea5ae2e76d3", "FETCH_DATA_WITH_FILTER", "ANSWER", "REDIRECT_b29211e9-9ee8-45f4-bdbb-054cb835d0d6"],
23+
"relations": //connections that this agent can make to other agents
24+
[
25+
{
26+
"id": "ac243657-5ab1-4727-b4be-1ea5ae2e76d3",
27+
"agentPurpose": "category detection",
28+
},
29+
{
30+
"id": "b29211e9-9ee8-45f4-bdbb-054cb835d0d6",
31+
"agentPurpose": "output prettifier",
32+
}
33+
]
34+
}
35+
}
36+
37+
{
38+
"id": "ac243657-5ab1-4727-b4be-1ea5ae2e76d3",
39+
"name": "agent_two",
40+
"description": "This is the second RAG agent",
41+
"model": "gemma:2b",
42+
"context":
43+
{
44+
"instruction": "Identify correct category for question: Available are PC, LAPTOP, ACCESSORIES - Its important to respond with single word",
45+
"steps": ["ANSWER"],
46+
}
47+
}
48+
49+
{
50+
"id": "b29211e9-9ee8-45f4-bdbb-054cb835d0d6",
51+
"name": "agent_three",
52+
"description": "This is the third RAG agent",
53+
"model": "gemma:2b",
54+
"context":
55+
{
56+
"instruction": "Your role is to prettify the response for the user to understand better",
57+
"steps": ["ANSWER"],
58+
}
59+
}

Docs/Images/temp/response.json

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
{
2+
"id": "a0353d9d-2dfb-4663-91a4-987a20c9aba1",
3+
"name": "agent_one",
4+
"model": "gemma:2b",
5+
"messages": [
6+
{
7+
"role": "system",
8+
"content": "You are shop assistant in a GeekITStuff store. You have to help the customer in finding the right product"
9+
}
10+
],
11+
"type": 2,
12+
"stream": false
13+
}

Docs/Images/temp/result.json

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
{
2+
"Id": "32d8d3f5-4cb5-4f9b-bb51-ab674ae212f5",
3+
"Name": "agent_one",
4+
"Model": "gemma:2b",
5+
"Messages": [
6+
{
7+
"Role": "system",
8+
"Content": "You are shop assistant in a GeekITStuff store. You have to help the customer in finding the right product"
9+
},
10+
{
11+
"Role": "user",
12+
"Content": "I am looking for something budget friendly but with options for extensions"
13+
},
14+
{
15+
"Role": "system",
16+
"Content": "Here is data from internal data source, This is what you should use to answer questions: [{\"id\":1,\"image\":\"pc1.jpg\",\"name\":\"Gaming PC Ultra\",\"brand\":\"PowerTech\",\"processor\":\"Intel Core i9-11900K\",\"type\":\"PC\",\"ram\":\"32GB DDR4\",\"storage\":\"1TB SSD + 2TB HDD\",\"gpu\":\"NVIDIA GeForce RTX 3090\",\"price\":2999.99,\"availability\":\"In Stock\",\"description\":\"The Gaming PC Ultra from PowerTech features an Intel Core i9 processor and NVIDIA RTX 3090, making it perfect for high-end gaming and demanding applications. With 32GB of RAM and ample storage, this PC can handle any task with ease.\"},{\"id\":2,\"image\":\"pc2.png\",\"name\":\"Workstation Pro\",\"brand\":\"TechMaster\",\"processor\":\"AMD Ryzen 9 5950X\",\"type\":\"PC\",\"ram\":\"64GB DDR4\",\"storage\":\"2TB SSD\",\"gpu\":\"NVIDIA Quadro RTX 5000\",\"price\":3499.99,\"availability\":\"In Stock\",\"description\":\"TechMaster's Workstation Pro is designed for professionals who require top-tier performance. With an AMD Ryzen 9 CPU, 64GB RAM, and NVIDIA Quadro RTX GPU, this workstation excels in 3D rendering, video editing, and other intensive tasks.\"},{\"id\":3,\"image\":\"pc3.jpg\",\"name\":\"Budget Gamer\",\"brand\":\"EconoPC\",\"processor\":\"Intel Core i5-10400F\",\"type\":\"PC\",\"ram\":\"16GB DDR4\",\"storage\":\"512GB SSD\",\"gpu\":\"NVIDIA GeForce GTX 1660 Super\",\"price\":799.99,\"availability\":\"Out of Stock\",\"description\":\"The Budget Gamer by EconoPC provides excellent value for entry-level gaming. Featuring an Intel Core i5 processor and NVIDIA GTX 1660 Super GPU, this PC delivers smooth performance for popular games at an affordable price.\"},{\"id\":4,\"image\":\"pc4.jpg\",\"name\":\"All-Purpose PC\",\"brand\":\"ValueComp\",\"processor\":\"AMD Ryzen 5 3600\",\"type\":\"PC\",\"ram\":\"16GB DDR4\",\"storage\":\"1TB HDD\",\"gpu\":\"AMD Radeon RX 5700\",\"price\":999.99,\"availability\":\"In Stock\",\"description\":\"ValueComp's All-Purpose PC is a versatile system suitable for gaming, work, and everyday use. It features an AMD Ryzen 5 processor, 16GB RAM, and a Radeon RX 5700 GPU, ensuring balanced performance for a variety of tasks.\"},{\"id\":5,\"image\":\"pc5.jpg\",\"name\":\"Compact Office PC\",\"brand\":\"OfficeMate\",\"processor\":\"Intel Core i3-10100\",\"type\":\"PC\",\"ram\":\"8GB DDR4\",\"storage\":\"256GB SSD\",\"gpu\":\"Integrated Graphics\",\"price\":499.99,\"availability\":\"In Stock\",\"description\":\"The Compact Office PC by OfficeMate is ideal for small spaces and routine office tasks. Equipped with an Intel Core i3 processor and 8GB of RAM, it offers reliable performance for word processing, spreadsheets, and internet browsing.\"},{\"id\":6,\"image\":\"pc6.jpg\",\"name\":\"Performance Beast\",\"brand\":\"ExtremeTech\",\"processor\":\"Intel Core i7-12700K\",\"type\":\"PC\",\"ram\":\"32GB DDR5\",\"storage\":\"2TB SSD\",\"gpu\":\"NVIDIA GeForce RTX 3080\",\"price\":2599.99,\"availability\":\"In Stock\",\"description\":\"ExtremeTech's Performance Beast is designed for the most demanding users. With an Intel Core i7 processor, 32GB DDR5 RAM, and NVIDIA RTX 3080 GPU, this PC is ideal for gaming, 3D rendering, and other high-performance applications.\"},{\"id\":7,\"image\":\"laptop1.jpg\",\"name\":\"UltraBook Pro\",\"brand\":\"PowerTech\",\"processor\":\"Intel Core i7-1165G7\",\"type\":\"Laptop\",\"ram\":\"16GB LPDDR4x\",\"storage\":\"512GB SSD\",\"gpu\":\"Intel Iris Xe Graphics\",\"price\":1299.99,\"availability\":\"In Stock\",\"description\":\"The UltraBook Pro by PowerTech offers a sleek design with powerful performance, featuring an Intel Core i7 processor and Intel Iris Xe Graphics. With 16GB of RAM and a 512GB SSD, this laptop is perfect for professionals on the go.\"},{\"id\":8,\"image\":\"laptop2.jpg\",\"name\":\"Gaming Laptop X\",\"brand\":\"TechMaster\",\"processor\":\"AMD Ryzen 7 5800H\",\"type\":\"Laptop\",\"ram\":\"32GB DDR4\",\"storage\":\"1TB SSD\",\"gpu\":\"NVIDIA GeForce RTX 3070\",\"price\":1999.99,\"availability\":\"In Stock\",\"description\":\"TechMaster's Gaming Laptop X is designed for gamers who need high performance on the go. Featuring an AMD Ryzen 7 CPU and NVIDIA RTX 3070 GPU, this laptop delivers smooth gaming experiences and fast load times.\"},{\"id\":9,\"image\":\"laptop3.jpg\",\"name\":\"Budget Laptop\",\"brand\":\"EconoPC\",\"processor\":\"Intel Core i3-1115G4\",\"type\":\"Laptop\",\"ram\":\"8GB DDR4\",\"storage\":\"256GB SSD\",\"gpu\":\"Integrated Graphics\",\"price\":499.99,\"availability\":\"Out of Stock\",\"description\":\"The Budget Laptop by EconoPC offers essential features at an affordable price. With an Intel Core i3 processor and 8GB of RAM, it's suitable for students and casual users who need reliable performance for everyday tasks.\"},{\"id\":10,\"image\":\"laptop4.jpg\",\"name\":\"All-Purpose Laptop\",\"brand\":\"ValueComp\",\"processor\":\"AMD Ryzen 5 4500U\",\"type\":\"Laptop\",\"ram\":\"16GB DDR4\",\"storage\":\"512GB SSD\",\"gpu\":\"AMD Radeon Graphics\",\"price\":899.99,\"availability\":\"In Stock\",\"description\":\"ValueComp's All-Purpose Laptop is versatile and powerful, equipped with an AMD Ryzen 5 processor and Radeon Graphics. It's ideal for a variety of tasks, including work, entertainment, and light gaming.\"},{\"id\":11,\"image\":\"laptop5.jpg\",\"name\":\"Compact Office Laptop\",\"brand\":\"OfficeMate\",\"processor\":\"Intel Core i5-1135G7\",\"type\":\"Laptop\",\"ram\":\"8GB LPDDR4x\",\"storage\":\"512GB SSD\",\"gpu\":\"Intel Iris Xe Graphics\",\"price\":799.99,\"availability\":\"In Stock\",\"description\":\"The Compact Office Laptop by OfficeMate is perfect for professionals who need a portable and efficient device. With an Intel Core i5 processor and 8GB of RAM, it offers solid performance for office applications and multitasking.\"},{\"id\":12,\"image\":\"laptop6.jpg\",\"name\":\"Creative Laptop\",\"brand\":\"CreativeTech\",\"processor\":\"Apple M1\",\"type\":\"Laptop\",\"ram\":\"16GB Unified Memory\",\"storage\":\"1TB SSD\",\"gpu\":\"Apple M1 GPU\",\"price\":1499.99,\"availability\":\"In Stock\",\"description\":\"CreativeTech's Creative Laptop is perfect for designers and content creators. Featuring the Apple M1 chip, 16GB of unified memory, and a 1TB SSD, this laptop offers exceptional performance and efficiency for creative tasks.\"}]"
17+
},
18+
{
19+
"Role": "assistant",
20+
"Content": "## Budget Gamer: Your Gateway to High-Performance Gaming on a Shoestring\n\nThe **Budget Gamer** from EconoPC is the PC that proves you can have the ultimate gaming experience without breaking the bank. It's packed with powerful features and sleek design, making it the perfect companion for both casual gamers and hardcore enthusiasts.\n\n**Here's what the Budget Gamer offers:**\n\n* **Unmatched value for its price:** This PC delivers high performance and exceptional features without the hefty price tag.\n* **Next-gen specs:** It boasts a brand-new Ryzen 7 5800U processor, 16GB of fast DDR5 memory, and a NVIDIA GeForce RTX 3060 graphics card – enough to run most popular games at high settings and even some demanding titles in 1080p.\n* **Ultra-quiet operation:** Enjoy a peaceful gaming environment with the built-in fans that ensure minimal noise.\n* **Sleek and stylish design:** The Budget Gamer boasts an elegant chassis and a unique mesh front panel, giving it a modern touch.\n* **Warranty and support:** EconoPC offers a comprehensive warranty and dedicated support resources, ensuring you have everything you need for complete peace of mind.\n\n**The Budget Gamer is perfect for:**\n\n* Gamers on a tight budget who still want to enjoy high-quality gaming.\n* First-time PC builders who want a powerful system without breaking the bank.\n* Gamers who demand high performance and a quiet and comfortable gaming environment.\n\n**Don't miss out on the ultimate gaming experience – get your Budget Gamer today!**"
21+
}
22+
],
23+
"Type": 2,
24+
"Stream": false,
25+
"Properties": {
26+
"FETCH_DATA*": ""
27+
}
28+
}

Docs/Images/temp/test.json

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": "llama3.1:8b",
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://localhost:5098/items",
16+
"method": "Get",
17+
"query": "",
18+
"payload": ""
19+
}
20+
},
21+
"steps": ["FETCH_DATA*","ANSWER", "REDIRECT+b29211e9-9ee8-45f4-bdbb-054cb835d0d6+AS_Output+REPLACE"],
22+
"relations":
23+
[
24+
"ac243657-5ab1-4727-b4be-1ea5ae2e76d3",
25+
"b29211e9-9ee8-45f4-bdbb-054cb835d0d6"
26+
]
27+
}
28+
},
29+
{
30+
"id": "b29211e9-9ee8-45f4-bdbb-054cb835d0d6",
31+
"name": "agent_three",
32+
"description": "This is the third RAG agent",
33+
"model": "llama3.1:8b",
34+
"context":
35+
{
36+
"instruction": "Adjust previous response to be better for marketting purposes. Dont include any introduction, just pure content",
37+
"steps": ["ANSWER"]
38+
}
39+
}
40+
]

Frontend/MainFE/.idea/.idea.MainFE/.idea/inspectionProfiles/Project_Default.xml

Lines changed: 21 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Lines changed: 114 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,114 @@
1+
@using MainFE.Components.Models
2+
@using Markdig
3+
@using Microsoft.FluentUI.AspNetCore.Components
4+
@using Message = MainFE.Components.Models.Message
5+
@inject HttpClient Http
6+
<link rel="stylesheet" href="css/chat.css">
7+
8+
<div class="messages-container">
9+
@foreach (var message in Chat?.Messages ?? [])
10+
{
11+
@if (message.Role != Role.System.ToString().ToLowerInvariant())
12+
{
13+
<span class="@(message.Role == Role.User.ToString() ? "message-role-user" : "message-role-bot")">@GetRoleLabel(message.Role)</span>
14+
<FluentCard class="@(message.Role == Role.User.ToString() ? "message-card user-message" : "message-card bot-message")">
15+
@((MarkupString)((message.Role == Role.User.ToString()
16+
? message.Content
17+
: Markdown.ToHtml((string)message.Content!,
18+
new MarkdownPipelineBuilder()
19+
.UseAdvancedExtensions()
20+
.Build())) ?? string.Empty))
21+
</FluentCard>
22+
}
23+
}
24+
@if (IsLoading)
25+
{
26+
<span class="message-role-bot">@_displayName</span>
27+
<FluentProgressRing Visible="IsLoading"></FluentProgressRing>
28+
}
29+
</div>
30+
<div class="input-container">
31+
<input @bind-value="_ask" @bind-value:event="oninput" placeholder="Enter your prompt here..." @onkeydown="CheckEnterKey" class="inp">
32+
<FluentButton IconStart="@(new Icons.Filled.Size28.Send())" BackgroundColor="rgba(0, 0, 0, 0)" Style="margin-top: 5px; background-color: transparent"
33+
Appearance="Appearance.Lightweight"
34+
Loading="@IsLoading"
35+
OnClick="@(() => SendAsync(_ask))">
36+
</FluentButton>
37+
</div>
38+
<FluentProgress Visible="@(IsLoading)" style="width: 100%;"></FluentProgress>
39+
40+
@code
41+
{
42+
[Parameter] public ChatDto? Chat { get; set; }
43+
[Parameter] public string SelectedModel { get; set; }
44+
[Parameter] public bool IsLoading { get; set; }
45+
[Parameter] public string? CustomName { get; set; }
46+
[Parameter] public bool IsRagChat { get; set; }
47+
[Parameter] public string? AgentId { get; set; }
48+
[Parameter] public bool Translate { get; set; }
49+
50+
private string _ask = string.Empty;
51+
private string _displayName => CustomName ?? SelectedModel;
52+
53+
private async Task SendAsync(string message)
54+
{
55+
if (IsRagChat)
56+
{
57+
await RaGSendAsync(message);
58+
return;
59+
}
60+
61+
IsLoading = true;
62+
if (!string.IsNullOrWhiteSpace(message))
63+
{
64+
Chat.Messages.Add(new Message { Role = Role.User.ToString(), Content = message });
65+
Chat.Model = SelectedModel;
66+
67+
var apiResponse = await Http.PostAsJsonAsync($"{ExtensionMethods.GetApiUrl()}/api/chats/complete?translate={Translate}", Chat);
68+
69+
if (apiResponse.IsSuccessStatusCode)
70+
{
71+
var response = await apiResponse.Content.ReadFromJsonAsync<ChatResponse>();
72+
if (response != null)
73+
{
74+
Chat.Messages.Add(response.Message);
75+
}
76+
}
77+
IsLoading = false;
78+
_ask = string.Empty;
79+
}
80+
}
81+
82+
private async Task RaGSendAsync(string message)
83+
{
84+
IsLoading = true;
85+
if (!string.IsNullOrWhiteSpace(message))
86+
{
87+
Chat.Messages.Add(new Message { Role = Role.User.ToString(), Content = message });
88+
Chat.Model = SelectedModel;
89+
90+
var apiResponse = await Http.PostAsJsonAsync($"{ExtensionMethods.GetApiUrl()}/api/agents/{AgentId}/process", Chat);
91+
92+
if (apiResponse.IsSuccessStatusCode)
93+
{
94+
var response = await apiResponse.Content.ReadFromJsonAsync<ChatDto>();
95+
if (response != null)
96+
{
97+
Chat = response;
98+
}
99+
}
100+
IsLoading = false;
101+
_ask = string.Empty;
102+
}
103+
}
104+
105+
private async Task CheckEnterKey(KeyboardEventArgs e)
106+
{
107+
if (e.Key == "Enter")
108+
{
109+
await SendAsync(_ask);
110+
}
111+
}
112+
113+
private string GetRoleLabel(string role) => role == Role.User.ToString() ? "( ͡° ͜ʖ ͡°) User" : $"{_displayName}";
114+
}
Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
@typeparam TItem
2+
3+
<div class="tile-select">
4+
@foreach (var item in Items)
5+
{
6+
<div class="tile @(EqualityComparer<TItem>.Default.Equals(item, SelectedItem) ? "selected" : "")"
7+
@onclick="() => SelectItem(item)">
8+
@item
9+
</div>
10+
}
11+
</div>
12+
13+
@code {
14+
[Parameter] public List<TItem> Items { get; set; }
15+
[Parameter] public TItem SelectedItem { get; set; }
16+
[Parameter] public EventCallback<TItem> SelectedItemChanged { get; set; }
17+
18+
private void SelectItem(TItem item)
19+
{
20+
SelectedItem = item;
21+
SelectedItemChanged.InvokeAsync(item);
22+
}
23+
}
24+
25+
<style>
26+
.tile-select {
27+
display: flex;
28+
flex-wrap: wrap;
29+
gap: 10px;
30+
}
31+
32+
.tile {
33+
padding: 10px;
34+
border: 1px solid #2b2a2a;
35+
border-radius: 8px;
36+
color: wheat;
37+
width: 100%;
38+
cursor: pointer;
39+
transition: background-color 0.3s;
40+
}
41+
42+
.tile:hover {
43+
background-color: #494949;
44+
}
45+
46+
.tile.selected {
47+
background-color: #8c8282;
48+
color: white;
49+
border-color: #ffffff;
50+
}
51+
</style>

0 commit comments

Comments
 (0)