mirror of
https://github.com/meta-llama/llama-stack.git
synced 2025-07-30 07:39:38 +00:00
added simple inferences
This commit is contained in:
parent
e4560a5e74
commit
626dffa0d9
2 changed files with 58 additions and 0 deletions
36
docs/source/inference-streaming.py
Normal file
36
docs/source/inference-streaming.py
Normal file
|
@ -0,0 +1,36 @@
|
||||||
|
import asyncio
|
||||||
|
|
||||||
|
from llama_stack_client import LlamaStackClient
|
||||||
|
from llama_stack_client.lib.inference.event_logger import EventLogger
|
||||||
|
from llama_stack_client.types import UserMessage
|
||||||
|
from termcolor import cprint
|
||||||
|
|
||||||
|
|
||||||
|
async def run_main(stream: bool = True):
|
||||||
|
client = LlamaStackClient(
|
||||||
|
base_url=f"http://localhost:5000",
|
||||||
|
)
|
||||||
|
|
||||||
|
message = UserMessage(
|
||||||
|
content="hello world, write me a 2 sentence poem about the moon", role="user"
|
||||||
|
)
|
||||||
|
print(f"User>{message.content}", "green")
|
||||||
|
|
||||||
|
response = client.inference.chat_completion(
|
||||||
|
messages=[message],
|
||||||
|
model="Llama3.2-11B-Vision-Instruct",
|
||||||
|
stream=stream,
|
||||||
|
)
|
||||||
|
|
||||||
|
if not stream:
|
||||||
|
cprint(f"> Response: {response}", "cyan")
|
||||||
|
else:
|
||||||
|
async for log in EventLogger().log(response):
|
||||||
|
log.print()
|
||||||
|
|
||||||
|
models_response = client.models.list()
|
||||||
|
print(models_response)
|
||||||
|
|
||||||
|
|
||||||
|
if __name__ == "__main__":
|
||||||
|
asyncio.run(run_main())
|
22
docs/source/inference.py
Normal file
22
docs/source/inference.py
Normal file
|
@ -0,0 +1,22 @@
|
||||||
|
import asyncio
|
||||||
|
|
||||||
|
from llama_stack_client import LlamaStackClient
|
||||||
|
from llama_stack_client.lib.inference.event_logger import EventLogger
|
||||||
|
from llama_stack_client.types import UserMessage
|
||||||
|
from termcolor import cprint
|
||||||
|
|
||||||
|
|
||||||
|
client = LlamaStackClient(
|
||||||
|
base_url=f"http://localhost:5000",
|
||||||
|
)
|
||||||
|
message = UserMessage(
|
||||||
|
content="hello world, write me a 2 sentence poem about the moon", role="user"
|
||||||
|
)
|
||||||
|
|
||||||
|
cprint(f"User>{message.content}", "green")
|
||||||
|
response = client.inference.chat_completion(
|
||||||
|
messages=[message],
|
||||||
|
model="Llama3.2-11B-Vision-Instruct",
|
||||||
|
)
|
||||||
|
|
||||||
|
cprint(f"> Response: {response.completion_message.content}", "cyan")
|
Loading…
Add table
Add a link
Reference in a new issue