You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Describe the bug
When using streaming in the OpenAIGenerator or OpenAIChatgenerator, langfuse will throw an exception that it cannot convert an empty dict into usage input.
site-packages/langfuse/utils/__init__.py", line101, in_convert_usage_inputraiseValueError(
ValueError: Usageobjectmusthaveeither {input, output, total, unit} or {promptTokens, completionTokens, totalTokens}
Paris{'tracer': {'name': 'test_langfuse', 'trace_url': 'https://cloud.langfuse.com/trace/4f3dd665-52f1-4938-9882-680dfda94ee8'}, 'llm': {'replies': ['According to the given context, the capital of France is:\n\nParis'], 'meta': [{'model': 'gpt-3.5-turbo', 'index': 0, 'finish_reason': 'stop', 'usage': {}}]}}
To Reproduce
importosos.environ["TOKENIZERS_PARALLELISM"] ="false"os.environ["HAYSTACK_CONTENT_TRACING_ENABLED"]="true"os.environ["LANGFUSE_SECRET_KEY"]="<secret_key>"os.environ["LANGFUSE_PUBLIC_KEY"]="<public_key>"os.environ["LANGFUSE_HOST"]="https://cloud.langfuse.com"fromhaystackimportPipelinefromhaystack.components.retrievers.in_memoryimportInMemoryBM25Retrieverfromhaystack.components.builders.prompt_builderimportPromptBuilderfromhaystack.components.generatorsimportOpenAIGeneratorfromhaystack.document_stores.in_memoryimportInMemoryDocumentStorefromhaystackimportDocumentfromhaystack.utilsimportSecretfromhaystack_integrations.components.connectors.langfuseimportLangfuseConnectordefprint_callback(data):
print(data.content, end="")
docstore=InMemoryDocumentStore()
docstore.write_documents([Document(content="Rome is the capital of Italy"), Document(content="Paris is the capital of France")])
query="What is the capital of France?"template="""Given the following information, answer the question.Context: {% for document in documents %} {{ document.content }}{% endfor %}Question: {{ query }}?"""pipe=Pipeline()
pipe.add_component("tracer", LangfuseConnector(name="test_langfuse"))
pipe.add_component("retriever", InMemoryBM25Retriever(document_store=docstore))
pipe.add_component("prompt_builder", PromptBuilder(template=template))
pipe.add_component("llm", OpenAIGenerator(api_key=Secret.from_token("<your-api-key>"),
api_base_url="http://localhost:30091/v1",
streaming_callback=print_callback))
pipe.connect("retriever", "prompt_builder.documents")
pipe.connect("prompt_builder", "llm")
res=pipe.run({
"prompt_builder": {
"query": query
},
"retriever": {
"query": query
}
})
print(res)
Describe your environment (please complete the following information):
OS: MacOS
Haystack version: 2.2.1
Integration version:
langfuse-haystack 0.0.4
The text was updated successfully, but these errors were encountered:
Describe the bug
When using streaming in the OpenAIGenerator or OpenAIChatgenerator, langfuse will throw an exception that it cannot convert an empty dict into usage input.
To Reproduce
Describe your environment (please complete the following information):
langfuse-haystack 0.0.4
The text was updated successfully, but these errors were encountered: