MCPcopy Index your code
hub / github.com/abetlen/llama-cpp-python / create_chat_completion

Function create_chat_completion

llama_cpp/server/app.py:408–526  ·  view source on GitHub ↗
(
    request: Request,
    body: CreateChatCompletionRequest = Body(
        openapi_examples={
            "normal": {
                "summary": "Chat Completion",
                "value": {
                    "model": "gpt-3.5-turbo",
                    "messages": [
                        {"role": "system", "content": "You are a helpful assistant."},
                        {"role": "user", "content": "What is the capital of France?"},
                    ],
                },
            },
            "json_mode": {
                "summary": "JSON Mode",
                "value": {
                    "model": "gpt-3.5-turbo",
                    "messages": [
                        {"role": "system", "content": "You are a helpful assistant."},
                        {"role": "user", "content": "Who won the world series in 2020"},
                    ],
                    "response_format": {"type": "json_object"},
                },
            },
            "tool_calling": {
                "summary": "Tool Calling",
                "value": {
                    "model": "gpt-3.5-turbo",
                    "messages": [
                        {"role": "system", "content": "You are a helpful assistant."},
                        {"role": "user", "content": "Extract Jason is 30 years old."},
                    ],
                    "tools": [
                        {
                            "type": "function",
                            "function": {
                                "name": "User",
                                "description": "User record",
                                "parameters": {
                                    "type": "object",
                                    "properties": {
                                        "name": {"type": "string"},
                                        "age": {"type": "number"},
                                    },
                                    "required": ["name", "age"],
                                },
                            },
                        }
                    ],
                    "tool_choice": {
                        "type": "function",
                        "function": {
                            "name": "User",
                        },
                    },
                },
            },
            "logprobs": {
                "summary": "Logprobs",
                "value": {
                    "model": "gpt-3.5-turbo",
                    "messages": [
                        {"role": "system", "content": "You are a helpful assistant."},
                        {"role": "user", "content": "What is the capital of France?"},
                    ],
                    "logprobs": True,
                    "top_logprobs": 10,
                },
            },
        }
    ),
)

Source from the content-addressed store, hash-verified

406 tags=[openai_v1_tag],
407)
408async def create_chat_completion(
409 request: Request,
410 body: CreateChatCompletionRequest = Body(
411 openapi_examples={
412 "normal": {
413 "summary": "Chat Completion",
414 "value": {
415 "model": "gpt-3.5-turbo",
416 "messages": [
417 {"role": "system", "content": "You are a helpful assistant."},
418 {"role": "user", "content": "What is the capital of France?"},
419 ],
420 },
421 },
422 "json_mode": {
423 "summary": "JSON Mode",
424 "value": {
425 "model": "gpt-3.5-turbo",
426 "messages": [
427 {"role": "system", "content": "You are a helpful assistant."},
428 {"role": "user", "content": "Who won the world series in 2020"},
429 ],
430 "response_format": {"type": "json_object"},
431 },
432 },
433 "tool_calling": {
434 "summary": "Tool Calling",
435 "value": {
436 "model": "gpt-3.5-turbo",
437 "messages": [
438 {"role": "system", "content": "You are a helpful assistant."},
439 {"role": "user", "content": "Extract Jason is 30 years old."},
440 ],
441 "tools": [
442 {
443 "type": "function",
444 "function": {
445 "name": "User",
446 "description": "User record",
447 "parameters": {
448 "type": "object",
449 "properties": {
450 "name": {"type": "string"},
451 "age": {"type": "number"},
452 },
453 "required": ["name", "age"],
454 },
455 },
456 }
457 ],
458 "tool_choice": {
459 "type": "function",
460 "function": {
461 "name": "User",
462 },
463 },
464 },
465 },

Callers

nothing calls this directly

Calls 1

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…