Skip to content

Instantly share code, notes, and snippets.

@elijahbenizzy
Last active August 23, 2024 20:30
Show Gist options
  • Save elijahbenizzy/9519a558279e550508470e82fb8b1a90 to your computer and use it in GitHub Desktop.
Save elijahbenizzy/9519a558279e550508470e82fb8b1a90 to your computer and use it in GitHub Desktop.
@action(reads=["prompt", "chat_history", "mode"], writes=["response"])
def chat_response(
state: State,
prepend_prompt: str,
model: str = "gpt-4o",
) -> Tuple[dict, State]:
chat_history = state["chat_history"].copy()
chat_history_to_send = chat_history[:-1]
prompt = f"{prepend_prompt}: {chat_history[-1]['content']}"
response = _query_openai(
prompt=prompt,
chat_history=chat_history_to_send,
model=model
)
return state.update(response={"content": response, "type": "text", "role": "assistant"})
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment