@@ -86,10 +86,17 @@ from locallab_client import SyncLocalLabClient
86
86
client = SyncLocalLabClient(" http://localhost:8000" )
87
87
88
88
try :
89
+ print (" Generating text..." )
89
90
# Generate text
90
91
response = client.generate(" Write a story" )
91
92
print (response)
92
93
94
+ print (" Streaming responses..." )
95
+ # Stream responses
96
+ for token in client.stream_generate(" Tell me a story" ):
97
+ print (token, end = " " , flush = True )
98
+
99
+ print (" Chat responses..." )
93
100
# Chat with AI
94
101
response = client.chat([
95
102
{" role" : " system" , " content" : " You are helpful." },
@@ -113,21 +120,25 @@ async def main():
113
120
client = LocalLabClient(" http://localhost:8000" )
114
121
115
122
try :
123
+ print (" Generating text..." )
116
124
# Generate text
117
125
response = await client.generate(" Write a story" )
118
126
print (response)
119
127
128
+ print (" Streaming responses..." )
120
129
# Stream responses
121
130
async for token in client.stream_generate(" Tell me a story" ):
122
131
print (token, end = " " , flush = True )
123
132
133
+ print (" \n Chatting with AI..." )
124
134
# Chat with AI
125
135
response = await client.chat([
126
136
{" role" : " system" , " content" : " You are helpful." },
127
137
{" role" : " user" , " content" : " Hello!" }
128
138
])
129
- print (response.choices[0 ][" message" ][" content" ])
130
-
139
+ # Extracting Content
140
+ content = response[' choices' ][0 ][' message' ][' content' ]
141
+ print (content)
131
142
finally :
132
143
# Always close the client
133
144
await client.close()
0 commit comments