Find answers from the community

J
JF
Offline, last seen 3 months ago
Joined September 25, 2024
With my streaming response it seems to be missing the first word from the response:

Plain Text
@app.post("/ask")
async def ask(data: AskModel):
    s3 = get_s3()
    chat_info = get_convo(data.chat_uuid, s3)
    access = chat_info.get('meta', {}).get('access', [])
    index_set = get_index(access, fs=s3)
    chat_history = chat_info["history"]
    chat_engine = index_set.as_chat_engine(
        similarity_top_k=3,
        streaming=True,
        chat_history=chat_history,
    )

    def stream_response():
        streaming_response = chat_engine.stream_chat(data.question)
        response_gen = streaming_response.response_gen
        first_token = next(response_gen)  # Get the first token of the response
        response = first_token
        yield f"data: {response}\n\n"  # Yield the first token separately

        for token in response_gen:
            yield f"data: {response}\n\n"
            response+=token

        chat_history.extend([
            {"role": "user", "content": data.question},
            {"role": "assistant", "content": ''.join(response)}
        ])
        chat_info['history'] = chat_history
        save_chat(data.chat_uuid, chat_info, s3)

    return StreamingResponse(stream_response(), media_type="text/event-stream")

How can i get the make sure the first token is included of the response? :)
the
e.g: call between the person and the company resulted in the person...
it should clearly have something on front of the ' call' text

with a non stream version, the response looks like:
"response": " The call resulted in the person being informed..."
2 comments
J
L
I sometimes get
Observation: tool response
from the chat_engine, what does this mean?
does this want the user to add more context? or is it a glitch from the way the default chat_engine prompt is setup
1 comment
L
J
JF
·

Hey people

Hey people,
I have this
Plain Text
s3 = s3fs.S3FileSystem(
    key=AWS_KEY,
    secret=AWS_SECRET,
    endpoint_url=S3_BUCKET_URL
)

def add_new_doc(name, filename, index_set):
    with open(filename, "r") as f:
        doc = f.read()
        storage_context = StorageContext.from_defaults(fs=s3)
        index_set[name] = VectorStoreIndex.from_documents(
            [Document(text=doc)],
            service_context=service_context,
            storage_context=storage_context,
        )
        storage_context.persist(persist_dir=f'bucket-name/{name}')
    return index_set

however the index for the specific file is still being saved into the local file, and doesnt go into s3, there are no errors
3 comments
L
J