Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update Instructor + Gemini example #267

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 1 addition & 12 deletions examples/instructor-gemini-flash/application.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import time
from copy import deepcopy
from typing import Annotated

Expand Down Expand Up @@ -180,14 +179,7 @@ def creator(
max_retries=attempts,
temperature=TEMPERATURE,
)
try:
res = ask_gemini.create(**create_kwargs) # type: ignore
except Exception as e:
print(f"ERROR in creator: {e}")
# if the model fails to generate a response even after multiple attempts, we will return None
# creator will be called again until a valid response is generated
return {"generated_topic": None}, state.update(generated_topic=None)
# add the user message and the generated topic to the chat history
res = ask_gemini.create(**create_kwargs)
return {"generated_topic": res}, state.update(generated_topic=res).append(
chat_history={"role": "user", "content": user_message}
).append(chat_history={"role": "assistant", "content": str(res)})
Expand All @@ -203,7 +195,6 @@ def get_topic_feedback(state: State) -> tuple[dict, State]:
If the user is happy with the generated topic, they can leave the feedback empty.
This feedback will be added as a user message to the chat history.
"""
time.sleep(2)
num_required_topics = state.get("num_required_topics", NUM_REQUIRED_TOPICS)
num_topics_so_far = len(state.get("topics_so_far", []))
generated_topic = state["generated_topic"]
Expand Down Expand Up @@ -248,8 +239,6 @@ def application(
.with_actions(setup, creator, get_topic_feedback, update_topics_so_far, terminal)
.with_transitions(
("setup", "creator"),
# go to creator again if the generated topic is None
("creator", "creator", expr("generated_topic is None")), # type: ignore
# get feedback if the generated topic is not None
("creator", "get_topic_feedback"),
# if the feedback is empty, add the generated topic to the list of topics generated so far
Expand Down
Binary file modified examples/instructor-gemini-flash/statemachine.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading