File tree 4 files changed +50
-2
lines changed
examples/batch-processing 4 files changed +50
-2
lines changed Original file line number Diff line number Diff line change
1
+ """llama-cpp-python server from scratch in a single file.
2
+ """
3
+
4
+ # import llama_cpp
5
+
6
+ # path = b"../../models/Qwen1.5-0.5B-Chat-GGUF/qwen1_5-0_5b-chat-q8_0.gguf"
7
+
8
+ # model_params = llama_cpp.llama_model_default_params()
9
+ # model = llama_cpp.llama_load_model_from_file(path, model_params)
10
+
11
+ # if model is None:
12
+ # raise RuntimeError(f"Failed to load model from file: {path}")
13
+
14
+
15
+ # ctx_params = llama_cpp.llama_context_default_params()
16
+ # ctx = llama_cpp.llama_new_context_with_model(model, ctx_params)
17
+
18
+ # if ctx is None:
19
+ # raise RuntimeError("Failed to create context")
20
+
21
+
22
+ from fastapi import FastAPI
23
+
24
+ app = FastAPI ()
25
+
26
+ import openai .types .chat as types
27
+
28
+ @app .post ("/v1/chat/completions" )
29
+ def create_chat_completions ():
30
+ return {"message" : "Hello World" }
Original file line number Diff line number Diff line change @@ -59,7 +59,16 @@ def main():
59
59
if not os .path .exists (config_file ):
60
60
raise ValueError (f"Config file { config_file } not found!" )
61
61
with open (config_file , "rb" ) as f :
62
- config_file_settings = ConfigFileSettings .model_validate_json (f .read ())
62
+ # Check if yaml file
63
+ if config_file .endswith (".yaml" ) or config_file .endswith (".yml" ):
64
+ import yaml
65
+ import json
66
+
67
+ config_file_settings = ConfigFileSettings .model_validate_json (
68
+ json .dumps (yaml .safe_load (f ))
69
+ )
70
+ else :
71
+ config_file_settings = ConfigFileSettings .model_validate_json (f .read ())
63
72
server_settings = ServerSettings .model_validate (config_file_settings )
64
73
model_settings = config_file_settings .models
65
74
else :
Original file line number Diff line number Diff line change @@ -97,7 +97,15 @@ def create_app(
97
97
if not os .path .exists (config_file ):
98
98
raise ValueError (f"Config file { config_file } not found!" )
99
99
with open (config_file , "rb" ) as f :
100
- config_file_settings = ConfigFileSettings .model_validate_json (f .read ())
100
+ # Check if yaml file
101
+ if config_file .endswith (".yaml" ) or config_file .endswith (".yml" ):
102
+ import yaml
103
+
104
+ config_file_settings = ConfigFileSettings .model_validate_json (
105
+ json .dumps (yaml .safe_load (f ))
106
+ )
107
+ else :
108
+ config_file_settings = ConfigFileSettings .model_validate_json (f .read ())
101
109
server_settings = ServerSettings .model_validate (config_file_settings )
102
110
model_settings = config_file_settings .models
103
111
Original file line number Diff line number Diff line change @@ -35,6 +35,7 @@ server = [
35
35
" pydantic-settings>=2.0.1" ,
36
36
" sse-starlette>=1.6.1" ,
37
37
" starlette-context>=0.3.6,<0.4" ,
38
+ " PyYAML>=5.1" ,
38
39
]
39
40
test = [
40
41
" pytest>=7.4.0" ,
You can’t perform that action at this time.
0 commit comments