GithubHelp home page GithubHelp logo

Streaming example about guidance HOT 7 CLOSED

guidance-ai avatar guidance-ai commented on August 24, 2024 1
Streaming example

from guidance.

Comments (7)

slundberg avatar slundberg commented on August 24, 2024 3

This is indeed much needed. Will post when this is pushed.

from guidance.

slundberg avatar slundberg commented on August 24, 2024 3

0.0.56 now has a first version of streaming support. We will need to also update library calls to update variables more frequently, but any comments or feedback are welcome over in #129

from guidance.

vaharoni avatar vaharoni commented on August 24, 2024 1

As a follow up - it would be great if the library allowed doing something like the following without blocking the event loop by internally calling openai.ChatCompletion.acreate instead of create.

import asyncio
import guidance


guidance.llm = guidance.llms.OpenAI(model='gpt-3.5-turbo')

program = guidance("""
{{#user~}}
Write A poem about sparkling water
{{~/user}}
{{#assistant~}}
{{gen 'poem'}}
{{~/assistant}}
""")


async def counter():
    for x in range(5):
        print(x, flush=True)
        await asyncio.sleep(1)


async def generate():
    # Currently unsupported
    async for chunk in program(async_mode=True, stream=True):
        print(chunk, flush=True)


async def main():
    await asyncio.gather(generate(), counter())


asyncio.run(main())

from guidance.

yermie avatar yermie commented on August 24, 2024 1

This is indeed much needed. Will post when this is pushed.

Thank you @slundberg . The guidance library has tremendous potential for controlling nuanced chatbot behavior vs. langchain and we appreciate your efforts.

from guidance.

andaag avatar andaag commented on August 24, 2024

I've got a working workaround here https://github.com/andaag/chattergpt/blob/e199ccc99b7d8476275f4ed5720b268d506490c1/shared.py#L41 - it's a bit ugly as it accesses internal classes, but should work fine until something is implemented.

from guidance.

rawsh avatar rawsh commented on August 24, 2024

I've got a working workaround here https://github.com/andaag/chattergpt/blob/e199ccc99b7d8476275f4ed5720b268d506490c1/shared.py#L41 - it's a bit ugly as it accesses internal classes, but should work fine until something is implemented.

Thanks for the link, using the internal done function is what I was missing to get hacky streaming working with FastAPI

from guidance.

marcotcr avatar marcotcr commented on August 24, 2024

Closing for now, feel free to reopen if needed.

from guidance.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.