Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add a REST API streaming endpoint for the query pipeline #5697

Closed
wants to merge 11 commits into from

Conversation

faaany
Copy link
Contributor

@faaany faaany commented Aug 31, 2023

Related Issues

Following the suggestion in PR #4889, I implemented a streaming endpoint in my application. I thought this feature might be interesting for other users as well, which leads to this PR.

Proposed Changes:

  • add a new endpoint query-streaming, which outputs the result of the last component in the pipeline in streaming form
  • this feature has one prerequisite: the last node in the pipeline should be a PromptNode or a node that accepts stream_handler in their run method. Otherwise, a warning message will be returned.

How did you test it?

  • locally with the following example yaml file
components:
- name: AnswerParser
  params: {}
  type: AnswerParser
- name: custom-at-query-time
  params:
    output_parser: AnswerParser
    prompt: "Please answer the following question. Question: {query} \n\n Answer:"
  type: PromptTemplate
- name: generator
  params:
    api_key: <your openai api key>
    default_prompt_template: custom-at-query-time
    model_name_or_path: text-davinci-003
  type: PromptNode
pipelines:
- name: query
  nodes:
  - inputs:
    - Query
    name: generator
version: 1.20.0rc0

To start the backend, run

export PIPELINE_YAML_PATH=/home/user/workspace/example.yaml 
export QUERY_PIPELINE_NAME=query 
uvicorn rest_api.application:app --reload --workers 1

To query the results, run

curl -w "\n" -N -X POST -H "Content-Type: application/json" -d '{"query": "Why do airplanes leave contrails in the sky?"}' http://localhost:8000/query-streaming

Notes for the reviewer

There is another PR #5646 of mine which enables passing an object to pipeline.run(). This PR will only work if that PR gets merged first. @ZanSara

The "exception handling" in my solution (the warning message) is not optimal, pls let me know if you have a better idea.
Also please let me know if a unit test is needed here.

Checklist

@faaany faaany requested a review from a team as a code owner August 31, 2023 08:27
@faaany faaany requested review from silvanocerza and removed request for a team August 31, 2023 08:27
@github-actions github-actions bot added topic:rest_api type:documentation Improvements on the docs labels Aug 31, 2023
@faaany
Copy link
Contributor Author

faaany commented Aug 31, 2023

@yao-matrix

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
topic:rest_api type:documentation Improvements on the docs
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant