mirror of
https://github.com/meta-llama/llama-stack.git
synced 2025-12-17 12:42:37 +00:00
.
This commit is contained in:
parent
1801aa145d
commit
f946d23d8e
2 changed files with 74 additions and 0 deletions
35
1.py
Normal file
35
1.py
Normal file
|
|
@ -0,0 +1,35 @@
|
|||
# Copyright (c) Meta Platforms, Inc. and affiliates.
|
||||
# All rights reserved.
|
||||
#
|
||||
# This source code is licensed under the terms described in the LICENSE file in
|
||||
# the root directory of this source tree.
|
||||
|
||||
import os
|
||||
|
||||
from llama_stack_client import LlamaStackClient
|
||||
|
||||
client = LlamaStackClient(base_url=f"http://localhost:{os.environ['LLAMA_STACK_PORT']}")
|
||||
|
||||
response = client.inference.chat_completion(
|
||||
model_id=os.environ["INFERENCE_MODEL"],
|
||||
messages=[
|
||||
{"role": "system", "content": "You are a helpful assistant."},
|
||||
{"role": "user", "content": "Write a haiku about coding"},
|
||||
],
|
||||
response_format={
|
||||
"type": "json_schema",
|
||||
"json_schema": {
|
||||
"type": "object",
|
||||
"properties": {
|
||||
"completion_message": {
|
||||
"type": "object",
|
||||
"properties": {
|
||||
"content": {"type": "string"},
|
||||
"additional_info": {"type": "string"},
|
||||
},
|
||||
}
|
||||
},
|
||||
},
|
||||
},
|
||||
)
|
||||
print(response.completion_message.content)
|
||||
Loading…
Add table
Add a link
Reference in a new issue