Skip to content

Commit

Permalink
Merge pull request #26 from phospho-app/nico/deploy-santa-streamlit
Browse files Browse the repository at this point in the history
Change logging in Santa streamlit
  • Loading branch information
oulianov authored Dec 12, 2023
2 parents e2a547c + 5e64656 commit 904ff21
Showing 1 changed file with 7 additions and 4 deletions.
11 changes: 7 additions & 4 deletions examples/streamlit-santa-agent/backend.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
from openai.types.chat import ChatCompletionChunk
from openai._streaming import Stream

from typing import List, Dict, Generator, Any
from typing import List, Dict, Generator, Any, Optional

# Initialize phospho to collect logs
phospho.init(
Expand Down Expand Up @@ -55,8 +55,6 @@ def random_intro(self, session_id: str) -> Generator[str, Any, None]:
"Happy halloween!... Uh-oh. Wrong holidays! Ho, ho, ho! Merry Christmas, how are you?",
]
)
# Let's log this intro to phospho in order to see which one is the most engaging
phospho.log(input="intro", output=chosen_intro, session_id=session_id)
# Create a streaming effect
splitted_text = chosen_intro.split(" ")
for i, word in enumerate(splitted_text):
Expand Down Expand Up @@ -97,7 +95,12 @@ def answer(
# phospho takes care of aggregating all of the tokens into a single, sensible log.
# It also logs all the parameters and all the responses, which is great for debugging
logged_content = phospho.log(
input=full_prompt, output=response, session_id=session_id
input=full_prompt,
output=response,
# We use the session_id to group all the logs of a single chat
session_id=session_id,
# We add the used intro as a metadata. It is the first message of the chat.
metadata={"intro": messages[0]["content"]},
)

# logged_content["output"] contains all the generated tokens until this point
Expand Down

0 comments on commit 904ff21

Please sign in to comment.