Skip to content

Commit 18485b6

Browse files
committed
Added additional logging for ollama/llamacpp calls
1 parent 26d4d2d commit 18485b6

File tree

1 file changed

+27
-0
lines changed

1 file changed

+27
-0
lines changed

markus_ai_server/server.py

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,13 +78,22 @@ def chat_with_llama_server_http(
7878
if 'stream' not in payload:
7979
payload['stream'] = False
8080

81+
start_log_data = {
82+
'model': model
83+
}
84+
logger.info(f'chat_with_llama_server_http starting: {start_log_data}')
8185
response = requests.post(
8286
f'{LLAMA_SERVER_URL}/v1/chat/completions',
8387
json=payload,
8488
headers={'Content-Type': 'application/json'},
8589
timeout=timeout,
8690
)
8791

92+
done_log_data = {
93+
'model': model,
94+
'response_status_code': response.status_code
95+
}
96+
logger.info(f'chat_with_llama_server_http done: {start_log_data}')
8897
if response.status_code == 200:
8998
data = response.json()
9099
if 'choices' in data and len(data['choices']) > 0:
@@ -123,13 +132,26 @@ def chat_with_ollama(
123132
"""Handle chat using ollama."""
124133
messages = _build_messages(content, system_prompt, image_files)
125134

135+
start_log_data = {
136+
'model': model
137+
}
138+
logger.info(f'chat_with_ollama starting: {start_log_data}')
126139
response = ollama.chat(
127140
model=model,
128141
messages=messages,
129142
stream=False,
130143
format=json_schema[SCHEMA_KEY] if json_schema else None,
131144
options=model_options,
132145
)
146+
done_log_data = {
147+
'model': model,
148+
'eval_duration': response.eval_duration,
149+
'prompt_eval_duration': response.prompt_eval_duration,
150+
'eval_count': response.eval_count,
151+
'prompt_eval_count': response.eval_count
152+
}
153+
154+
logger.info(f'chat_with_ollama done: {done_log_data}')
133155
return response.message.content
134156

135157

@@ -165,7 +187,12 @@ def chat_with_llamacpp(
165187
pass # TODO: pass image files
166188

167189
try:
190+
start_log_data = {
191+
'model': model
192+
}
193+
logger.info(f'chat_with_llamacpp starting: {start_log_data}')
168194
result = subprocess.run(cmd, capture_output=True, text=False, timeout=timeout, check=True)
195+
logger.info(f'chat_with_llamacpp done: {start_log_data}')
169196

170197
stdout_text = result.stdout.decode('utf-8', errors='replace')
171198

0 commit comments

Comments
 (0)