Skip to content
This repository was archived by the owner on Jun 5, 2025. It is now read-only.

Commit f0fff68

Browse files
committed
Update the integration_tests.py to extract correctly FIM repsonses
Signed-off-by: Radoslav Dimitrov <[email protected]>
1 parent b16c741 commit f0fff68

File tree

2 files changed

+19
-10
lines changed

2 files changed

+19
-10
lines changed

src/codegate/providers/llamacpp/completion_handler.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,8 @@ async def execute_completion(
6060
model_path = f"{Config.get_config().model_base_path}/{request['model']}.gguf"
6161

6262
# Create a copy of the request dict and remove stream_options
63-
# Reason - Request error as JSON: {'error': "Llama.create_completion() got an unexpected keyword argument 'stream_options'"}
63+
# Reason - Request error as JSON:
64+
# {'error': "Llama.create_completion() got an unexpected keyword argument 'stream_options'"}
6465
request_dict = dict(request)
6566
request_dict.pop("stream_options", None)
6667

tests/integration/integration_tests.py

Lines changed: 17 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -67,17 +67,25 @@ def parse_response_message(response, streaming=True):
6767
if "DONE" in decoded_line or "message_stop" in decoded_line:
6868
break
6969

70-
decoded_line = decoded_line.replace("data:", "")
70+
decoded_line = decoded_line.replace("data:", "").strip()
7171
json_line = json.loads(decoded_line)
72-
7372
message_content = None
73+
# Handle both chat and FIM responses
7474
if "choices" in json_line:
75-
if "finish_reason" in json_line["choices"][0]:
75+
choice = json_line["choices"][0]
76+
# Break if the conversation is over
77+
if choice.get("finish_reason") == "stop":
7678
break
77-
if "delta" in json_line["choices"][0]:
78-
message_content = json_line["choices"][0]["delta"].get("content", "")
79-
elif "text" in json_line["choices"][0]:
80-
message_content = json_line["choices"][0].get("text", "")
79+
# Handle chat responses
80+
if "delta" in choice:
81+
delta = choice["delta"]
82+
if "content" in delta and delta["content"] is not None:
83+
message_content = delta["content"]
84+
# Handle FIM responses
85+
elif "text" in choice:
86+
text = choice["text"]
87+
if text is not None:
88+
message_content = text
8189
elif "delta" in json_line:
8290
message_content = json_line["delta"].get("text", "")
8391
elif "message" in json_line:
@@ -87,7 +95,6 @@ def parse_response_message(response, streaming=True):
8795

8896
if message_content is not None:
8997
response_message += message_content
90-
9198
else:
9299
if "choices" in response.json():
93100
response_message = response.json()["choices"][0]["message"].get("content", "")
@@ -97,7 +104,8 @@ def parse_response_message(response, streaming=True):
97104
except Exception as e:
98105
logger.exception("An error occurred: %s", e)
99106

100-
return response_message
107+
# Remove any trailing newlines and return
108+
return response_message.strip()
101109

102110
@staticmethod
103111
def replace_env_variables(input_string, env):

0 commit comments

Comments
 (0)