-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathchat.py
More file actions
63 lines (51 loc) · 1.68 KB
/
Copy pathchat.py
File metadata and controls
63 lines (51 loc) · 1.68 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
import os
import fire
from llama_stack_client import LlamaStackClient
from llama_stack_client.lib.agents.agent import Agent
from llama_stack_client.lib.agents.event_logger import EventLogger
from llama_stack_client.types.agent_create_params import AgentConfig
from termcolor import colored
def main(host: str, port: int):
client = LlamaStackClient(
base_url=f"http://{host}:{port}",
)
available_models = [
model.identifier for model in client.models.list() if model.model_type == "llm"
]
if not available_models:
print(colored("No available models. Exiting.", "red"))
return
else:
selected_model = available_models[0]
print(f"Using model: {selected_model}")
client.shields.register(shield_id="grumpy-guard-shield", provider_shield_id="grumpy-guard")
agent = Agent(
client=client,
model=selected_model,
instructions="You are a helpful assistant.",
sampling_params={
"strategy": {"type": "top_p", "temperature": 1.0, "top_p": 0.9},
},
tools=[],
input_shields=["grumpy-guard-shield"],
output_shields=[],
enable_session_persistence=False,
)
session_id = agent.create_session("test-session")
while True:
prompt = input("Enter a prompt: ")
if not prompt:
break
response = agent.create_turn(
messages=[
{
"role": "user",
"content": prompt,
}
],
session_id=session_id,
)
for log in EventLogger().log(response):
log.print()
if __name__ == "__main__":
fire.Fire(main)