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

can i use verba via api ? #254

Open
michabbb opened this issue Aug 9, 2024 · 3 comments
Open

can i use verba via api ? #254

michabbb opened this issue Aug 9, 2024 · 3 comments
Labels
enhancement New feature or request

Comments

@michabbb
Copy link

michabbb commented Aug 9, 2024

instead of using the frontend ??? thanks!

@CarstenHoyer
Copy link

It looks like the fetching of context happens through /api/query - but after that the Manager look (ie querying Ollama) happens through a websocket. So I don't think it can be used as an API, but I think you could write a thin middlelayer to do it.

@danielhangan
Copy link

You can write custom route that follows the same pattern as websocket_generate_stream route.

async def generate_stream(payload: GeneratePayload):
    chunks, context = manager.retrieve_chunks([payload.query])

    retrieved_chunks_text = [chunk.text for chunk in chunks]

    full_text = ""
    async for chunk in manager.generate_stream_answer(
            [payload.query], retrieved_chunks_text, payload.conversation
        ):
        full_text += chunk["message"]
        if chunk["finish_reason"] == "stop":
            chunk["full_text"] = full_text
        yield f"data: {json.dumps(chunk)}\n\n"
    yield "data: [DONE]\n\n"

@router.post("/completion")
async def completion(payload: GeneratePayload):
    return StreamingResponse(generate_stream(payload), media_type="text/event-stream")

@thomashacker
Copy link
Collaborator

Great idea, we're working on an API for this! 🚀

@thomashacker thomashacker added the enhancement New feature or request label Sep 13, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

4 participants