10async def timeout(it: AsyncIterator[T], timeo: float, sentinel: T) -> AsyncGenerator[T,
None]:
12 nxt = asyncio.ensure_future(it.__anext__())
15 yield await asyncio.wait_for(asyncio.shield(nxt), timeo)
16 nxt = asyncio.ensure_future(it.__anext__())
17 except asyncio.TimeoutError:
19 except StopAsyncIteration:
39 client = ollama.AsyncClient()
43 if content_in := input(
'>>> '):
44 messages.append({
'role':
'user',
'content': content_in})
46 message = {
'role':
'assistant',
'content':
''}
47 respaiter = await client.chat(model=
'tinydolphin', messages=messages, stream=
True)
48 print(
"type is {}".format(type(respaiter)))
49 zob =
timeout(respaiter, 0.01,
None)
50 print(
"zob type is {}".format(type(zob)))
54 response = await anext(zob)
55 if response
is not None:
57 messages.append(message)
59 content = response[
'message'][
'content']
60 print(content, end=
'', flush=
True)
61 message[
'content'] += content