Skip to content

Commit bf67d8f

Browse files
Revert "rag (#7)"
This reverts commit 9c703bd.
1 parent 9c703bd commit bf67d8f

24 files changed

+289
-377
lines changed

.dockerignore

Lines changed: 0 additions & 22 deletions
This file was deleted.

.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
11
.DS_Store
2+
configs/*
3+
!configs/example.toml
24
llm_backend/protos/
35

46
# Byte-compiled / optimized / DLL files

Dockerfile

Lines changed: 0 additions & 35 deletions
This file was deleted.

README.md

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ uv run gen-protos
1111

1212
## Usage
1313

14-
Please configure the `configs/config.toml` file.
14+
Please configure the `configs/config.toml` file (refer to `configs/example.toml` for the options).
1515
The following environment variables are required (`export` them or place them in a `.env` file):
1616

1717
- `OPENAI_API_KEY`: Your ChatGPT API key.
@@ -23,12 +23,6 @@ The following environment variables are required (`export` them or place them in
2323
python3 scripts/serve.py --config configs/config.toml
2424
```
2525

26-
You can refer to `scripts/client.py` for an example implementation of a client:
27-
28-
```shell
29-
python3 scripts/client.py
30-
```
31-
3226
## Features
3327

3428
Refer to the protobuf files in the `protos/` directory for the features provided by the server.

configs/config.toml

Lines changed: 0 additions & 44 deletions
This file was deleted.

configs/example.toml

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
[server]
2+
host = 'localhost'
3+
port = 50051
4+
max_workers = 10
5+
6+
[service.search.embeddings]
7+
# Name of embedding model. All available models can be found [here](https://huggingface.co/models?language=zh)
8+
model = 'moka-ai/m3e-base'
9+
10+
[service.search.query]
11+
# The template must contain the `{keywords}` placeholder.
12+
prompt_template = 'Please search for the content related to the following keywords: {keywords}.'
13+
similarity_top_k = 3
14+
15+
[service.summarize.chatgpt]
16+
model = 'o3-mini'
17+
18+
[service.summarize.query]
19+
system_template = """
20+
You are an expert Q&A system that is trusted around the world.
21+
Always answer the query using the provided context information, and not prior knowledge.
22+
Some rules to follow:
23+
1. Never directly reference the given context in your answer.
24+
2. Avoid statements like 'Based on the context, ...' or The context information ...' or anything along those lines."""
25+
26+
# The template must contain the `{context_str}` and `{query_str}` placeholders.
27+
user_template = """
28+
Context information from multiple sources is below.
29+
---------------------
30+
{context_str}
31+
---------------------
32+
Given the information from multiple sources and not prior knowledge, answer the query.
33+
Query: {query_str}
34+
Answer: """
35+
36+
# The content of `{query_str}` placeholder in the user template.
37+
query_str = '請用繁體中文總結這幾篇新聞。'
38+
39+
# The transform function from the request strings to the query strings.
40+
# Must be one of:
41+
# - 'plain': The query string is the same as the request string.
42+
# - 'numbered': Add a number (1., 2., ...) to the beginning of each request string.
43+
content_format = 'plain'

docker-compose.yaml

Lines changed: 0 additions & 35 deletions
This file was deleted.

llm_backend/__init__.py

Lines changed: 25 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,18 @@
11
import os
22

3-
import grpc
3+
from grpc._server import _Server
44
from pydantic import BaseModel
55

6-
from .rag import RagConfig, RagService, add_RagServiceServicer_to_server
6+
from .search import (
7+
SearchService,
8+
add_SearchServiceServicer_to_server,
9+
)
10+
from .search.config import SearchConfig
11+
from .summarize import (
12+
SummarizeService,
13+
add_SummarizeServiceServicer_to_server,
14+
)
15+
from .summarize.config import SummarizeConfig
716

817

918
class ServerConfig(BaseModel):
@@ -12,11 +21,21 @@ class ServerConfig(BaseModel):
1221
max_workers: int = (os.cpu_count() or 1) * 5
1322

1423

24+
class ServiceConfig(BaseModel):
25+
search: SearchConfig
26+
summarize: SummarizeConfig
27+
28+
1529
class Config(BaseModel):
1630
server: ServerConfig
17-
service: RagConfig
31+
service: ServiceConfig
32+
33+
34+
def setup_search_service(config: Config, server: _Server):
35+
search_service = SearchService(config.service.search)
36+
add_SearchServiceServicer_to_server(search_service, server)
1837

1938

20-
def setup_rag_service(config: Config, server: grpc.aio.Server):
21-
rag_service = RagService(config.service)
22-
add_RagServiceServicer_to_server(rag_service, server)
39+
def setup_summarize_service(config: Config, server: _Server):
40+
summarize_service = SummarizeService(config.service.summarize)
41+
add_SummarizeServiceServicer_to_server(summarize_service, server)

llm_backend/rag/__init__.py

Lines changed: 0 additions & 5 deletions
This file was deleted.

llm_backend/rag/content_formatters.py

Lines changed: 0 additions & 17 deletions
This file was deleted.

0 commit comments

Comments
 (0)