1
2

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

streamlit[xxxx]: Langfuse client is disabled since no public_key was provided as a parameter or environment variable 'LANGFUSE_PUBLIC_KEY'

Posted at

内容

Streamlitで構築したアプリケーションにLangfuseへの送信設定を実施したが、Langfuse側のTraceに結果が表示されない。送信元のサーバを確認すると下記のエラーを確認。

streamlit[xxxx]: Langfuse client is disabled since no public_key 
was provided as a parameter or environment variable 'LANGFUSE_PUBLIC_KEY'.
See our docs: https://langfuse.com/docs/sdk/python/low-level-sdk#initialize-client

LANGFUSE_PUBLIC_KEYといった環境変数を渡せていないようだ。下記環境変数は設定済み。

.bash_profile
export LANGFUSE_SECRET_KEY=sk-lf-**********
export LANGFUSE_PUBLIC_KEY=pk-lf-**********
export LANGFUSE_HOST=https://us.cloud.langfuse.com
echo $LANGFUSE_PUBLIC_KEY
pk-lf-**********

テスト用のStreamlitのプログラムを作成。

import streamlit as st
import os
from langfuse import Langfuse

langfuse = Langfuse(
    secret_key=os.environ.get("LANGFUSE_SECRET_KEY"),
    public_key=os.environ.get("LANGFUSE_PUBLIC_KEY"),
    host=os.environ.get("LANGFUSE_HOST")
)

st.title("テスト")

try:
    result = langfuse.auth_check()
    if result:
        st.success("OK")
    else:
        st.error("NG")
except Exception as e:
    st.error(e)

実行結果はstatus_code: 401, body: {'message': 'No authorization header'}で認証情報が渡せていないようだ。
Streamlitはsystemdで起動しているのでsystemd側に記載。

[Unit]
Description=streamlit
After=network.target

[Service]
Type=simple
WorkingDirectory=/root
ExecStart=/usr/local/bin/streamlit run /root/app.py
Restart = on-failure

Environment=LANGFUSE_SECRET_KEY=sk-lf-**********
Environment=LANGFUSE_PUBLIC_KEY=pk-lf-**********
Environment=LANGFUSE_HOST=https://us.cloud.langfuse.com

[Install]
WantedBy=multi-user.target
systemctl daemon-reload
systemctl restart streamlit_app.service

上記実施後、実施結果がOKとなる。@observe()を付けたプログラム実行後、Langfuse側のTraceに実行結果が表示されていることを確認。

1
2
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
1
2

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?