Skip to content

Conversation

@wkukka1
Copy link
Collaborator

@wkukka1 wkukka1 commented Jul 10, 2025

Updates:

  • added json schema to ollama and llama.cpp (cli and sever) calls
  • added json_schema param in post request to /chat endpoint

@wkukka1 wkukka1 requested a review from Rolland-He July 10, 2025 14:55
Copy link
Collaborator

@Rolland-He Rolland-He left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hi, @wkukka1 nice work! I’ve left a inline comment regarding magic strings, mostly suggesting to extract repeated literals into named constants. Just a minor style suggestion and totally fine to leave as is. Everything else looks good!

messages = _build_messages(content, system_prompt, image_files=[]) # TODO: Pass image files
payload = {'model': model, 'messages': messages, 'stream': False, 'max_tokens': 512}
if json_schema:
payload['json_schema'] = json_schema["schema"]
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For coding style, try to define "schema" as a constant like SCHEMA_KEY = "schema" and reuse it throughout. This makes the intent clearer and avoids potential typos. Similarly for "--json-schema".

model=model,
messages=messages,
stream=False,
format=json_schema['schema'] if json_schema else None,
Copy link
Collaborator

@Rolland-He Rolland-He Jul 10, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same here.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's still 'schema'.

cmd = [LLAMA_CPP_CLI, '-m', model_path, '--n-gpu-layers', '40', '-p', content, '-n', '512', '--single-turn']
if json_schema:
raw_schema = json_schema["schema"] if "schema" in json_schema else json_schema
cmd += ["--json-schema", json.dumps(raw_schema)]
Copy link
Collaborator

@Rolland-He Rolland-He Jul 10, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same here.

@wkukka1 wkukka1 requested a review from Rolland-He July 10, 2025 18:23
Copy link
Collaborator

@Rolland-He Rolland-He left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hi @wkukka1 , good work! There's still one place left.

model=model,
messages=messages,
stream=False,
format=json_schema['schema'] if json_schema else None,
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's still 'schema'.

@wkukka1 wkukka1 requested a review from Rolland-He July 10, 2025 19:03
Copy link
Collaborator

@Rolland-He Rolland-He left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good!

@wkukka1 wkukka1 requested a review from david-yz-liu July 10, 2025 19:31
assert args[0] == "http://localhost:8080/v1/chat/completions"

body = kwargs["json"]
print(body)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Delete this line

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fixed!

@wkukka1 wkukka1 requested a review from david-yz-liu July 10, 2025 20:20
@david-yz-liu david-yz-liu merged commit 251b034 into MarkUsProject:main Jul 10, 2025
2 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants