1
- from typing import List
2
-
3
1
from fastapi import APIRouter , FastAPI
4
2
from fastapi .middleware .cors import CORSMiddleware
5
3
6
4
from codegate import __description__ , __version__
7
- from codegate .config import Config
8
5
from codegate .dashboard .dashboard import dashboard_router
9
- from codegate .pipeline .base import PipelineStep , SequentialPipelineProcessor
10
- from codegate .pipeline .codegate_context_retriever .codegate import CodegateContextRetriever
11
- from codegate .pipeline .extract_snippets .extract_snippets import CodeSnippetExtractor
12
- from codegate .pipeline .extract_snippets .output import CodeCommentStep
13
- from codegate .pipeline .output import OutputPipelineProcessor , OutputPipelineStep
14
- from codegate .pipeline .secrets .manager import SecretsManager
15
- from codegate .pipeline .secrets .secrets import (
16
- CodegateSecrets ,
17
- SecretRedactionNotifier ,
18
- SecretUnredactionStep ,
19
- )
6
+ from codegate .pipeline .factory import PipelineFactory
20
7
from codegate .pipeline .secrets .signatures import CodegateSignatures
21
- from codegate .pipeline .system_prompt .codegate import SystemPrompt
22
- from codegate .pipeline .version .version import CodegateVersion
23
8
from codegate .providers .anthropic .provider import AnthropicProvider
24
9
from codegate .providers .llamacpp .provider import LlamaCppProvider
25
10
from codegate .providers .ollama .provider import OllamaProvider
28
13
from codegate .providers .vllm .provider import VLLMProvider
29
14
30
15
31
- def init_app () -> FastAPI :
16
+ def init_app (pipeline_factory : PipelineFactory ) -> FastAPI :
32
17
"""Create the FastAPI application."""
33
18
app = FastAPI (
34
19
title = "CodeGate" ,
@@ -43,44 +28,6 @@ def init_app() -> FastAPI:
43
28
allow_headers = ["*" ],
44
29
)
45
30
46
- # Initialize secrets manager
47
- # TODO: we need to clean up the secrets manager
48
- # after the conversation is concluded
49
- # this was done in the pipeline step but I just removed it for now
50
- secrets_manager = SecretsManager ()
51
-
52
- # Define input pipeline steps
53
- input_steps : List [PipelineStep ] = [
54
- CodegateSecrets (),
55
- CodegateVersion (),
56
- CodeSnippetExtractor (),
57
- SystemPrompt (Config .get_config ().prompts .default_chat ),
58
- CodegateContextRetriever (),
59
- ]
60
-
61
- # Define FIM pipeline steps
62
- fim_steps : List [PipelineStep ] = [
63
- CodegateSecrets (),
64
- ]
65
-
66
- # Initialize input pipeline processors
67
- input_pipeline_processor = SequentialPipelineProcessor (input_steps , secrets_manager )
68
- fim_pipeline_processor = SequentialPipelineProcessor (fim_steps , secrets_manager )
69
-
70
- # Define output pipeline steps
71
- output_steps : List [OutputPipelineStep ] = [
72
- SecretRedactionNotifier (),
73
- SecretUnredactionStep (),
74
- CodeCommentStep (),
75
- ]
76
- fim_output_steps : List [OutputPipelineStep ] = [
77
- # temporarily disabled
78
- # SecretUnredactionStep(),
79
- ]
80
-
81
- output_pipeline_processor = OutputPipelineProcessor (output_steps )
82
- fim_output_pipeline_processor = OutputPipelineProcessor (fim_output_steps )
83
-
84
31
# Create provider registry
85
32
registry = ProviderRegistry (app )
86
33
@@ -91,60 +38,57 @@ def init_app() -> FastAPI:
91
38
registry .add_provider (
92
39
"openai" ,
93
40
OpenAIProvider (
94
- pipeline_processor = input_pipeline_processor ,
95
- fim_pipeline_processor = fim_pipeline_processor ,
96
- output_pipeline_processor = output_pipeline_processor ,
97
- fim_output_pipeline_processor = fim_output_pipeline_processor ,
41
+ pipeline_processor = pipeline_factory . create_input_pipeline () ,
42
+ fim_pipeline_processor = pipeline_factory . create_fim_pipeline () ,
43
+ output_pipeline_processor = pipeline_factory . create_output_pipeline () ,
44
+ fim_output_pipeline_processor = pipeline_factory . create_fim_output_pipeline () ,
98
45
),
99
46
)
100
47
registry .add_provider (
101
48
"anthropic" ,
102
49
AnthropicProvider (
103
- pipeline_processor = input_pipeline_processor ,
104
- fim_pipeline_processor = fim_pipeline_processor ,
105
- output_pipeline_processor = output_pipeline_processor ,
106
- fim_output_pipeline_processor = fim_output_pipeline_processor ,
50
+ pipeline_processor = pipeline_factory . create_input_pipeline () ,
51
+ fim_pipeline_processor = pipeline_factory . create_fim_pipeline () ,
52
+ output_pipeline_processor = pipeline_factory . create_output_pipeline () ,
53
+ fim_output_pipeline_processor = pipeline_factory . create_fim_output_pipeline () ,
107
54
),
108
55
)
109
56
registry .add_provider (
110
57
"llamacpp" ,
111
58
LlamaCppProvider (
112
- pipeline_processor = input_pipeline_processor ,
113
- fim_pipeline_processor = fim_pipeline_processor ,
114
- output_pipeline_processor = output_pipeline_processor ,
115
- fim_output_pipeline_processor = fim_output_pipeline_processor ,
59
+ pipeline_processor = pipeline_factory . create_input_pipeline () ,
60
+ fim_pipeline_processor = pipeline_factory . create_fim_pipeline () ,
61
+ output_pipeline_processor = pipeline_factory . create_output_pipeline () ,
62
+ fim_output_pipeline_processor = pipeline_factory . create_fim_output_pipeline () ,
116
63
),
117
64
)
118
65
registry .add_provider (
119
66
"vllm" ,
120
67
VLLMProvider (
121
- pipeline_processor = input_pipeline_processor ,
122
- fim_pipeline_processor = fim_pipeline_processor ,
123
- output_pipeline_processor = output_pipeline_processor ,
124
- fim_output_pipeline_processor = fim_output_pipeline_processor ,
68
+ pipeline_processor = pipeline_factory . create_input_pipeline () ,
69
+ fim_pipeline_processor = pipeline_factory . create_fim_pipeline () ,
70
+ output_pipeline_processor = pipeline_factory . create_output_pipeline () ,
71
+ fim_output_pipeline_processor = pipeline_factory . create_fim_output_pipeline () ,
125
72
),
126
73
)
127
74
registry .add_provider (
128
75
"ollama" ,
129
76
OllamaProvider (
130
- pipeline_processor = input_pipeline_processor ,
131
- fim_pipeline_processor = fim_pipeline_processor ,
132
- output_pipeline_processor = output_pipeline_processor ,
133
- fim_output_pipeline_processor = fim_output_pipeline_processor ,
77
+ pipeline_processor = pipeline_factory . create_input_pipeline () ,
78
+ fim_pipeline_processor = pipeline_factory . create_fim_pipeline () ,
79
+ output_pipeline_processor = pipeline_factory . create_output_pipeline () ,
80
+ fim_output_pipeline_processor = pipeline_factory . create_fim_output_pipeline () ,
134
81
),
135
82
)
136
83
137
84
# Create and add system routes
138
- system_router = APIRouter (tags = ["System" ]) # Tags group endpoints in the docs
85
+ system_router = APIRouter (tags = ["System" ])
139
86
140
87
@system_router .get ("/health" )
141
88
async def health_check ():
142
89
return {"status" : "healthy" }
143
90
144
- # Include the router in the app - this exposes the health check endpoint
145
91
app .include_router (system_router )
146
-
147
- # Include the routes for the dashboard
148
92
app .include_router (dashboard_router )
149
93
150
94
return app
0 commit comments