mirror of
https://github.com/meta-llama/llama-stack.git
synced 2025-07-30 07:39:38 +00:00
adding a few more inference examples
This commit is contained in:
parent
626dffa0d9
commit
703d7ebb6e
2 changed files with 69 additions and 0 deletions
37
docs/source/inference-loop-history.py
Normal file
37
docs/source/inference-loop-history.py
Normal file
|
@ -0,0 +1,37 @@
|
||||||
|
import asyncio
|
||||||
|
|
||||||
|
from llama_stack_client import LlamaStackClient
|
||||||
|
from llama_stack_client.types import UserMessage
|
||||||
|
from termcolor import cprint
|
||||||
|
|
||||||
|
client = LlamaStackClient(
|
||||||
|
base_url="http://localhost:5000",
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
|
async def chat_loop():
|
||||||
|
conversation_history = []
|
||||||
|
|
||||||
|
while True:
|
||||||
|
user_input = input("User> ")
|
||||||
|
if user_input.lower() in ["exit", "quit", "bye"]:
|
||||||
|
cprint("Ending conversation. Goodbye!", "yellow")
|
||||||
|
break
|
||||||
|
|
||||||
|
user_message = UserMessage(content=user_input, role="user")
|
||||||
|
conversation_history.append(user_message)
|
||||||
|
|
||||||
|
response = client.inference.chat_completion(
|
||||||
|
messages=conversation_history,
|
||||||
|
model="Llama3.2-11B-Vision-Instruct",
|
||||||
|
)
|
||||||
|
|
||||||
|
cprint(f"> Response: {response.completion_message.content}", "cyan")
|
||||||
|
|
||||||
|
assistant_message = UserMessage(
|
||||||
|
content=response.completion_message.content, role="user"
|
||||||
|
)
|
||||||
|
conversation_history.append(assistant_message)
|
||||||
|
|
||||||
|
|
||||||
|
asyncio.run(chat_loop())
|
32
docs/source/inference-loop.py
Normal file
32
docs/source/inference-loop.py
Normal file
|
@ -0,0 +1,32 @@
|
||||||
|
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="http://localhost:5000",
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
|
async def chat_loop():
|
||||||
|
while True:
|
||||||
|
|
||||||
|
user_input = input("User> ")
|
||||||
|
|
||||||
|
if user_input.lower() in ["exit", "quit", "bye"]:
|
||||||
|
cprint("Ending conversation. Goodbye!", "yellow")
|
||||||
|
break
|
||||||
|
|
||||||
|
message = UserMessage(content=user_input, role="user")
|
||||||
|
|
||||||
|
response = client.inference.chat_completion(
|
||||||
|
messages=[message],
|
||||||
|
model="Llama3.2-11B-Vision-Instruct",
|
||||||
|
)
|
||||||
|
|
||||||
|
cprint(f"> Response: {response.completion_message.content}", "cyan")
|
||||||
|
|
||||||
|
|
||||||
|
asyncio.run(chat_loop())
|
Loading…
Add table
Add a link
Reference in a new issue