Skip to content

Commit

Permalink
fix llm app examples
Browse files Browse the repository at this point in the history
  • Loading branch information
jeffkayne committed Aug 29, 2023
1 parent 7237f77 commit d034a44
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 7 deletions.
9 changes: 5 additions & 4 deletions examples/streamlit/llm_app.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
else:
st.warning("To save some feedback to Trubrics, add your account details in the sidebar.")

models = ("text-davinci-003", "text-davinci-002")
models = ("gpt-3.5-turbo",)
model = st.selectbox(
"Choose your GPT-3.5 LLM",
models,
Expand All @@ -38,10 +38,10 @@
button = st.button(f"Ask {model}")

if button:
response = openai.Completion.create(model=model, prompt=prompt, temperature=0.5, max_tokens=200)
response_text = response.choices[0].text.replace("\n", "")
response = openai.ChatCompletion.create(model=model, messages=[{"role": "user", "content": prompt}])
response_text = response.choices[0].message["content"]
st.session_state.logged_prompt = collector.log_prompt(
model_config={"model": model}, prompt=prompt, generation=response_text
model_config={"model": model}, prompt=prompt, generation=response_text, tags=["llm_app.py"]
)
st.session_state.response = response_text

Expand All @@ -56,6 +56,7 @@
model=model,
align="flex-start",
single_submit=False,
tags=["llm_app.py"],
)

if feedback:
Expand Down
9 changes: 7 additions & 2 deletions examples/streamlit/llm_chatbot.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ def init_trubrics(email, password):
if "session_id" not in st.session_state:
st.session_state["session_id"] = str(uuid.uuid4())

model = "gpt-4"
model = "gpt-3.5-turbo"

openai_api_key = st.secrets.get("OPENAI_API_KEY")
if prompt := st.chat_input():
Expand All @@ -41,7 +41,11 @@ def init_trubrics(email, password):
response = openai.ChatCompletion.create(model=model, messages=st.session_state.messages)
msg = response.choices[0].message
logged_prompt = collector.log_prompt(
model_config={"model": model}, prompt=prompt, generation=msg["content"], session_id=st.session_state.session_id
model_config={"model": model},
prompt=prompt,
generation=msg["content"],
session_id=st.session_state.session_id,
tags=["llm_chatbot.py"],
)
st.session_state.prompt_ids.append(logged_prompt.id)
st.session_state.messages.append(msg)
Expand All @@ -61,6 +65,7 @@ def init_trubrics(email, password):
align="flex-end",
single_submit=True,
key=f"feedback_{int(n/2)}",
tags=["llm_chatbot.py"],
)

else:
Expand Down
2 changes: 1 addition & 1 deletion requirements.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
requests>=2.28.0
pydantic>=1.9.1,<2.0
pydantic>=1.9.1
typer>=0.6.1
loguru>=0.6.0

0 comments on commit d034a44

Please sign in to comment.